Create multiple directories using

I want to create several directories (test1, test2) with two subdirectories (/ home / test1 / bin and / home / test 2 / conf) similarly for test2. My book looks like this:

-- - hosts: localhost tasks: - name: Create directory file: path=/home/{{item}}/bin state=directory file: path=/home/{{item}}/conf state=directory with_items: - test1 - test2 

However, I get the following error:

 An exception occurred during task execution. The full traceback is: Traceback (most recent call last): File "/root/ansible/lib/ansible/executor/process/worker.py", line 122, in run executor_result = TaskExecutor(host, task, job_vars, new_play_context, self._new_stdin, self._loader, shared_loader_obj).run() File "/root/ansible/lib/ansible/executor/task_executor.py", line 89, in run items = self._get_loop_items() File "/root/ansible/lib/ansible/executor/task_executor.py", line 179, in _get_loop_items items = self._shared_loader_obj.lookup_loader.get(self._task.loop, loader=self._loader, templar=templar).run(terms=loop_terms, variables=vars_copy) File "/root/ansible/lib/ansible/plugins/lookup/items.py", line 26, in run return self._flatten(terms) TypeError: _flatten() takes exactly 2 arguments (1 given) fatal: [localhost]: FAILED! => {"failed": true, "stdout": ""} 

What is the problem? I am using the latest version of git. Is there a better way to approach this?

+5
source share
1 answer

I think that the errors arose because you used the file module 2 times in 1 task. You should use only 1 module for each task.

In your case, you should use a nested loop to create multiple directories and subdirectories.

Example:

 --- - hosts: localhost tasks: - name: test file: path=/tmp/{{item.0}}/{{item.1}} state=directory with_nested: - ['test1', 'test2'] - ['bin', 'conf'] 
+14
source

Source: https://habr.com/ru/post/1232072/


All Articles