User Tools

Site Tools


Running commands with SALT


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 in all minions:

sudo salt '*'

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 configured as DNS nameserver and show what nameservers are configured:

sudo salt -C 'G@dns:nameservers:' grains.get dns:"nameservers"
linux/salt-stack/running_commands.txt · Last modified: 2022/02/11 11:36 by