Uno-Dan

Add users

Aug 2nd, 2021
820
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ---
  2.  
  3. - name: add users
  4.   ansible.builtin.user:
  5.     name: "{{ item.key }}"
  6.     shell: "{{ item.value.shell }}"
  7.     groups: "{{ item.value.groups }}"
  8.     comment: "{{ item.value.comment }}"
  9.     state: present
  10.     append: yes
  11.  
  12.   loop: "{{ lookup('dict', users) }}"
  13.   register: echo
  14.   loop_control:
  15.     label: "add user: {{ item.key }}"
  16.  
  17. - name: setting user password
  18.   ansible.builtin.user:
  19.     name: "{{ item.item.key }}"
  20.     password: $1$SomeSalt$/jbIwfYCu0MxPBND2EtRH.
  21.  
  22.   loop: "{{ echo.results }}"
  23.   loop_control:
  24.     label: "set password for: {{ item.item.key }}"
  25.   when: item.changed == true
  26.  
  27. - name: expire user password
  28.   command: passwd --expire {{ item.item.key }}
  29.  
  30.   loop: "{{ echo.results }}"
  31.   loop_control:
  32.     label: "expire password for: {{ item.item.key }}"
  33.   when: item.changed == true
RAW Paste Data