2016-12-15 23:45:51 +00:00
|
|
|
.. _states-include:
|
|
|
|
|
2012-09-22 21:55:32 +00:00
|
|
|
===================
|
|
|
|
Include and Exclude
|
|
|
|
===================
|
|
|
|
|
2015-07-23 23:42:25 +00:00
|
|
|
Salt SLS files can include other SLS files and exclude SLS files that have been
|
|
|
|
otherwise included. This allows for an SLS file to easily extend or manipulate
|
|
|
|
other SLS files.
|
2012-09-22 21:55:32 +00:00
|
|
|
|
2013-04-29 02:19:43 +00:00
|
|
|
Include
|
|
|
|
=======
|
|
|
|
|
2015-07-23 23:42:25 +00:00
|
|
|
When other SLS files are included, everything defined in the included SLS file
|
|
|
|
will be added to the state run. When including define a list of SLS formulas
|
2013-04-29 02:19:43 +00:00
|
|
|
to include:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
include:
|
|
|
|
- http
|
|
|
|
- libvirt
|
|
|
|
|
2015-07-23 23:42:25 +00:00
|
|
|
The include statement will include SLS formulas from the same environment
|
|
|
|
that the including SLS formula is in. But the environment can be explicitly
|
2013-04-29 02:19:43 +00:00
|
|
|
defined in the configuration to override the running environment, therefore
|
2015-07-23 23:42:25 +00:00
|
|
|
if an SLS formula needs to be included from an external environment named "dev"
|
2013-04-29 02:19:43 +00:00
|
|
|
the following syntax is used:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
include:
|
|
|
|
- dev: http
|
|
|
|
|
2015-07-23 23:42:25 +00:00
|
|
|
**NOTE**: ``include`` does not simply inject the states where you place it
|
2016-03-01 15:36:23 +00:00
|
|
|
in the SLS file. If you need to guarantee order of execution, consider using
|
2015-05-20 14:46:03 +00:00
|
|
|
requisites.
|
|
|
|
|
2015-05-18 16:12:07 +00:00
|
|
|
.. include:: ../../_incl/_incl/sls_filename_cant_contain_period.rst
|
2015-01-20 05:02:26 +00:00
|
|
|
|
2013-05-16 23:51:50 +00:00
|
|
|
Relative Include
|
|
|
|
================
|
|
|
|
|
2015-07-23 23:42:25 +00:00
|
|
|
In Salt 0.16.0, the capability to include SLS formulas which are relative to
|
|
|
|
the running SLS formula was added. Simply precede the formula name with a
|
|
|
|
``.``:
|
2013-05-16 23:51:50 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
include:
|
|
|
|
- .virt
|
|
|
|
- .virt.hyper
|
|
|
|
|
2015-07-23 23:42:25 +00:00
|
|
|
In Salt 2015.8, the ability to include SLS formulas which are relative to the
|
|
|
|
parents of the running SLS formula was added. In order to achieve this,
|
|
|
|
precede the formula name with more than one ``.`` (dot). Much like Python's
|
|
|
|
relative import abilities, two or more leading dots represent a relative
|
|
|
|
include of the parent or parents of the current package, with each ``.``
|
|
|
|
representing one level after the first.
|
2015-07-21 06:19:04 +00:00
|
|
|
|
2015-07-23 23:42:25 +00:00
|
|
|
The following SLS configuration, if placed within ``example.dev.virtual``,
|
|
|
|
would result in ``example.http`` and ``base`` being included respectively:
|
2015-07-21 06:19:04 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
include:
|
|
|
|
- ..http
|
|
|
|
- ...base
|
|
|
|
|
|
|
|
|
2012-09-22 21:55:32 +00:00
|
|
|
Exclude
|
|
|
|
=======
|
|
|
|
|
2015-07-23 23:42:25 +00:00
|
|
|
The exclude statement, added in Salt 0.10.3, allows an SLS to hard exclude
|
|
|
|
another SLS file or a specific id. The component is excluded after the
|
2012-09-22 21:55:32 +00:00
|
|
|
high data has been compiled, so nothing should be able to override an
|
|
|
|
exclude.
|
|
|
|
|
2016-03-22 03:56:17 +00:00
|
|
|
Since the exclude can remove an id or an sls the type of component to exclude
|
2015-07-23 23:42:25 +00:00
|
|
|
needs to be defined. An exclude statement that verifies that the running
|
2016-03-22 03:56:17 +00:00
|
|
|
:ref:`highstate <running-highstate>` does not contain the ``http`` sls and the
|
|
|
|
``/etc/vimrc`` id would look like this:
|
2012-09-22 21:55:32 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
exclude:
|
|
|
|
- sls: http
|
2015-01-20 05:02:26 +00:00
|
|
|
- id: /etc/vimrc
|
2016-02-24 23:56:52 +00:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
The current state processing flow checks for duplicate IDs before
|
|
|
|
processing excludes. An error occurs if duplicate IDs are present even if
|
|
|
|
one of the IDs is targeted by an ``exclude``.
|
2016-03-24 21:48:00 +00:00
|
|
|
|