2014-02-27 21:36:13 +00:00
|
|
|
.. _targeting-grains:
|
|
|
|
|
2016-02-01 03:10:02 +00:00
|
|
|
======================
|
|
|
|
Targeting using Grains
|
|
|
|
======================
|
2011-05-23 07:17:30 +00:00
|
|
|
|
2016-02-01 03:10:02 +00:00
|
|
|
Grain data can be used when targeting minions.
|
2011-06-24 01:36:44 +00:00
|
|
|
|
2016-02-01 03:10:02 +00:00
|
|
|
For example, the following matches all CentOS minions:
|
2013-08-11 02:55:51 +00:00
|
|
|
|
|
|
|
.. code-block:: bash
|
2012-05-06 18:46:08 +00:00
|
|
|
|
|
|
|
salt -G 'os:CentOS' test.ping
|
|
|
|
|
2013-08-11 02:55:51 +00:00
|
|
|
Match all minions with 64-bit CPUs, and return number of CPU cores for each
|
|
|
|
matching minion:
|
|
|
|
|
|
|
|
.. code-block:: bash
|
2012-05-06 18:46:08 +00:00
|
|
|
|
|
|
|
salt -G 'cpuarch:x86_64' grains.item num_cpus
|
|
|
|
|
2013-06-14 02:05:19 +00:00
|
|
|
Additionally, globs can be used in grain matches, and grains that are nested in
|
2018-05-28 21:13:12 +00:00
|
|
|
a dictionary can be matched by adding a colon for each level that is traversed.
|
|
|
|
For example, the following will match hosts that have a grain called
|
|
|
|
``ec2_tags``, which itself is a dictionary with a key named ``environment``,
|
|
|
|
which has a value that contains the word ``production``:
|
2013-08-11 02:55:51 +00:00
|
|
|
|
|
|
|
.. code-block:: bash
|
2013-06-14 01:28:11 +00:00
|
|
|
|
|
|
|
salt -G 'ec2_tags:environment:*production*'
|
|
|
|
|
2016-02-01 03:10:02 +00:00
|
|
|
.. important::
|
|
|
|
See :ref:`Is Targeting using Grain Data Secure? <faq-grain-security>` for
|
|
|
|
important security information.
|
2013-06-14 01:28:11 +00:00
|
|
|
|