Skip to content

Instantly share code, notes, and snippets.

@godber
Last active December 18, 2015 11:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save godber/5777861 to your computer and use it in GitHub Desktop.
Save godber/5777861 to your computer and use it in GitHub Desktop.
A Salt SLS Module for managing a per host /etc/salt/minion.d/grains.conf file based on matching host IDs. If there is a host.conf file, that will be used, if not, then default.conf will be used.
salt-minion:
pkg:
- installed
service:
- running
- require:
- pkg: salt-minion
- watch:
- file: /etc/salt/minion.d/grains.conf
/etc/salt/minion.d/grains.conf:
file:
- managed
{% if salt['cp.hash_file']('salt://minion/' + grains['id'] + '.conf') %}
- source: {{'salt://minion/' + grains['id'] + '.conf'}}
{% else %}
- source: salt://minion/default.conf
{% endif %}
salt-minion:
pkg:
- installed
service:
- running
- require:
- pkg: salt-minion
- watch:
- file: /etc/salt/minion.d/grains.conf
/etc/salt/minion.d/grains.conf:
file:
- managed
- source:
- salt://minion/{{ + grains['id'] + }}.conf
- salt://minion/default.conf
@godber
Copy link
Author

godber commented Jun 17, 2013

As it turns out, there is no reason to do what is shown in gistfile1.yml. sources can be given a list and will use the first one it finds. gistfile2.yml provides a better example.

I discovered this here:
http://docs.saltstack.com/ref/states/all/salt.states.file.html#operations-on-files-directories-and-symlinks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment