forked from ccchb/ansible
roles/user_mgmt: improve by using state and default values
This commit is contained in:
parent
dee5a45271
commit
a771624793
5 changed files with 16 additions and 10 deletions
|
@ -1,3 +1,5 @@
|
|||
# do NOT create every user on every maschine
|
||||
user_mgmt_default_state: absent
|
||||
user_mgmt_default:
|
||||
crest:
|
||||
ssh_key:
|
||||
|
|
|
@ -14,8 +14,8 @@ php_fpm_env:
|
|||
|
||||
user_mgmt:
|
||||
crest:
|
||||
created: true
|
||||
state: present
|
||||
groups: sudo
|
||||
genofire:
|
||||
created: true
|
||||
state: present
|
||||
groups: sudo
|
||||
|
|
|
@ -8,11 +8,11 @@ dns: 213.133.98.98 8.8.8.8
|
|||
|
||||
user_mgmt:
|
||||
crest:
|
||||
created: true
|
||||
state: present
|
||||
groups: sudo
|
||||
genofire:
|
||||
created: true
|
||||
state: present
|
||||
groups: sudo
|
||||
fritz:
|
||||
created: true
|
||||
state: present
|
||||
groups: sudo
|
||||
|
|
|
@ -1,2 +1,6 @@
|
|||
---
|
||||
user_mgmt_default_state: "present"
|
||||
user_mgmt_default_groups: []
|
||||
|
||||
user_mgmt_default: {}
|
||||
user_mgmt: {}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
- name: Add User
|
||||
user:
|
||||
name: "{{ item.key }}"
|
||||
groups: "{{ item.value.groups | default([]) }}"
|
||||
groups: "{{ item.value.groups | default(user_mgmt_default_groups) }}"
|
||||
state: present
|
||||
when: item.value.created | default
|
||||
when: (item.value.state | default(user_mgmt_default_state)) == "present"
|
||||
with_dict: "{{ _user_mgmt }}"
|
||||
|
||||
- name: Add ssh-key to user
|
||||
|
@ -15,7 +15,7 @@
|
|||
user: "{{ item.0.key }}"
|
||||
key: "{{ item.1 }}"
|
||||
state: present
|
||||
when: _user_mgmt[item.0.key].created | default
|
||||
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
|
||||
|
@ -23,12 +23,12 @@
|
|||
user: "{{ item.0.key }}"
|
||||
key: "{{ item.1 }}"
|
||||
state: absent
|
||||
when: _user_mgmt[item.0.key].created | default
|
||||
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: not (item.value.created | default)
|
||||
when: (item.value.state | default(user_mgmt_default_state)) == "absent"
|
||||
with_dict: "{{ _user_mgmt }}"
|
||||
|
|
Loading…
Reference in a new issue