ansible/roles/user_mgmt/tasks/main.yml

35 lines
971 B
YAML
Raw Normal View History

---
- 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([]) }}"
state: present
when: item.value.created | default
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
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
loop: "{{ _user_mgmt |dict2items | subelements('value.ssh_key.absent') }}"
- name: Remove user
user:
name: "{{ item.key }}"
state: absent
when: not (item.value.created | default)
with_dict: "{{ _user_mgmt }}"