2012-03-07 22:38:43 +00:00
|
|
|
==============
|
|
|
|
Pillar of Salt
|
|
|
|
==============
|
|
|
|
|
2012-05-23 04:43:12 +00:00
|
|
|
Pillar is an interface for Salt designed to offer global values that can be
|
2013-04-05 23:41:39 +00:00
|
|
|
distributed to all minions. Pillar data is managed in a similar way as
|
2012-05-23 04:43:12 +00:00
|
|
|
the Salt State Tree.
|
2012-03-07 22:38:43 +00:00
|
|
|
|
2013-02-06 02:07:46 +00:00
|
|
|
Pillar was added to Salt in version 0.9.8
|
2012-03-07 22:38:43 +00:00
|
|
|
|
2013-02-06 02:47:09 +00:00
|
|
|
.. note:: Storing sensitive data
|
|
|
|
|
2013-04-10 16:00:20 +00:00
|
|
|
Unlike state tree, pillar data is only available for the targeted
|
2013-02-06 02:47:09 +00:00
|
|
|
minion specified by the matcher type. This makes it useful for
|
|
|
|
storing sensitive data specific to a particular minion.
|
|
|
|
|
2013-07-01 05:20:27 +00:00
|
|
|
|
2012-03-07 22:38:43 +00:00
|
|
|
Declaring the Master Pillar
|
|
|
|
===========================
|
|
|
|
|
|
|
|
The Salt Master server maintains a pillar_roots setup that matches the
|
2012-03-15 00:09:19 +00:00
|
|
|
structure of the file_roots used in the Salt file server. Like the
|
2012-03-07 22:38:43 +00:00
|
|
|
Salt file server the ``pillar_roots`` option in the master config is based
|
|
|
|
on environments mapping to directories. The pillar data is then mapped to
|
|
|
|
minions based on matchers in a top file which is laid out in the same way
|
2012-07-19 03:54:44 +00:00
|
|
|
as the state top file. Salt pillars can use the same matcher types as the
|
2012-08-04 22:42:21 +00:00
|
|
|
standard top file.
|
2012-03-07 22:38:43 +00:00
|
|
|
|
2012-05-16 10:58:35 +00:00
|
|
|
The configuration for the ``pillar_roots`` in the master config is identical in
|
|
|
|
behavior and function as the ``file_roots`` configuration:
|
2012-03-07 22:38:43 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
pillar_roots:
|
|
|
|
base:
|
|
|
|
- /srv/pillar
|
|
|
|
|
|
|
|
This example configuration declares that the base environment will be located
|
2013-01-20 05:15:24 +00:00
|
|
|
in the ``/srv/pillar`` directory. The top file used matches the name of the top
|
|
|
|
file used for States, and has the same structure:
|
2012-03-07 22:38:43 +00:00
|
|
|
|
2012-05-16 10:58:35 +00:00
|
|
|
``/srv/pillar/top.sls``
|
|
|
|
|
2012-03-07 22:38:43 +00:00
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
base:
|
|
|
|
'*':
|
|
|
|
- packages
|
2012-07-19 03:54:44 +00:00
|
|
|
|
2013-01-20 05:15:24 +00:00
|
|
|
This further example shows how to use other standard top matching types (grain
|
|
|
|
matching is used in this example) to deliver specific salt pillar data to minions
|
|
|
|
with different 'os' grains:
|
2013-01-20 05:04:22 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
dev:
|
2013-01-20 05:15:24 +00:00
|
|
|
'os:Debian':
|
2013-07-01 05:20:27 +00:00
|
|
|
- match: grain
|
2013-01-20 05:15:24 +00:00
|
|
|
- servers
|
2012-07-19 03:54:44 +00:00
|
|
|
|
2012-05-16 10:58:35 +00:00
|
|
|
``/srv/pillar/packages.sls``
|
2012-03-07 22:38:43 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
{% if grains['os'] == 'RedHat' %}
|
|
|
|
apache: httpd
|
|
|
|
git: git
|
|
|
|
{% elif grains['os'] == 'Debian' %}
|
|
|
|
apache: apache2
|
|
|
|
git: git-core
|
|
|
|
{% endif %}
|
2012-05-16 10:58:35 +00:00
|
|
|
|
2012-05-23 04:43:12 +00:00
|
|
|
Now this data can be used from within modules, renderers, State SLS files, and
|
|
|
|
more via the shared pillar `dict`_:
|
2012-03-07 22:38:43 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
apache:
|
|
|
|
pkg:
|
|
|
|
- installed
|
|
|
|
- name: {{ pillar['apache'] }}
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
git:
|
|
|
|
pkg:
|
|
|
|
- installed
|
|
|
|
- name: {{ pillar['git'] }}
|
2012-03-29 14:58:32 +00:00
|
|
|
|
2012-05-23 04:43:12 +00:00
|
|
|
.. _`dict`: http://docs.python.org/library/stdtypes.html#mapping-types-dict
|
|
|
|
|
2013-06-19 00:26:21 +00:00
|
|
|
|
|
|
|
Note that you cannot just list key/value-information in ``top.sls``.
|
|
|
|
|
|
|
|
|
2013-07-01 05:20:27 +00:00
|
|
|
Including Other Pillars
|
|
|
|
=======================
|
|
|
|
|
|
|
|
Pillar SLS files may include other pillar files, similar to State files.
|
|
|
|
Two syntaxes are available for this purpose. The simple form simply includes
|
|
|
|
the additional pillar as if it were part of the same file:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
include:
|
|
|
|
- users
|
|
|
|
|
|
|
|
The full include form allows two additional options -- passing default values
|
|
|
|
to the templating engine for the included pillar file as well as an optional
|
|
|
|
key under which to nest the results of the included pillar:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
include:
|
|
|
|
- users:
|
|
|
|
defaults:
|
|
|
|
- sudo: ['bob', 'paul']
|
|
|
|
key: users
|
|
|
|
|
|
|
|
With this form, the included file, users.sls, will be nested within the 'users'
|
|
|
|
key of the compiled pillar. Additionally, the 'sudo' value will be available
|
|
|
|
as a template variable to users.sls.
|
|
|
|
|
|
|
|
|
2012-08-24 06:49:04 +00:00
|
|
|
Viewing Minion Pillar
|
|
|
|
=====================
|
|
|
|
|
|
|
|
Once the pillar is set up the data can be viewed on the minion via the
|
2013-06-19 00:26:21 +00:00
|
|
|
``pillar`` module, the pillar module comes with two functions,
|
|
|
|
:mod:`pillar.data <salt.modules.pillar.data>` and and :mod:`pillar.raw
|
|
|
|
<salt.modules.pillar.raw>`. :mod:`pillar.data <salt.modules.pillar.data>` will
|
|
|
|
return a freshly reloaded pillar and :mod:`pillar.raw
|
|
|
|
<salt.modules.pillar.raw>` will return the current pillar without a refresh:
|
2012-08-24 06:49:04 +00:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
# salt '*' pillar.data
|
|
|
|
|
2013-02-05 18:07:44 +00:00
|
|
|
|
2013-06-19 00:26:21 +00:00
|
|
|
Pillar "get" Function
|
|
|
|
=====================
|
|
|
|
|
|
|
|
.. versionadded:: 0.14.0
|
|
|
|
|
|
|
|
The :mod:`pillar.get <salt.modules.pillar.get>` function works much in the same
|
|
|
|
way as the ``get`` method in a python dict, but with an enhancement: nested
|
|
|
|
dict components can be extracted using a `:` delimiter.
|
|
|
|
|
|
|
|
If a structure like this is in pillar:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
foo:
|
|
|
|
bar:
|
|
|
|
baz: qux
|
|
|
|
|
|
|
|
Extracting it from the raw pillar in an sls formula or file template is done
|
|
|
|
this way:
|
|
|
|
|
|
|
|
.. code-block:: jinja
|
|
|
|
|
|
|
|
{{ pillar['foo']['bar']['baz'] }}
|
|
|
|
|
|
|
|
Now, with the new :mod:`pillar.get <salt.modules.pillar.get>` function the data
|
|
|
|
can be safely gathered and a default can be set, allowing the template to fall
|
|
|
|
back if the value is not available:
|
|
|
|
|
|
|
|
.. code-block:: jinja
|
|
|
|
|
|
|
|
{{ salt['pillar.get']('foo:bar:baz', 'qux') }}
|
|
|
|
|
|
|
|
This makes handling nested structures much easier.
|
2012-05-16 10:58:35 +00:00
|
|
|
|
|
|
|
|
2012-03-29 14:58:32 +00:00
|
|
|
Refreshing Pillar Data
|
|
|
|
======================
|
|
|
|
|
|
|
|
When pillar data is changed on the master the minions need to refresh the data
|
|
|
|
locally. This is done with the ``saltutil.refresh_pillar`` function.
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
salt '*' saltutil.refresh_pillar
|
2012-05-23 16:34:44 +00:00
|
|
|
|
2013-02-05 18:07:44 +00:00
|
|
|
This function triggers the minion to refresh the pillar and will always return
|
|
|
|
``True``
|
|
|
|
|
2012-05-23 16:34:44 +00:00
|
|
|
Targeting with Pillar
|
|
|
|
=====================
|
|
|
|
|
2012-05-23 16:40:36 +00:00
|
|
|
Pillar data can be used when targeting minions. This allows for ultimate
|
|
|
|
control and flexibility when targeting minions.
|
2012-05-23 16:34:44 +00:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
salt -I 'somekey:specialvalue' test.ping
|
2013-04-22 17:59:49 +00:00
|
|
|
|
2013-06-14 02:05:19 +00:00
|
|
|
Like with :doc:`Grains <../targeting/grains>`, it is possible to use globbing
|
|
|
|
as well as match nested values in Pillar, by adding colons for each level that
|
|
|
|
is being traversed. The below example would match minions with a pillar named
|
|
|
|
``foo``, which is a dict containing a key ``bar``, with a value beginning with
|
|
|
|
``baz``::
|
2013-06-14 01:29:04 +00:00
|
|
|
|
|
|
|
salt -I 'foo:bar:baz*'
|
|
|
|
|
|
|
|
|
2013-04-22 17:59:49 +00:00
|
|
|
Master Config In Pillar
|
|
|
|
=======================
|
|
|
|
|
|
|
|
For convenience the data stored in the master configuration file is made
|
|
|
|
available in all minion's pillars. This makes global configuration of services
|
|
|
|
and systems very easy but may not be desired if sensitive data is stored in the
|
|
|
|
master configuration.
|
|
|
|
|
|
|
|
To disable the master config from being added to the pillar set `pillar_opts`
|
|
|
|
to `False`:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
pillar_opts: False
|