Learn › Linux Automation with Salt › Target one or both minions

Target one or both minions

Choose one Salt minion or an exact two-minion list, then verify each named reply with a practice word.

Choose recipients before sending a Salt request

In Lesson 1, you connected one Salt master to two accepted minions. This lesson starts with that enrolled fleet. A fresh fleet may have been prepared for you; a reused fleet is checked before continuing, without overwriting its keys or settings. Use the salt-master terminal for every salt command below. The minion-a and minion-b terminals remain available if a machine needs inspection.

A target tells the master which minion IDs should receive a job. The target comes before the function in a Salt command. First use test.ping, a harmless Salt request that returns True when a minion runs it and replies. It is not the ordinary network ping command. An ordinary ping sends Internet Control Message Protocol (ICMP) traffic; it cannot prove that a minion accepted and answered a Salt job. Then use test.echo, which returns the short word you send to the chosen minion. Decide who should receive each request before you run it.

These three targets express different choices:

TargetMeaning in this fleet
'minion-a'The one minion with that exact ID
-L 'minion-a,minion-b'The two IDs named in an explicit list
'minion-*'Any accepted minion whose ID starts with minion-

-L means list; separate the IDs with a comma and no spaces. The * is a glob wildcard, meaning zero or more characters in an ID. Quote a glob with single quotes so the shell passes it to Salt instead of expanding it as a local filename pattern. The broader target '*' can select every accepted minion, whatever its ID. Today the two globs may produce the same two replies, but a future accepted minion-c would join minion-*, and a future accepted db-1 would join '*'. An explicit two-ID list keeps naming the same two IDs.

Worked example: send a word only to minion-a

Here is the complete method. First, on salt-master, read the accepted IDs:

sudo salt-key --list=accepted

Check that minion-a and minion-b are accepted. A key listing shows who the master trusts; it does not prove who is connected or who will answer now. Check a live Salt reply from each machine before sending a word:

sudo salt --timeout=10 'minion-a' test.ping
sudo salt --timeout=10 'minion-b' test.ping

Read each named True. This confirms a Salt reply from that minion, not the health of every function. --timeout=10 sets the Salt client's reply-wait interval to ten seconds; total command time can differ. If no named reply appears, that is an absence, not a returned False. Wait briefly and send a fresh request. If it is still absent, check the accepted key, minion service, private connection and recent service messages before deciding what failed.

Here is a complete authored example, not captured output from your machines. The example word camp7 is an input, not a password. The intended recipient is minion-a only:

sudo salt --timeout=10 'minion-a' test.echo camp7

Expected shape of the example result:

minion-a:
    camp7

The exact ID selects minion-a. test.echo asks that minion to return the final argument, camp7. The name beside the returned word lets you connect recipient, input and reply. It says nothing about minion-b. Your Terminal pane shows a short practice word for this lab. It is not a secret. Use that displayed word for the checked requests below, not camp7. If you reconnect, use the word shown for this same lab.

Rehearse: name the other minion

Now select minion-b only. Keep the worked example open. Replace YOUR_WORD with the short practice word visible in your Terminal pane; the placeholder is not a literal word to send:

sudo salt --timeout=10 'minion-b' test.echo YOUR_WORD

Look for the same word under the minion-b name. Compare both the name and word with the request you made. If you are unsure, replay the minion-a example or use Workspace help, then retry; help does not reduce credit. One named result shows that one minion answered. It does not establish the health of both minions.

Predict, then inspect a two-minion request

You have seen each exact-ID request work. Now choose both named minions. Before running the next command, consider which names and words you expect to see and why. You may record uncertainty and continue without guessing. Replace YOUR_WORD with the word shown in your Terminal pane:

sudo salt --timeout=10 -L 'minion-a,minion-b' test.echo YOUR_WORD

Inspect your real terminal output. The -L flag tells Salt to interpret the comma-separated IDs as a list, rather than one ID containing a comma. Look for two separate named replies, each returning your practice word. Interpret each reply: if both names return the word, both answered this particular request. If one name is missing, the other reply does not cover it. A missing result may mean the minion was not selected, was disconnected, or did not return within the wait. Read the target and accepted-key list before diagnosing the service. An absent line is not a returned False.

Compare explicit and pattern targets

With the current two-ID fleet, inspect two quoted glob targets on salt-master:

sudo salt --timeout=10 'minion-*' test.ping
sudo salt --timeout=10 '*' test.ping

Compare the names that actually reply with the accepted-key list. The pattern minion-* means an ID that begins with minion-; '*' has no name restriction. Each can include more machines as the fleet grows. A pattern that happens to return the same two names today is not a permanent two-machine allowlist. Use an exact ID or -L when the task requires specific recipients. Before any future command that changes a machine, make the target decision first and verify the named recipients with a harmless read like test.ping.

To see a target that names nobody in this two-minion lab, try this harmless read:

sudo salt --timeout=10 'minion-z' test.ping

minion-z is not one of the accepted IDs for this exercise, so expect no named minion-z reply. Salt may report that no minions matched. This is different from targeting a known ID and receiving no reply before a timeout: in that case the minion might be unavailable, and the absence alone does not identify the cause. If an unexpected ID appears in the accepted list, stop and inspect it rather than treating the wider glob's output as permission to include it.

Make a justified choice and verify it

Your task is to send your practice word to minion-a only, then to the exact two-minion set, without including a future machine whose ID might match a pattern. On salt-master, replace YOUR_WORD in each command with the short word visible in your Terminal pane:

sudo salt --timeout=10 'minion-a' test.echo YOUR_WORD
sudo salt --timeout=10 -L 'minion-a,minion-b' test.echo YOUR_WORD

Verify the first job by reading the minion-a name and returned word. Verify the second job by reading both names and returned words from that same request. The earlier minion-b rehearsal cannot fill a missing reply from the two-minion job. If one reply is absent, wait briefly and rerun the same target; then inspect that minion's service, accepted key and connection if absence continues. Do not widen the target to '*' to hide a missing reply. If the expected replies return, leave the fleet unchanged: the justified decision was a recipient choice, not a configuration edit. Use Check chapter for automatic feedback from real Salt jobs. The check should credit observed recipients and the displayed word, not copied commands, a typed answer or a simulated terminal result. This is guided practice without XP, not independent mastery.

Carry the method into the next problem

You can now choose one exact minion or an explicit two-minion set and check each named answer. The returned practice word supports that the named minion answered that job. It does not prove that every possible Salt function would succeed or that a silent minion returned False.

In the next chapter, you will meet grains, facts reported by a minion, and use one to solve a changed targeting problem. Start that problem with its own explanation and worked example. Today's guided recipient selection is practice, not a claim of independent mastery.

Practice Target one or both minions in a real Linux terminal at The Linux Camp. Progress is verified automatically as you type commands on the machine.