Answer the question
In order to leave comments, you need to log in
How to run a loop inside a loop using Ansible?
Hello!
There was a need to create several files of the same type, for example test1 test2 test3
To create one file, I use the following:
- name: Create file
become: yes
shell: "{{ item }}"
with_items:
- echo -e '123' >> /tmp/{{ item }}
-echo -e '456' >> /tmp/{{ item }}
-echo -e '123' >> /tmp/{{ item }}
This will create one test file with 123456123 in it.
Task use the with_sequence module to create n-files test1,test2,....testn
Thank you!
Answer the question
In order to leave comments, you need to log in
- name: create files
become: yes
shell: echo '{{ item }}' > /tmp/test{{ item }}
with_sequence: start=1 count=n
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question