Updated the Nodegroup docs to include how to target nodegroups in SLS Jinja

See issue #28268
This commit is contained in:
Sam Michel 2015-10-26 11:11:01 -07:00
parent 6a92bfbd42
commit f2a6bc94df

View file

@ -67,3 +67,33 @@ nodegroup`` on the line directly following the nodegroup name.
A limited amount of functionality, such as targeting with -N from the command-line may be
available without a restart.
Using Nodegroups in SLS files
=============================
To use Nodegroups in Jinja logic for SLS files, the :conf_master:'pillar_opts' option in ``/etc/salt/master`` must be set to "True". This will pass the master's configuration as Pillar data to each minion.
.. note::
If the master's configuration contains any sensitive data, this will be passed to each minion. Do not enable this
option if you have any configuration data that you do not want to get on your minions.
Also, if you make changes to your nodegroups, you might need to run ``salt '*' saltutil.refresh_pillar`` after
restarting the master.
Once pillar_opts is enabled, you can find the nodegroups under the "master" pillar. To make sure that only the correct minions are targeted, you should use each matcher for the nodegroup definition.
For example, to check if a minion is in the 'webserver' nodegroup:
.. code-block:: yaml
nodegroups:
webserver: 'G@os:Debian and L@minion1,minion2'
.. code-block:: yaml
{% if grains.id in salt['pillar.get']('master:nodegroups:webserver', []) and grains.os in salt['pillar.get']('master:nodegroups:webserver', []) %}
...
{% endif %}
.. note::
If you do not include all of the matchers used to define a nodegroup, Salt might incorrectly target minions
that meet some of the nodegroup requirements, but not all of them.