shellsalt-project

Why do these SaltStack functions have different output?


I'm new to SaltStack and ran these two command:

# salt '*' test.echo "$PWD"
# salt '*' cmd.run "pwd"

I have got different output! Does anyone know what is the difference between two above command?

I expected the same result for both commands.


Solution

  • When you run a shell command, first any shell expansions are processed, then the command is executed.

    For the first command it expands "$PWD" to the current working directory of the shell, then instructs all minions to run e.g. test.echo('/home/mhm').

    For the second command it instead instructs all minions to run cmd.run('pwd'), which returns the current working directory of the minion service.