Common Salt commands and states¶
Manage the contents of a file:
/root/salt-demo:
file.managed:
- user: root
- group: root
- mode: 644
- source: salt://node/salt-demo
- makedirs: True
This state requires the file node/salt-demo to be present and to
contain the contents you want to save at /root/salt-demo on each
targeted minion.
Ensure a package is installed:
cowsay:
pkg.installed
This ensures the cowsay package is installed on targeted minions.
Common commands¶
See which minions are connected:
salt '*' test.ping
Tell all minions to apply all their states:
salt '*' state.apply
Run a command on all minions:
salt '*' cmd.run 'uptime'
Show minion grain items:
salt '*' grains.items
Show the states that apply to each minion:
salt '*' state.show_top
Filter by grain:
root@ba:/# salt -G 'type:aggregator' test.ping # Ping aggregators only
node-1:
True
root@ba:/# salt -G 'osmajorrelease:7' test.ping # Ping Debian Wheezy minions only
node-7:
True
node-1:
True
node-2:
True
Run in batches:
root@ba:/# salt '*' -b 2 test.ping # Ping 2 minions at a time
Executing run on ['node-2', 'node-1']
node-1:
True
retcode:
0
node-2:
True
retcode:
0
Executing run on ['node-7']
node-7:
True
retcode:
0
root@ba:/# salt '*' --batch-size 25% test.ping # Ping 25% of the environment at a time
Executing run on ['node-2']
node-2:
True
retcode:
0
Executing run on ['node-1']
node-1:
True
retcode:
0
Executing run on ['node-7']
node-7:
True
retcode:
0