1
0

compound.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. .. _targeting-compound:
  2. =================
  3. Compound matchers
  4. =================
  5. Compound matchers allow very granular minion targeting using any of Salt's
  6. matchers. The default matcher is a :mod:`glob <python2:fnmatch>` match, just as
  7. with CLI and :term:`top file <Top File>` matching. To match using anything other than a
  8. glob, prefix the match string with the appropriate letter from the table below,
  9. followed by an ``@`` sign.
  10. ====== ==================== ============================================================== =============================================
  11. Letter Match Type Example :ref:`Alt Delimiter? <target-alt-delimiters>`
  12. ====== ==================== ============================================================== =============================================
  13. G Grains glob ``G@os:Ubuntu`` Yes
  14. E PCRE Minion ID ``E@web\d+\.(dev|qa|prod)\.loc`` No
  15. P Grains PCRE ``P@os:(RedHat|Fedora|CentOS)`` Yes
  16. L List of minions ``L@minion1.example.com,minion3.domain.com or bl*.domain.com`` No
  17. I Pillar glob ``I@pdata:foobar`` Yes
  18. J Pillar PCRE ``J@pdata:^(foo|bar)$`` Yes
  19. S Subnet/IP address ``S@192.168.1.0/24`` or ``S@192.168.1.100`` No
  20. R Range cluster ``R@%foo.bar`` No
  21. N Nodegroups ``N@group1`` No
  22. ====== ==================== ============================================================== =============================================
  23. Matchers can be joined using boolean ``and``, ``or``, and ``not`` operators.
  24. For example, the following string matches all Debian minions with a hostname
  25. that begins with ``webserv``, as well as any minions that have a hostname which
  26. matches the :mod:`regular expression <python2:re>` ``web-dc1-srv.*``:
  27. .. code-block:: bash
  28. salt -C 'webserv* and G@os:Debian or E@web-dc1-srv.*' test.version
  29. That same example expressed in a :term:`top file <Top File>` looks like the following:
  30. .. code-block:: yaml
  31. base:
  32. 'webserv* and G@os:Debian or E@web-dc1-srv.*':
  33. - match: compound
  34. - webserver
  35. .. versionadded:: 2015.8.0
  36. Excluding a minion based on its ID is also possible:
  37. .. code-block:: bash
  38. salt -C 'not web-dc1-srv' test.version
  39. Versions prior to 2015.8.0 a leading ``not`` was not supported in compound
  40. matches. Instead, something like the following was required:
  41. .. code-block:: bash
  42. salt -C '* and not G@kernel:Darwin' test.version
  43. Excluding a minion based on its ID was also possible:
  44. .. code-block:: bash
  45. salt -C '* and not web-dc1-srv' test.version
  46. Precedence Matching
  47. -------------------
  48. Matchers can be grouped together with parentheses to explicitly declare precedence amongst groups.
  49. .. code-block:: bash
  50. salt -C '( ms-1 or G@id:ms-3 ) and G@id:ms-3' test.version
  51. .. note::
  52. Be certain to note that spaces are required between the parentheses and targets. Failing to obey this
  53. rule may result in incorrect targeting!
  54. .. _target-alt-delimiters:
  55. Alternate Delimiters
  56. --------------------
  57. .. versionadded:: 2015.8.0
  58. Matchers that target based on a key value pair use a colon (``:``) as
  59. a delimiter. Matchers with a ``Yes`` in the ``Alt Delimiters`` column
  60. in the previous table support specifying an alternate delimiter character.
  61. This is done by specifying an alternate delimiter character between the leading
  62. matcher character and the ``@`` pattern separator character. This avoids
  63. incorrect interpretation of the pattern in the case that ``:`` is part of the
  64. grain or pillar data structure traversal.
  65. .. code-block:: bash
  66. salt -C 'J|@foo|bar|^foo:bar$ or J!@gitrepo!https://github.com:example/project.git' test.ping