diff --git a/README.rst b/README.rst index 4d3279a..84c9a9f 100644 --- a/README.rst +++ b/README.rst @@ -34,10 +34,15 @@ is configured. Ensures the bashrc file exists in the users home directory. Set manage_bashrc: True in pillar per user. Defaults to False +``users.profile`` +---------------- + +Ensures the profile file exists in the users home directory. Set manage_profile: +True in pillar per user. Defaults to False + ``users.vimrc`` --------------- 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 ce7763b..c697889 100644 --- a/pillar.example +++ b/pillar.example @@ -12,6 +12,7 @@ users: createhome: True manage_vimrc: False manage_bashrc: False + manage_profile: False expire: 16426 sudouser: True # sudo_rules doesn't need the username as a prefix for the rule diff --git a/users/files/profile/profile b/users/files/profile/profile new file mode 100644 index 0000000..757ba0a --- /dev/null +++ b/users/files/profile/profile @@ -0,0 +1,22 @@ +# ~/.profile: executed by the command interpreter for login shells. +# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login +# exists. +# see /usr/share/doc/bash/examples/startup-files for examples. +# the files are located in the bash-doc package. + +# the default umask is set in /etc/profile; for setting the umask +# for ssh logins, install and configure the libpam-umask package. +#umask 022 + +# if running bash +if [ -n "$BASH_VERSION" ]; then + # include .bashrc if it exists + if [ -f "$HOME/.bashrc" ]; then + . "$HOME/.bashrc" + fi +fi + +# set PATH so it includes user's private bin if it exists +if [ -d "$HOME/bin" ] ; then + PATH="$HOME/bin:$PATH" +fi diff --git a/users/profile.sls b/users/profile.sls new file mode 100644 index 0000000..b62c096 --- /dev/null +++ b/users/profile.sls @@ -0,0 +1,27 @@ +{% from "users/map.jinja" import users with context %} +include: + - users + +{% 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_profile', 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 %} +{%- if manage -%} +users_{{ name }}_user_profile: + file.managed: + - name: {{ home }}/.profile + - user: {{ name }} + - group: {{ user_group }} + - mode: 644 + - source: + - salt://users/files/profile/{{ name }}/profile + - salt://users/files/profile/profile +{% endif %} +{% endfor %}