-
正則匹配
# salt -E '192*' test.ping [WARNING ] Cannot resolve address None info via socket: <class 'socket.gaierror'> 192.168.0.62: True
列表匹配
#salt -L Minion,Minion1 test.pingGrians匹配
#salt -G 'os:MacOS' test.ping
其中os:MacOS是一組鍵值對組匹配
#salt -N groups test.ping.復合匹配
#salt -C 'G@os:MacOS or L@Minion1'
支持使用and 和or 關聯多個條件Pillar值匹配
#salt -I 'key:value' test.pingCIDR匹配
#salt -s '192.168.1.0/24' test.ping
管理對象屬性:
Grains是saltstack組件中非常重要的組件之一
Grains是saltstack記錄Minion的一些靜態信息的組件,可以簡單理解為Grains里面記錄著每臺Minion的常用屬性比如:CPU,內存,磁盤,網絡信息。
可以通過:grains.items查看某臺Minion的所有Grains信息
簡單Grains的命令:
#salt '192.168.0.62' sys.list_functions grains
列出grains開頭的
#salt '192.168.0.62' sys.list_functions
列出所有
# salt '192.168.0.62' sys.doc grains.append
查看幫助信息
數據管理中心
Pillar在saltstack中主要作用就是存儲和定義配置管理中需要的一些數據,比如:軟件版本號,用戶名密碼等信息。
# cat minion | grep -C 4 pillar_roots
# Salt caches should be cleared.
#hash_type: sha256
# The Salt pillar is searched for locally if file_client is set to local. If
# this is the case, and pillar data is defined, then the pillar_roots need to
# also be configured on the minion:
#pillar_roots:
# base:
# - /srv/pillar
# Set a hard-limit on the size of the files that can be pushed to the master.
知識補充:
如果在只是想匹配模式的上下幾行,grep可以實現。
$grep -5 'parttern' inputfile //打印匹配行的前后5行
$grep -C 5 'parttern' inputfile //打印匹配行的前后5行
$grep -A 5 'parttern' inputfile //打印匹配行的后5行
$grep -B 5 'parttern' inputfile //打印匹配行的前5行
在Master 配置文件中有一段Pillar setting選項專門定義Pillar相關的參數:
- 查看所有module列表
#salt '*' sys.list_modules - 查看指定module的所有function
#salt '*' sys.list_functions cmd - 查看指定module用法
#salt '*' sys.doc cmd - saltstack默認支持一次執行多個Module
#salt '*' test.echo,cmd.run
states是saltstack中的配置語言
- 查看所有states列表
#salt '*' sys.list_state_modules - 查看指定states的所有function
#salt '*' sys.list_state_functions file - 查看file.states的詳細用法與例子
#salt '*' sys.state_doc file.rename