Difference between revisions of "Use loops in task (Ansible)"

From wikieduonline
Jump to navigation Jump to search
 
(2 intermediate revisions by one other user not shown)
Line 25: Line 25:
 
</pre>
 
</pre>
  
 +
== Related terms ==
 +
* <code>[[for]]</code>
 +
* <code>[[with_items:]]</code>
  
 
== See also ==
 
== See also ==
 
* <code>[[with_items]]</code> https://docs.ansible.com/ansible/latest/plugins/lookup/items.html
 
* <code>[[with_items]]</code> https://docs.ansible.com/ansible/latest/plugins/lookup/items.html
 
* [[User ssh access]]
 
* [[User ssh access]]
 +
* {{Ansible}}
  
  
[[Category: Software development]]
+
[[Category:Ansible]]
 
[[Category:Server administration]]
 
[[Category:Server administration]]

Latest revision as of 16:48, 20 December 2022

Ansible offers two keywords for creating loops: loop and with_<lookup>.


$ vim create-users.yml 
---
- name: Create New Users
  hosts: all
  gather_facts: false
  tasks:
   - name: Create Users Task
      user:
        name: "{{ item }}"
        state: present
        password: "{{ default_user_password | password_hash('sha512', 'A512') }}"
        shell: /bin/bash
        groups: "{{ admin_group }}"
        append: true
      loop:
        - bob
        - wendy
        - lofty
        - dizzy
...                  

Related terms[edit]

See also[edit]

Advertising: