ansible/roles/user_mgmt/tasks/main.yml

35 lines
1.1 KiB
YAML

---
- name: Merge ansible variables for host
set_fact: _user_mgmt="{{ user_mgmt_default | combine(user_mgmt, recursive=true) }}"
- name: Add User
user:
name: "{{ item.key }}"
groups: "{{ item.value.groups | default(user_mgmt_default_groups) }}"
state: present
when: (item.value.state | default(user_mgmt_default_state)) == "present"
with_dict: "{{ _user_mgmt }}"
- name: Add ssh-key to user
authorized_key:
user: "{{ item.0.key }}"
key: "{{ item.1 }}"
state: present
when: (_user_mgmt[item.0.key].created | default(user_mgmt_default_state)) == "present"
loop: "{{ _user_mgmt |dict2items | subelements('value.ssh_key.present') }}"
- name: Remove ssh-key to user
authorized_key:
user: "{{ item.0.key }}"
key: "{{ item.1 }}"
state: absent
when: (_user_mgmt[item.0.key].created | default(user_mgmt_default_state)) == "present"
loop: "{{ _user_mgmt |dict2items | subelements('value.ssh_key.absent') }}"
- name: Remove user
user:
name: "{{ item.key }}"
state: absent
when: (item.value.state | default(user_mgmt_default_state)) == "absent"
with_dict: "{{ _user_mgmt }}"