Merge pull request #90 from spoage/manage-arbitrary-user-files
Manage arbitrary user files
This commit is contained in:
commit
57811826af
@ -46,3 +46,8 @@ True in pillar per user. Defaults to False
|
|||||||
Ensures the vimrc file exists in the users home directory. Set manage_vimrc:
|
Ensures the vimrc file exists in the users home directory. Set manage_vimrc:
|
||||||
True in pillar per user. Defaults to False
|
True in pillar per user. Defaults to False
|
||||||
This depends on the vim-formula to be installed
|
This depends on the vim-formula to be installed
|
||||||
|
|
||||||
|
``users.user_files``
|
||||||
|
---------------
|
||||||
|
|
||||||
|
Permits the abitrary management of files. See pillar.example for configuration details.
|
||||||
|
@ -84,6 +84,13 @@ users:
|
|||||||
44444444
|
44444444
|
||||||
55555555
|
55555555
|
||||||
|
|
||||||
|
user_files:
|
||||||
|
enabled: True
|
||||||
|
# 'source' allows you to define an arbitrary directory to sync, useful to use for default files.
|
||||||
|
# should be a salt fileserver path either with or without 'salt://'
|
||||||
|
# if not present, it defaults to 'salt://users/files/user/<username>
|
||||||
|
source: users/files/default
|
||||||
|
|
||||||
## Absent user
|
## Absent user
|
||||||
cuser:
|
cuser:
|
||||||
absent: True
|
absent: True
|
||||||
|
0
users/files/user/.keep
Normal file
0
users/files/user/.keep
Normal file
@ -2,6 +2,7 @@
|
|||||||
{% from "users/map.jinja" import users with context %}
|
{% from "users/map.jinja" import users with context %}
|
||||||
{% set used_sudo = [] %}
|
{% set used_sudo = [] %}
|
||||||
{% set used_googleauth = [] %}
|
{% set used_googleauth = [] %}
|
||||||
|
{% set used_user_files = [] %}
|
||||||
|
|
||||||
{%- 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.absent is not defined or not user.absent %}
|
||||||
@ -14,9 +15,12 @@
|
|||||||
{%- if 'google_auth' in user %}
|
{%- if 'google_auth' in user %}
|
||||||
{%- do used_googleauth.append(1) %}
|
{%- do used_googleauth.append(1) %}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
{%- if salt['pillar.get']('users:' ~ name ~ ':user_files:enabled', False) %}
|
||||||
|
{%- do used_user_files.append(1) %}
|
||||||
|
{%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
{%- if used_sudo or used_googleauth %}
|
{%- if used_sudo or used_googleauth or used_user_files %}
|
||||||
include:
|
include:
|
||||||
{%- if used_sudo %}
|
{%- if used_sudo %}
|
||||||
- users.sudo
|
- users.sudo
|
||||||
@ -24,6 +28,9 @@ include:
|
|||||||
{%- if used_googleauth %}
|
{%- if used_googleauth %}
|
||||||
- users.googleauth
|
- users.googleauth
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
{%- if used_user_files %}
|
||||||
|
- users.user_files
|
||||||
|
{%- endif %}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
{% for name, user in pillar.get('users', {}).items()
|
{% for name, user in pillar.get('users', {}).items()
|
||||||
|
44
users/user_files.sls
Normal file
44
users/user_files.sls
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
{% from "users/map.jinja" import users with context -%}
|
||||||
|
|
||||||
|
include:
|
||||||
|
- users
|
||||||
|
|
||||||
|
{% set userfile_dirs = salt['cp.list_master_dirs'](prefix='users/files/user/') -%}
|
||||||
|
{%- for username, user in salt['pillar.get']('users', {}).items() if (user.absent is not defined or not user.absent) -%}
|
||||||
|
{%- set user_files = salt['pillar.get'](('users:' ~ username ~ ':user_files'), {'enabled': False}) -%}
|
||||||
|
{%- set user_group = salt['pillar.get'](('users:' ~ username ~ ':prime_group:name'), username) -%}
|
||||||
|
{%- if user_files.enabled -%}
|
||||||
|
|
||||||
|
{%- if user_files.source is defined -%}
|
||||||
|
{%- if user_files.source.startswith('salt://') -%}
|
||||||
|
{%- set file_source = user_files.source -%}
|
||||||
|
{%- else -%}
|
||||||
|
{%- set file_source = ('salt://' ~ user.user_files.source) -%}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- set skip_user = False -%}
|
||||||
|
{%- else -%}
|
||||||
|
{%- if ('users/files/user/' ~ username) in userfile_dirs -%}
|
||||||
|
{%- set file_source = ('salt://users/files/user/' ~ username) -%}
|
||||||
|
{%- set skip_user = False -%}
|
||||||
|
{%- else -%}
|
||||||
|
{%- set skip_user = True -%}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- endif -%}
|
||||||
|
|
||||||
|
{%- if not skip_user %}
|
||||||
|
users_userfiles_{{ username }}_recursive:
|
||||||
|
file.recurse:
|
||||||
|
- name: {{ user.home }}
|
||||||
|
- source: {{ file_source }}
|
||||||
|
- user: {{ username }}
|
||||||
|
- group: {{ user_group }}
|
||||||
|
- clean: False
|
||||||
|
- include_empty: True
|
||||||
|
- keep_symlinks: True
|
||||||
|
- require:
|
||||||
|
- user: users_{{ username }}_user
|
||||||
|
- file: users_{{ username }}_user
|
||||||
|
{% endif -%}
|
||||||
|
|
||||||
|
{%- endif -%}
|
||||||
|
{%- endfor -%}
|
Loading…
Reference in New Issue
Block a user