[root@ansible-text1 ~]# ansible testhost -m command -a "hostname"
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
ECDSA key fingerprint is 24:d8:54:02:c9:e6:c0:df:b2:35:14:ab:ca:c9:8a:12.
Are you sure you want to continue connecting (yes/no)? 192.168.110.12 | CHANGED | rc=0 >>
ansible-text2
127.0.0.1 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Host key verification failed.",
"unreachable": true
}
这个错误是
免密配置的错误
只设置了一台主机
这里需要设置两台主机
本机的还有另外一台虚拟机的
[root@ansible-test1 ~]# ssh-copy-id 192.168.2.20 这个步骤就是设置两台虚拟机的操作 需将两台的虚拟机主机都操作一遍
The authenticity of host '192.168.2.20 (192.168.2.20)' can't be established.
ECDSA key fingerprint is dc:a5:08:4d:9a:40:8a:be:ee:68:dd:41:61:7d:d7:05.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.2.20's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.2.20'"
and check to make sure that only the key(s) you wanted were added.
两台都设置完成后
更改配置文件
vim / etc/ansible/host
将两台虚拟机的ip 加进入
运行 ansible testhost -m command -a "hostname"
即可