一个远控时无法执行ansible命令的情况
来源:10-3 【自动化运维框架-Ansible工具】-2

藩王
2024-01-24
mac 系统
远控一台centos虚拟机,设置虚拟机免密登录其他两台centos虚拟机
用mac的terminal工具远控执行 ansible 的相关命令 出现了报错,
但是我直接通过虚拟机却可以执行,并且在直接用虚拟机执行 ansible 相关命令之后,在一小段时间内,可以用 mac 的 terminal 远控执行 ansible 相关命令了,但是过一会就又不能执行了
[root@localhost ~]# ansible all -m ping
192.168.112.132 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: root@192.168.112.132: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
"unreachable": true
}
192.168.112.133 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: root@192.168.112.133: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
"unreachable": true
}
[root@localhost ~]# ansible all -m command -a "ls /root"
192.168.112.132 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: root@192.168.112.132: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
"unreachable": true
}
192.168.112.133 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: root@192.168.112.133: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
"unreachable": true
}
写回答
1回答
-
看了一下你的描述,你是在远程的centos系统上执行的ansible指令对吧。如果直接用系统默认的ping就OK,但是用ansible执行ping就报错?
按照ansible的提示,应该是没有设置免密登录
你可以通过如下方式进行验证,ssh root@192.168.112.132,看是否需要输入密码,按照我的理解应该是需要的。
这时候,再按照ssh-copy-id root@192.168.112.132,输入密码后拷贝公钥,之后就可以实现免密登录了
再执行以下ansible all -m ping看一下结果
022024-02-06
相似问题