1
0

globbing.rst 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. .. _targeting-glob:
  2. ==========================
  3. Matching the ``minion id``
  4. ==========================
  5. Each minion needs a unique identifier. By default when a minion starts for the
  6. first time it chooses its :abbr:`FQDN (fully qualified domain name)` as that
  7. identifier. The minion id can be overridden via the minion's :conf_minion:`id`
  8. configuration setting.
  9. .. tip:: minion id and minion keys
  10. The :term:`minion id <Minion ID>` is used to generate the minion's public/private keys
  11. and if it ever changes the master must then accept the new key as though
  12. the minion was a new host.
  13. Globbing
  14. ========
  15. The default matching that Salt utilizes is :py:mod:`shell-style globbing
  16. <python2:fnmatch>` around the :term:`minion id <Minion ID>`. This also works for states
  17. in the :term:`top file <Top File>`.
  18. .. note::
  19. You must wrap :command:`salt` calls that use globbing in single-quotes to
  20. prevent the shell from expanding the globs before Salt is invoked.
  21. Match all minions:
  22. .. code-block:: bash
  23. salt '*' test.version
  24. Match all minions in the example.net domain or any of the example domains:
  25. .. code-block:: bash
  26. salt '*.example.net' test.version
  27. salt '*.example.*' test.version
  28. Match all the ``webN`` minions in the example.net domain (``web1.example.net``,
  29. ``web2.example.net`` … ``webN.example.net``):
  30. .. code-block:: bash
  31. salt 'web?.example.net' test.version
  32. Match the ``web1`` through ``web5`` minions:
  33. .. code-block:: bash
  34. salt 'web[1-5]' test.version
  35. Match the ``web1`` and ``web3`` minions:
  36. .. code-block:: bash
  37. salt 'web[1,3]' test.version
  38. Match the ``web-x``, ``web-y``, and ``web-z`` minions:
  39. .. code-block:: bash
  40. salt 'web-[x-z]' test.version
  41. .. note::
  42. For additional targeting methods please review the
  43. :ref:`compound matchers <targeting-compound>` documentation.
  44. Regular Expressions
  45. ===================
  46. Minions can be matched using Perl-compatible :py:mod:`regular expressions
  47. <python2:re>` (which is globbing on steroids and a ton of caffeine).
  48. Match both ``web1-prod`` and ``web1-devel`` minions:
  49. .. code-block:: bash
  50. salt -E 'web1-(prod|devel)' test.version
  51. When using regular expressions in a State's :term:`top file <Top File>`, you must specify
  52. the matcher as the first option. The following example executes the contents of
  53. ``webserver.sls`` on the above-mentioned minions.
  54. .. code-block:: yaml
  55. base:
  56. 'web1-(prod|devel)':
  57. - match: pcre
  58. - webserver
  59. Lists
  60. =====
  61. At the most basic level, you can specify a flat list of minion IDs:
  62. .. code-block:: bash
  63. salt -L 'web1,web2,web3' test.version