03-saltstack 基本管理与操作

模块文档:

https://docs.saltstack.com/en/latest/ref/modules/all/index.html
http://docs.saltstack.cn/ref/runners/all/

 

1.salt 该命令执行salt的执行模块,通常在master端运行,也是我们最常用到的命令

salt [options] '<target>' <function> [arguments]
salt '*' test.ping
salt 'salt-minion01' test.ping

 2.salt-run 该命令执行runner(salt带的或者自定义的,runner以后会讲),通常在master端执行,比如经常用到的manage

salt-run [options] [runner.func]
salt-run manage.status    # 查看所有minion状态
salt-run manage.down      # 查看所有没在线minion
salt-run manage.up        # 查看所有在线minion

 3.salt-key 密钥管理,通常在master端执行

salt-key [options]
salt-key -L                      # 查看所有minion-key
salt-key -a <key-name>           # 接受某个minion-key
salt-key -d <key-name>           # 删除某个minion-key
salt-key -A                      # 接受所有的minion-key
salt-key -D                      # 删除所有的minion-key

 4.salt-call 该命令通常在minion上执行,minion自己执行可执行模块,不是通过master下发job

salt-call [options] <function> [arguments]
salt-call test.ping              # 自己执行test.ping命令
salt-call cmd.run 'ifconfig'     # 自己执行cmd.run函数

 5.salt-cp 分发文件到minion上,不支持目录分发,通常在master运行

salt-cp [options] '<target>' SOURCE DEST
salt-cp '*' testfile.html /tmp
salt-cp 'test*' index.html /tmp/a.html

 6.salt匹配minion执行命令

 1.globbing 默认
salt '*' test.ping                 # 匹配所以 
salt 'test*' test.ping            # 匹配test1,test..
salt '*.test.com' test.ping    # 匹配a.test.com,b.test.com....
salt 'test?.xx.com' test.ping # 匹配test1.xx.com,test2.xx.com...
salt 'web[1-5]' test.ping       # 匹配web1到web
salt 'web-[x-z]' test.ping      # 匹配web-x,web-y,web-z

2.RE 正则
salt -E 'web1-(pro|devel)' test.ping  # 匹配web1-pro,web2-devel

3.List 列表
salt -L 'web1, test1' test.ping          # 匹配web1,test1

4.grains
salt -G 'os:CentOS' test.ping          # 匹配centos系统
salt 'test*' grains.items                  # 查看所有grains键/值
salt 'test*' grains.ls                        # 查看所有grains项
salt 'test*' grains.item num_cpus     # 查看某个grains的值

 

posted @ 2017-04-18 10:12  sunmmi  阅读(148)  评论(0)    收藏  举报