1
0

include.rst 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. .. _states-include:
  2. ===================
  3. Include and Exclude
  4. ===================
  5. Salt SLS files can include other SLS files and exclude SLS files that have been
  6. otherwise included. This allows for an SLS file to easily extend or manipulate
  7. other SLS files.
  8. Include
  9. =======
  10. When other SLS files are included, everything defined in the included SLS file
  11. will be added to the state run. When including define a list of SLS formulas
  12. to include:
  13. .. code-block:: yaml
  14. include:
  15. - http
  16. - libvirt
  17. The include statement will include SLS formulas from the same environment
  18. that the including SLS formula is in. But the environment can be explicitly
  19. defined in the configuration to override the running environment, therefore
  20. if an SLS formula needs to be included from an external environment named "dev"
  21. the following syntax is used:
  22. .. code-block:: yaml
  23. include:
  24. - dev: http
  25. **NOTE**: ``include`` does not simply inject the states where you place it
  26. in the SLS file. If you need to guarantee order of execution, consider using
  27. requisites.
  28. .. include:: ../../_incl/_incl/sls_filename_cant_contain_period.rst
  29. Relative Include
  30. ================
  31. In Salt 0.16.0, the capability to include SLS formulas which are relative to
  32. the running SLS formula was added. Simply precede the formula name with a
  33. ``.``:
  34. .. code-block:: yaml
  35. include:
  36. - .virt
  37. - .virt.hyper
  38. In Salt 2015.8, the ability to include SLS formulas which are relative to the
  39. parents of the running SLS formula was added. In order to achieve this,
  40. precede the formula name with more than one ``.`` (dot). Much like Python's
  41. relative import abilities, two or more leading dots represent a relative
  42. include of the parent or parents of the current package, with each ``.``
  43. representing one level after the first.
  44. The following SLS configuration, if placed within ``example.dev.virtual``,
  45. would result in ``example.http`` and ``base`` being included respectively:
  46. .. code-block:: yaml
  47. include:
  48. - ..http
  49. - ...base
  50. Exclude
  51. =======
  52. The exclude statement, added in Salt 0.10.3, allows an SLS to hard exclude
  53. another SLS file or a specific id. The component is excluded after the
  54. high data has been compiled, so nothing should be able to override an
  55. exclude.
  56. Since the exclude can remove an id or an sls the type of component to exclude
  57. needs to be defined. An exclude statement that verifies that the running
  58. :ref:`highstate <running-highstate>` does not contain the ``http`` sls and the
  59. ``/etc/vimrc`` id would look like this:
  60. .. code-block:: yaml
  61. exclude:
  62. - sls: http
  63. - id: /etc/vimrc
  64. .. note::
  65. The current state processing flow checks for duplicate IDs before
  66. processing excludes. An error occurs if duplicate IDs are present even if
  67. one of the IDs is targeted by an ``exclude``.