directory-structure


SaltStack: Use directory as source only if it exists


I'd like to know if there's a way of running a SaltStack state only if a directory source is defined in the master.
Basically, I want to allow fo users to put certain configuration files in their HOME directory. Most of the users won't have anything special, but some of them might (a custom .vimrc, for instance)
What I'd like to do is execute a file.recurse for the user's HOMEdirectory only if that directory exists in master.
As of now, I have the following:
{% for username in pillar['users'] %}
{{ username }}:
user:
- present
- home: /home/{{ username }}
[ . . . ] # (yadda, yadda, yadda)
# ToDo: Is there a way of not running this AT ALL if the users's directory is
# not present?
/home/{{ username }}:
file.recurse:
- user: {{ username }}
- group: ubuntu
- source:
- salt://users/{{ username }}
- require:
- user: {{ username }}
{% endfor %}
What I want to do is what in the code appears as the ToDo: If there's a directory salt://users/{{ username }} in the salt tree (or in the salt master), then execute the file.recurse with that directory as the source for the file.recurse. Otherwise, just skip that state and use with whatever default content of $HOME is has when a user is created (just do nothing, I mean).
I thought adding an onlyif clause to the file.recurse configuration (something like - onlyif: test -e salt://users/{{ username }} would help... but nopes... I also tried to create an empty directory in salt://users/empty_dir/ and pass it as a default (as described here for a file.managed), but that trick doesn't work with file.recurse (at least not yet):
Thank you in advance.
You could try something similar to
{% for username in pillar['users'] %}
{{ username }}:
user:
- present
- home: /home/{{ username }}
[ . . . ] # (yadda, yadda, yadda)
# NB!!!! POTENTIAL PERF BOTTLENECK
{% if 'users/'+username not in salt['cp.list_master_dirs'](prefix='users') %}
/home/{{ username }}:
file.recurse:
- user: {{ username }}
- group: ubuntu
- source:
- salt://users/{{ username }}
- require:
- user: {{ username }}
{% endif %}
{% endfor %}

Related Links

can I place the js,css,images files under resources folder and place this resource folder under src/main/webapp folder?
VMS directory issue
SaltStack: Use directory as source only if it exists
Is it safe to clone a git repository into its own .git directory?
CAB Files MAKECAB.exe Way to store directory structure
how do I create the URL “m.mysite.com” from mysite.com?
URL structure for inner pages?
Ideal directory structure for web application
Development directory Structure [closed]

Categories

HOME
ms-access
gitlab
pypi
cplex
q
jsp-tags
survey
fingerprint
acquia
wamp
python-unittest
dax
mapserver
modelica
nstableview
apache-metamodel
oracle-coherence
text-rendering
nas
tar
telerik-reporting
restful-authentication
centos6.5
semantic-analysis
tooltipster
fifo
flink-streaming
bcd
webtest
android-kernel
mmenu
vxworks
hue
bootstrapper
unoconv
grid.mvc
dynamic-reports
boost-multi-index
clean-architecture
ionicons
jlink
aurelia-validation
elgg
typed-lambda-calculus
gcsfuse
iso8601
pycaffe
infix-notation
adxstudio-portals
file-writing
fody
pickadate
itextpdf
tcpserver
msys
marching-cubes
wyam
ionic
graph-drawing
oberon
heisenbug
sgen
picturefill
centos5
dexterity
back-stack
random-seed
xamlparseexception
sqlperformance
flashvars
mhtml
first-responder
frameset
pysimplesoap
blackberry-playbook
xdomainrequest
file-comparison
winbugs14
lpeg
asp.net-mvc-areas
avatar
noscript

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile