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 HOME
directory 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.