additional course material RH294
Olaf Bohlen
2020-08-20 1de6236f80a879ca110981fe0e5c0c05c521225b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
---
- name: a play for a simple loop
  hosts: foobar
  remote_user: olbohlen
  become: yes
  vars:
    installstate: present
    run_my_task: false
    users:
      - name: frodo
        shell: /bin/bash
      - name: bilbo
        shell: /bin/bash
      - name: gollum
        shell: /bin/nologin
  tasks:
    - name: "create user {{ item['name'] }}"
      user:
        name: "{{ item['name'] }}"
        shell: "{{ item['shell'] }}"
        state: "{{ installstate }}"
      loop: "{{ users }}"
      register: userregister
      when: run_my_task
      
    - name: 'show created users'
      shell: getent passwd
      register: geout
    - debug:
        msg: "{{ geout.stdout_lines }}"
 
    - debug:
        var: userregister