User Tools

Site Tools


salt-stack:running_commands

Running commands with SALT

Targeting

To run commands you need to specify the target. You can find more info about targeting here.

Also, you can check some examples below.

Simple targeting examples

Perform a test.ping in all minions:

sudo salt '*' test.ping

Targeting on grains

Create a directory in all minions running CentOS:

sudo salt -G 'os:Centos' file.makedirs /opt/cylance/

Compound targeting

Copy a file from the salt-filserver to all minions running Centos version 6:

sudo salt -C 'G@os:Centos and G@osmajorrelease:6' cp.get_file salt://cylance/config_defaults.txt /opt/cylance/config_defaults.txt

You can find more info about compound targeting here.

Substitutions (template rendering)

You can make substitutions for rendering the commands with jinja, typing the value to be used between double curly brackets {{ … }}.

Example: Copy the appropriate version of CylancePROTECT install RPM from the salt-filserver, depending on the Centos os major release, using the grain osmajorrelease:

sudo salt -C 'G@os:Centos' cp.get_file salt://cylance/CylancePROTECT.el{{grains.osmajorrelease}}.rpm /opt/cylance/CylancePROTECT.el{{grains.osmajorrelease}}.rpm template=jinja

Sample commands with Salt

Find out servers with 172.17.1.1 configured as DNS nameserver and show what nameservers are configured:

sudo salt -C 'G@dns:nameservers:172.17.1.1' grains.get dns:"nameservers"
salt-stack/running_commands.txt · Last modified: 2019/07/18 09:19 (external edit)