From 33287f650f9b3e6961b6edfb7fdf7d154f377995 Mon Sep 17 00:00:00 2001 From: Hatifnatt Date: Thu, 23 Mar 2017 12:19:06 +0300 Subject: [PATCH 1/3] Add ability to specify mode for files and symlinks in user_files --- pillar.example | 5 +++++ users/user_files.sls | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/pillar.example b/pillar.example index 256303a..c9f1cbe 100644 --- a/pillar.example +++ b/pillar.example @@ -119,6 +119,11 @@ users: # should be a salt fileserver path either with or without 'salt://' # if not present, it defaults to 'salt://users/files/user/ source: users/files/default + # You can specify octal mode for files and symlinks that will be copied. Since version 2016.11.0 + # it's possible to use 'keep' for file_mode, to preserve file original mode, thus you can save + # execution bit for example. + file_mode: keep + sym_mode: 640 ## Absent user cuser: diff --git a/users/user_files.sls b/users/user_files.sls index 461628b..dc654fe 100644 --- a/users/user_files.sls +++ b/users/user_files.sls @@ -9,6 +9,8 @@ include: {%- set user_files = salt['pillar.get'](('users:' ~ username ~ ':user_files'), {'enabled': False}) -%} {%- set user_group = salt['pillar.get'](('users:' ~ username ~ ':prime_group:name'), username) -%} {%- set user_home = salt['pillar.get'](('users:' ~ username ~ ':home'), current.get('home', '/home/' ~ username )) -%} +{%- set user_files_file_mode = salt['pillar.get'](('users:' ~ username ~ ':user_files:file_mode'), False) -%} +{%- set user_files_sym_mode = salt['pillar.get'](('users:' ~ username ~ ':user_files:sym_mode'), False) -%} {%- if user_files.enabled -%} {%- if user_files.source is defined -%} @@ -35,6 +37,12 @@ users_userfiles_{{ username }}_recursive: - user: {{ username }} - group: {{ user_group }} - clean: False + {% if user_files_file_mode -%} + - file_mode: {{ user_files_file_mode }} + {% endif -%} + {% if user_files_sym_mode -%} + - sym_mode: {{ user_files_sym_mode }} + {% endif -%} - include_empty: True - keep_symlinks: True - require: From 48416398e3d4e68b9c164c055bb434773bda71bd Mon Sep 17 00:00:00 2001 From: Hatifnatt Date: Thu, 27 Jul 2017 04:29:47 +0300 Subject: [PATCH 2/3] Change False to None in user_files to be closer to Salt default values. --- users/user_files.sls | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/users/user_files.sls b/users/user_files.sls index dc654fe..eb01202 100644 --- a/users/user_files.sls +++ b/users/user_files.sls @@ -9,8 +9,8 @@ include: {%- set user_files = salt['pillar.get'](('users:' ~ username ~ ':user_files'), {'enabled': False}) -%} {%- set user_group = salt['pillar.get'](('users:' ~ username ~ ':prime_group:name'), username) -%} {%- set user_home = salt['pillar.get'](('users:' ~ username ~ ':home'), current.get('home', '/home/' ~ username )) -%} -{%- set user_files_file_mode = salt['pillar.get'](('users:' ~ username ~ ':user_files:file_mode'), False) -%} -{%- set user_files_sym_mode = salt['pillar.get'](('users:' ~ username ~ ':user_files:sym_mode'), False) -%} +{%- set user_files_file_mode = salt['pillar.get'](('users:' ~ username ~ ':user_files:file_mode'), None) -%} +{%- set user_files_sym_mode = salt['pillar.get'](('users:' ~ username ~ ':user_files:sym_mode'), None) -%} {%- if user_files.enabled -%} {%- if user_files.source is defined -%} @@ -37,10 +37,10 @@ users_userfiles_{{ username }}_recursive: - user: {{ username }} - group: {{ user_group }} - clean: False - {% if user_files_file_mode -%} + {% if user_files_file_mode is not None -%} - file_mode: {{ user_files_file_mode }} {% endif -%} - {% if user_files_sym_mode -%} + {% if user_files_sym_mode is not None -%} - sym_mode: {{ user_files_sym_mode }} {% endif -%} - include_empty: True From 335bc3109575c361999edf2cced44356a943703e Mon Sep 17 00:00:00 2001 From: Hatifnatt Date: Thu, 27 Jul 2017 16:27:44 +0300 Subject: [PATCH 3/3] 'None' works in an unexpected way. Reverting back to 'False'. This reverts commit 48416398e3d4e68b9c164c055bb434773bda71bd. --- users/user_files.sls | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/users/user_files.sls b/users/user_files.sls index eb01202..dc654fe 100644 --- a/users/user_files.sls +++ b/users/user_files.sls @@ -9,8 +9,8 @@ include: {%- set user_files = salt['pillar.get'](('users:' ~ username ~ ':user_files'), {'enabled': False}) -%} {%- set user_group = salt['pillar.get'](('users:' ~ username ~ ':prime_group:name'), username) -%} {%- set user_home = salt['pillar.get'](('users:' ~ username ~ ':home'), current.get('home', '/home/' ~ username )) -%} -{%- set user_files_file_mode = salt['pillar.get'](('users:' ~ username ~ ':user_files:file_mode'), None) -%} -{%- set user_files_sym_mode = salt['pillar.get'](('users:' ~ username ~ ':user_files:sym_mode'), None) -%} +{%- set user_files_file_mode = salt['pillar.get'](('users:' ~ username ~ ':user_files:file_mode'), False) -%} +{%- set user_files_sym_mode = salt['pillar.get'](('users:' ~ username ~ ':user_files:sym_mode'), False) -%} {%- if user_files.enabled -%} {%- if user_files.source is defined -%} @@ -37,10 +37,10 @@ users_userfiles_{{ username }}_recursive: - user: {{ username }} - group: {{ user_group }} - clean: False - {% if user_files_file_mode is not None -%} + {% if user_files_file_mode -%} - file_mode: {{ user_files_file_mode }} {% endif -%} - {% if user_files_sym_mode is not None -%} + {% if user_files_sym_mode -%} - sym_mode: {{ user_files_sym_mode }} {% endif -%} - include_empty: True