//安装salt-ssh
[root@localhost salt]# yum -y install salt-ssh
//修改配置文件,添加受控机信息
[root@localhost salt]# vim /etc/salt/roster
[root@localhost salt]# 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
node1:
host: 192.168.161.133
user: root
passwd: 123456
node2:
host: 192.168.161.134
user: root
passwd: 123456
//ping一下
[root@localhost salt]# salt-ssh '*' test.ping
node1:
----------
retcode:
254
stderr:
stdout:
The host key needs to be accepted, to auto accept run salt-ssh with the -i flag:
The authenticity of host '192.168.161.133 (192.168.161.133)' can't be established.
ECDSA key fingerprint is SHA256:yFImkxnTXlvrUi0ziMYzapAAGMHXpWmLKgX/klCoZ0s.
ECDSA key fingerprint is MD5:fd:f7:a0:72:10:9d:1b:be:1e:8c:89:60:a0:1a:5e:7d.
Are you sure you want to continue connecting (yes/no)?
node2:
----------
retcode:
254
stderr:
stdout:
The host key needs to be accepted, to auto accept run salt-ssh with the -i flag:
The authenticity of host '192.168.161.134 (192.168.161.134)' can't be established.
ECDSA key fingerprint is SHA256:BoRqxFUbuj4f0ICilMcfMoU9NW/SK4o/mxmqLokh680.
ECDSA key fingerprint is MD5:58:0a:d0:66:84:ba:5a:a9:8c:28:24:c7:e8:e8:e4:5a.
Are you sure you want to continue connecting (yes/no)?
//第一次访问时需要输入 yes/no ,但是 saltstack是不支持交互式操作的,所以为了解决这个问题,我们需要对其进行设置,让系统不进行主机验证。
[root@localhost salt]# vim ~/.ssh/config
[root@localhost salt]# cat ~/.ssh/config
StrictHostKeyChecking no
[root@localhost salt]# salt-ssh '*' test.ping
node1:
True
node2:
True