sudo salt --out=nested'*' cmd.run_all 'echo HELLO'
salt --out=raw '*' cmd.run_all 'echo HELLO'
salt --out=json '*' cmd.run_all 'echo HELLO'
--out=yaml
--out=quiet
Targeting strings
1
2
3
4
5
6
salt '*' test.ping
sudo salt 'myminion' test.ping
sudo salt 'my*' test.ping
sudo salt 'my*mini*' test.ping
sudo salt '??minion' test.ping
sudo salt '[a-m]yminion' test.ping
Perl-compatible regular expression matching PCRE
1
2
3
4
5
6
7
salt -E'myminion' test.ping
salt -E'my' test.ping
salt -E'my.*n' test.ping
salt -E'^myminion$' test.ping
salt -E'((my)|(your))minion' test.ping
salt -E'myminion(s)?' test.ping
salt -E'(my)?minion' test.ping
List matching
1
2
salt -L 'myminion' test.ping
salt -L 'myminion,yourminion,theirminion' test.ping
Grains Grains represent static data describing a minion. Pillars Pillar data is similar to grains except that it can be defined more dynamically and is a secure store for data.
Grain and pillar matching
1
2
3
4
5
6
7
salt '*' grains.item os_family
salt '*' grains.item os
salt '*' grains.item osfinger
salt --grain 'os_family:RedHat' test.ping
salt -G 'os:Ubuntu' test.ping
salt -G 'os:u*' test.ping
salt '*' grains.items
设置变量
1
2
3
4
salt '*'grains.setval foo bar
salt '*'grains.item foo
salt '*'grains.setval baz '["larry", "moe", "curly"]'
salt '*'grains.delval baz
1
2
3
4
5
6
# cat /etc/salt/grains
baz:
- larry
- moe
- curly
foo: bar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
salt '*.baz.com' test.ping
salt -E 'web-(prod|dev)' test.ping
salt -L 'web-jonh, dborac-ether' test.ping
# By grains, target the RedHat and Debian systems
salt -G 'os:(RedHat|Debian)' test.ping
# By Pillar data, target human resources
salt -I 'deparment:HR' test.ping
# By IP/subnet, target the local network
salt -S '192.16.0.0/24' test.ping
Compound matching
1
2
3
4
5
6
7
8
9
10
11
12
# By minion ID and grains
salt -C 'web-* and G@os:Ubuntu' test.ping
# By grains and Pillar data
salt -C 'G@cpuarch:x86_64 and I@office:32D' test.ping
salt -C '*minion and G@os:Ubuntu and not L@yourminion,theirminion'
test.ping
salt -C '* and not G@os_family:RedHat' test.ping
salt -C 'G@os:Ubuntu or G@os:Fedora' test.ping
组合
Letter
Match Type
Example
G
Grains glob
G@os:Ubuntu
E
PCRE minion ID
E@web\d+.(dev\
qa\
prod).loc
P
Grains PCRE
P@os:(RedHat\
Fedora\
CentOS)
L
List of minions
L@minion1.example.com, minion3.domain.com
I
Pillar glob
I@pdata:foobar
S
Subnet/IP address
S@192.168.1.0/24 or S@192.168.1.100
R
Range cluster
R@%foo.bar
Remote execution modules and functions
1
2
<module>.<function>
test.ping
1
salt'*' sys.list_modules
常用模块
用户管理
1
2
3
4
salt '*' sys.doc user.add
salt '*' user.add name <uid><gid><groups><home><shell>
We can also specify an sls file. Sls files don’t normally use execution modules, and instead use state modules that are called automagically by Salt when it processes the state, although there is a special state module to call execution modules from within sls files. More on writing states in a minute:
Apply the states from the ssh.sls file on all minions.
Notice how we omit the .sls extension in the command line.
salt ‘*’ state.sls ssh
salt -N ‘logs_wpk’ state.highstate salt kvmguest-001-sjc-13-33..com state.highstate salt kvmguest-001-sjc-13-33..com state.sls base.zabbix