You'll learn how to:
Estimated time: 10 minutes
Targeting is how you select Salt minions when running commands, applying configurations, and when doing almost anything else in SaltStack that involves a Salt minion.
The simplest way to target is using the Salt minion ID. This value can be set to anything you want in the minion config file, and can be specified using the
-i option in the bootstrap script.
salt 'minion1' disk.usage
Globbing on the Salt minion ID is supported by simply including a wildcard in the target:
salt 'minion*' disk.usage
In an ideal world, each system in your environment has a structured name that tells you everything you need to know about the hardware, OS, and system role. While we wait for that world, SaltStack provides a powerful targeting system to help you find and filter systems based on static and custom data.
Targets can be based on Salt minion system information using the Grains system:
salt -G 'os:Ubuntu' test.ping
Targets can be filtered by regular expression:
salt -E 'minion[0-9]' test.ping
Targets can be explicitly specified in a list:
salt -L 'minion1,minion2' test.ping
Or Multiple target types can be combined in one command:
salt -C 'G@os:Ubuntu and minion* or S@192.168.50.*' test.ping
Don’t worry too much about these targeting methods just yet. Just be confident that the targeting mechanism has enough flexibility to find the systems that you want to manage.
Hopefully you’ve got a good understanding of how execution modules are used from the command line, and how to filter Salt minions using targets. The next step is to define re-usable configuration templates, called states, so we can make more awesomeness happen at once.