From 07aeb2c4f89f28c686d077abede221cb955193d9 Mon Sep 17 00:00:00 2001 From: Slawomir Pucia Date: Wed, 23 Apr 2014 13:38:31 +0200 Subject: [PATCH] New format of user.absent support introduced. Old format still supported. --- pillar.example | 15 +++++++++++---- users/init.sls | 24 +++++++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/pillar.example b/pillar.example index b876a9b..a936a40 100644 --- a/pillar.example +++ b/pillar.example @@ -1,10 +1,9 @@ users: -## Minimal required pillar values + ## Minimal required pillar values auser: - groups: - - admin + fullname: A User -## Full list of pillar values + ## Full list of pillar values buser: fullname: B User home: /custom/buser @@ -25,6 +24,14 @@ users: ssh_auth: - PUBLICKEY + ## Absent user + cuser: + absent: True + purge: True + force: True + + +## Old syntax of absent_users still supported absent_users: - donald - bad_guy diff --git a/users/init.sls b/users/init.sls index b2c272f..c873c71 100644 --- a/users/init.sls +++ b/users/init.sls @@ -1,7 +1,7 @@ include: - users.sudo -{% for name, user in pillar.get('users', {}).items() %} +{% for name, user in pillar.get('users', {}).items() if user.absent is not defined or not user.absent %} {%- if user == None -%} {%- set user = {} -%} {%- endif -%} @@ -105,8 +105,8 @@ user_{{ name }}_public_key: {% endif %} - {% if 'ssh_auth' in user %} - {% for auth in user['ssh_auth'] %} +{% if 'ssh_auth' in user %} +{% for auth in user['ssh_auth'] %} ssh_auth_{{ name }}_{{ loop.index0 }}: ssh_auth.present: - user: {{ name }} @@ -144,6 +144,24 @@ sudoer-{{ name }}: {% endfor %} +{% for name, user in pillar.get('users', {}).items() if user.absent is defined and user.absent %} +{{ name }}: +{% if 'purge' in user or 'force' in user %} + user.absent: + {% if 'purge' in user %} + - purge: {{ user['purge'] }} + {% endif %} + {% if 'force' in user %} + - force: {{ user['force'] }} + {% endif %} +{% else %} + user.absent +{% endif -%} +/etc/sudoers.d/{{ name }}: + file.absent: + - name: /etc/sudoers.d/{{ name }} +{% endfor %} + {% for user in pillar.get('absent_users', []) %} {{ user }}: user.absent