From 622b846d7f859a0a1fbdfe5794b9a6a8d30848ac Mon Sep 17 00:00:00 2001 From: Niels Abspoel Date: Thu, 11 Jun 2015 23:34:16 +0200 Subject: [PATCH] Enable/disable bashrc/vimrc per user Made both states configurable per user in pillar data Had to drop extend, for this otherwise the extend would be empty if manage is False --- README.rst | 6 ++++-- pillar.example | 2 ++ users/bashrc.sls | 23 ++++++++++++----------- users/vimrc.sls | 23 ++++++++++++----------- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/README.rst b/README.rst index 1efde1d..4d3279a 100644 --- a/README.rst +++ b/README.rst @@ -31,11 +31,13 @@ is configured. ``users.bashrc`` ---------------- -Ensures the bashrc file exists in the users home directory +Ensures the bashrc file exists in the users home directory. Set manage_bashrc: +True in pillar per user. Defaults to False ``users.vimrc`` --------------- -Ensures the vimrc file exists in the users home directory. +Ensures the vimrc file exists in the users home directory. Set manage_vimrc: +True in pillar per user. Defaults to False This depends on the vim-formula to be installed diff --git a/pillar.example b/pillar.example index 4526573..d6e0033 100644 --- a/pillar.example +++ b/pillar.example @@ -9,6 +9,8 @@ users: password: $6$w............. home: /custom/buser createhome: True + manage_vimrc: False + manage_bashrc: False expire: 16426 sudouser: True sudo_rules: diff --git a/users/bashrc.sls b/users/bashrc.sls index 7415f4b..fc268f4 100644 --- a/users/bashrc.sls +++ b/users/bashrc.sls @@ -2,25 +2,26 @@ include: - users -extend: {% for name, user in pillar.get('users', {}).items() if user.absent is not defined or not user.absent %} {%- if user == None -%} {%- set user = {} -%} {%- endif -%} {%- set home = user.get('home', "/home/%s" % name) -%} - +{%- set manage = user.get('manage_bashrc', False) -%} {%- if 'prime_group' in user and 'name' in user['prime_group'] %} {%- set user_group = user.prime_group.name -%} {%- else -%} {%- set user_group = name -%} {%- endif %} - users_{{ name }}_user: - file.managed: - - name: {{ home }}/.bashrc - - owner: {{ name }} - - group: {{ user_group }} - - mode: 644 - - source: - - salt://users/files/bashrc/{{ name }}/bashrc - - salt://users/files/bashrc/bashrc +{%- if manage -%} +users_{{ name }}_user_bashrc: + file.managed: + - name: {{ home }}/.bashrc + - user: {{ name }} + - group: {{ user_group }} + - mode: 644 + - source: + - salt://users/files/bashrc/{{ name }}/bashrc + - salt://users/files/bashrc/bashrc +{% endif %} {% endfor %} diff --git a/users/vimrc.sls b/users/vimrc.sls index 34131c5..e678bb6 100644 --- a/users/vimrc.sls +++ b/users/vimrc.sls @@ -3,25 +3,26 @@ include: - users - vim -extend: {% for name, user in pillar.get('users', {}).items() if user.absent is not defined or not user.absent %} {%- if user == None -%} {%- set user = {} -%} {%- endif -%} {%- set home = user.get('home', "/home/%s" % name) -%} - +{%- set manage = user.get('manage_vimrc', False) -%} {%- if 'prime_group' in user and 'name' in user['prime_group'] %} {%- set user_group = user.prime_group.name -%} {%- else -%} {%- set user_group = name -%} {%- endif %} - users_{{ name }}_user: - file.managed: - - name: {{ home }}/.vimrc - - owner: {{ name }} - - group: {{ user_group }} - - mode: 644 - - source: - - salt://users/files/vimrc/{{ name }}/vimrc - - salt://users/files/vimrc/vimrc +{%- if manage -%} +users_{{ name }}_user_vimrc: + file.managed: + - name: {{ home }}/.vimrc + - user: {{ name }} + - group: {{ user_group }} + - mode: 644 + - source: + - salt://users/files/vimrc/{{ name }}/vimrc + - salt://users/files/vimrc/vimrc +{% endif %} {% endfor %}