2020-09-17 14:55:13 +02:00
|
|
|
---
|
|
|
|
- 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 }}"
|
2020-09-17 16:12:22 +02:00
|
|
|
groups: "{{ item.value.groups | default(user_mgmt_default_groups) }}"
|
2020-09-17 14:55:13 +02:00
|
|
|
state: present
|
2020-09-17 16:12:22 +02:00
|
|
|
when: (item.value.state | default(user_mgmt_default_state)) == "present"
|
2020-09-17 14:55:13 +02:00
|
|
|
with_dict: "{{ _user_mgmt }}"
|
|
|
|
|
|
|
|
- name: Add ssh-key to user
|
|
|
|
authorized_key:
|
|
|
|
user: "{{ item.0.key }}"
|
|
|
|
key: "{{ item.1 }}"
|
|
|
|
state: present
|
2020-09-18 13:17:02 +02:00
|
|
|
when: (_user_mgmt[item.0.key].state | default(user_mgmt_default_state)) == "present"
|
2020-09-17 14:55:13 +02:00
|
|
|
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
|
2020-09-18 13:17:02 +02:00
|
|
|
when: (_user_mgmt[item.0.key].state | default(user_mgmt_default_state)) == "present"
|
2020-09-17 14:55:13 +02:00
|
|
|
loop: "{{ _user_mgmt |dict2items | subelements('value.ssh_key.absent') }}"
|
|
|
|
|
|
|
|
- name: Remove user
|
|
|
|
user:
|
|
|
|
name: "{{ item.key }}"
|
|
|
|
state: absent
|
2020-09-17 16:12:22 +02:00
|
|
|
when: (item.value.state | default(user_mgmt_default_state)) == "absent"
|
2020-09-17 14:55:13 +02:00
|
|
|
with_dict: "{{ _user_mgmt }}"
|