Wednesday, November 27, 2019

Types of Loops

ansible-playbook test.yml

test.yml

---

- hosts: gui
  become: yes
  tasks:
   - name: install stuff
     apt: name={{ item }} update_cache=yes state=latest
     with items:
      - vim
      - nano
      - apache2

Below playbook, it will substitute the contents of file1 and file2 to the variable.



---

- hosts: gui
  become: yes
  tasks:
   - name: show file contents
     debug: msg={{ item }}
     with file:
      - file1.txt
      - file2.txt


---

- hosts: gui
  become: yes
  tasks:
   - name: show file contents
     debug: msg=this is loop {{ item }}
     with_sequence: start=1 end=10

More info: More Loops

No comments:

Post a Comment