From 7845013a39ce3620dd639bb3af1da3d05d562a15 Mon Sep 17 00:00:00 2001 From: "Adrien \"ze\" Urban" Date: Thu, 7 Mar 2019 11:53:59 +0100 Subject: [PATCH 1/4] groups: support `absent` like for users. Also remove warning for passing unknown arguments on group.absent --- users/init.sls | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/users/init.sls b/users/init.sls index 696ccbd..8804b6c 100644 --- a/users/init.sls +++ b/users/init.sls @@ -5,13 +5,17 @@ {% set used_user_files = [] %} {% for group, setting in salt['pillar.get']('groups', {}).items() %} -users_group_{{ setting.get('state', "present") }}_{{ group }}: - group.{{ setting.get('state', "present") }}: +{% if setting.absent is defined and setting.absent or setting.get('state', "present") == 'absent' %} +users_group_absent_{{ group }}: + group.absent: - name: {{ group }} - {%- if setting.get('gid') %} - - gid: {{setting.get('gid') }} - {%- endif %} +{% else %} +users_group_present_{{ group }}: + group.present: + - name: {{ group }} + - gid: {{ setting.get('gid') }} - system: {{ setting.get('system',"False") }} +{% endif %} {% endfor %} {%- for name, user in pillar.get('users', {}).items() From b69bef3cd1af3a6fe3cc71d1885d7150ebfb3055 Mon Sep 17 00:00:00 2001 From: "Adrien \"ze\" Urban" Date: Thu, 7 Mar 2019 11:55:56 +0100 Subject: [PATCH 2/4] group: add pillar example --- pillar.example | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pillar.example b/pillar.example index abd7b50..424f602 100644 --- a/pillar.example +++ b/pillar.example @@ -169,3 +169,10 @@ users: absent_users: - donald - bad_guy + +groups: + badguys: + absent: True + niceguys: + gid: 4242 + system: False From def8f53932cf9aa500bc334d635792e94cac2bbc Mon Sep 17 00:00:00 2001 From: "Adrien \"ze\" Urban" Date: Thu, 7 Mar 2019 11:58:57 +0100 Subject: [PATCH 3/4] group: add support for members members, addusers, delusers, and in pillar examples --- pillar.example | 7 +++++++ users/init.sls | 3 +++ 2 files changed, 10 insertions(+) diff --git a/pillar.example b/pillar.example index 424f602..467e8dd 100644 --- a/pillar.example +++ b/pillar.example @@ -176,3 +176,10 @@ groups: niceguys: gid: 4242 system: False + addusers: root + delusers: toor + ssl-cert: + system: True + members: + - www-data + - openldap diff --git a/users/init.sls b/users/init.sls index 8804b6c..8af84d5 100644 --- a/users/init.sls +++ b/users/init.sls @@ -15,6 +15,9 @@ users_group_present_{{ group }}: - name: {{ group }} - gid: {{ setting.get('gid') }} - system: {{ setting.get('system',"False") }} + - members: {{ setting.get('members')|json }} + - addusers: {{ setting.get('addusers')|json }} + - delusers: {{ setting.get('delusers')|json }} {% endif %} {% endfor %} From c128b1ea286716a2ff6b1db4c2b17d3fddf3e303 Mon Sep 17 00:00:00 2001 From: "Adrien \"ze\" Urban" Date: Thu, 7 Mar 2019 14:38:54 +0100 Subject: [PATCH 4/4] gid: default to "null" using `|json` would let the state get an error if gid is a string, as it would not be converted. Using directly the `None` yaml value, and letting numbers as string be converted by yaml parser. --- users/init.sls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/users/init.sls b/users/init.sls index 8af84d5..068d3f6 100644 --- a/users/init.sls +++ b/users/init.sls @@ -13,7 +13,7 @@ users_group_absent_{{ group }}: users_group_present_{{ group }}: group.present: - name: {{ group }} - - gid: {{ setting.get('gid') }} + - gid: {{ setting.get('gid', "null") }} - system: {{ setting.get('system',"False") }} - members: {{ setting.get('members')|json }} - addusers: {{ setting.get('addusers')|json }}