salt除了支持Master 和Minion方式之外,还支持SSH; SSH方式因为没有minion主动连接master,所以需要维护 roster,提供master可以操作的对象;roster的配置文件默认在:/etc/sat/roster
[root@linux-node1 ~]# cat /etc/salt/roster
# Sample salt-ssh config file
#web1:
# host: 192.168.42.1 # The IP addr or DNS hostname
# user: fred # Remote executions will be executed as user fred
# passwd: foobarbaz # The password to use for login, if omitted, keys are used
# sudo: True # Whether to sudo to root, not enabled by default
#web2:
# host: 192.168.42.2
linux-node1.oldboyedu.com:
host: 192.168.74.20
port: 22
user: root
linux-node2.oldboyedu.com:
host: 192.168.74.32
port: 22
user: root
# priv: /root/.ssh/id_rsa
如果在roster的配置文件中没有写入私钥文件或者密码,第一次操作的时候,需要写入密码
[root@linux-node1 ~]# salt-ssh '*' test.ping -i
之后就可以正常操作了
[root@linux-node1 ~]# salt-ssh '*' test.ping
linux-node1.oldboyedu.com:
True
linux-node2.oldboyedu.com:
True
[root@linux-node1 ~]# salt-ssh '*' cmd.run 'uptime'
linux-node1.oldboyedu.com:
16:08:30 up 12:09, 1 user, load average: 0.01, 0.03, 0.05
linux-node2.oldboyedu.com:
16:08:26 up 8:15, 1 user, load average: 0.19, 0.11, 0.07
[root@linux-node1 ~]# salt-ssh '*' -r 'uptime'
linux-node1.oldboyedu.com:
----------
retcode:
0
stderr:
stdout:
16:09:14 up 12:09, 1 user, load average: 0.00, 0.03, 0.05
linux-node2.oldboyedu.com:
----------
retcode:
0
stderr:
stdout:
16:09:11 up 8:15, 1 user, load average: 0.15, 0.11, 0.07
[root@linux-node1 ~]# salt-ssh '*' state.sls salt.init_repo #和salt的操作相同