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:
|
user_mgmt_default:
|
||||||
crest:
|
crest:
|
||||||
ssh_key:
|
ssh_key:
|
||||||
|
|
|
@ -14,8 +14,8 @@ php_fpm_env:
|
||||||
|
|
||||||
user_mgmt:
|
user_mgmt:
|
||||||
crest:
|
crest:
|
||||||
created: true
|
state: present
|
||||||
groups: sudo
|
groups: sudo
|
||||||
genofire:
|
genofire:
|
||||||
created: true
|
state: present
|
||||||
groups: sudo
|
groups: sudo
|
||||||
|
|
|
@ -8,11 +8,11 @@ dns: 213.133.98.98 8.8.8.8
|
||||||
|
|
||||||
user_mgmt:
|
user_mgmt:
|
||||||
crest:
|
crest:
|
||||||
created: true
|
state: present
|
||||||
groups: sudo
|
groups: sudo
|
||||||
genofire:
|
genofire:
|
||||||
created: true
|
state: present
|
||||||
groups: sudo
|
groups: sudo
|
||||||
fritz:
|
fritz:
|
||||||
created: true
|
state: present
|
||||||
groups: sudo
|
groups: sudo
|
||||||
|
|
|
@ -1,2 +1,6 @@
|
||||||
|
---
|
||||||
|
user_mgmt_default_state: "present"
|
||||||
|
user_mgmt_default_groups: []
|
||||||
|
|
||||||
user_mgmt_default: {}
|
user_mgmt_default: {}
|
||||||
user_mgmt: {}
|
user_mgmt: {}
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
- name: Add User
|
- name: Add User
|
||||||
user:
|
user:
|
||||||
name: "{{ item.key }}"
|
name: "{{ item.key }}"
|
||||||
groups: "{{ item.value.groups | default([]) }}"
|
groups: "{{ item.value.groups | default(user_mgmt_default_groups) }}"
|
||||||
state: present
|
state: present
|
||||||
when: item.value.created | default
|
when: (item.value.state | default(user_mgmt_default_state)) == "present"
|
||||||
with_dict: "{{ _user_mgmt }}"
|
with_dict: "{{ _user_mgmt }}"
|
||||||
|
|
||||||
- name: Add ssh-key to user
|
- name: Add ssh-key to user
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
user: "{{ item.0.key }}"
|
user: "{{ item.0.key }}"
|
||||||
key: "{{ item.1 }}"
|
key: "{{ item.1 }}"
|
||||||
state: present
|
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') }}"
|
loop: "{{ _user_mgmt |dict2items | subelements('value.ssh_key.present') }}"
|
||||||
|
|
||||||
- name: Remove ssh-key to user
|
- name: Remove ssh-key to user
|
||||||
|
@ -23,12 +23,12 @@
|
||||||
user: "{{ item.0.key }}"
|
user: "{{ item.0.key }}"
|
||||||
key: "{{ item.1 }}"
|
key: "{{ item.1 }}"
|
||||||
state: absent
|
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') }}"
|
loop: "{{ _user_mgmt |dict2items | subelements('value.ssh_key.absent') }}"
|
||||||
|
|
||||||
- name: Remove user
|
- name: Remove user
|
||||||
user:
|
user:
|
||||||
name: "{{ item.key }}"
|
name: "{{ item.key }}"
|
||||||
state: absent
|
state: absent
|
||||||
when: not (item.value.created | default)
|
when: (item.value.state | default(user_mgmt_default_state)) == "absent"
|
||||||
with_dict: "{{ _user_mgmt }}"
|
with_dict: "{{ _user_mgmt }}"
|
||||||
|
|
Loading…
Reference in a new issue