ansible testhost -m command -a “hostname“错误 Ansible远程执行命令

[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"

即可

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值