--- # tasks file for users - name: Construire la liste des utilisateurs ansible.builtin.set_fact: users: "{{ users + specific }}" when: specific | length > 0 loop: "{{ lookup('ansible.builtin.varnames', '^users.+', wantlist=True) }}" vars: specific: "{{ lookup('ansible.builtin.vars', item, default='') }}" - name: Créer un groupe au nom de l'utilisateur ansible.builtin.group: name: "{{ item.name }}" when: user.group is undefined become: true loop: "{{ users }}" loop_control: label: "{{ item.name }}" - name: Créer les autres groupes ansible.builtin.group: name: "{{ item.1 }}" become: true loop: "{{ users | subelements('groups', skip_missing=True) }}" loop_control: label: "{{ item.1 }}" - name: Créer les utilisateurs ansible.builtin.user: name: "{{ item.name }}" comment: "{{ item.comment | default(omit) }}" password: "{{ item.password | default(omit) }}" password_lock: "{{ item.password_lock | default(omit) }}" home: "{{ item.home | default(omit) }}" shell: "{{ item.shell | default(omit) }}" group: "{{ item.group | default(item.name) }}" groups: "{{ item.groups | default(omit) }}" become: true loop: "{{ users }}" loop_control: label: "{{ item.name }}"