Ansible 报错 Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password)

发布时间 2024-01-09 10:52:47作者: beawh

[root@k8s-master ~]# ansible-playbook /etc/ansible/copy.yml

PLAY [webservers] **************************************************************************************************************************************************************************************

TASK [copy files] **************************************************************************************************************************************************************************************
failed: [192.168.10.149] (item={u'dest': u'/root/copytest4.txt', u'src': u'/root/copytest4.txt'}) => {"ansible_loop_var": "item", "item": {"dest": "/root/copytest4.txt", "src": "/root/copytest4.txt"}, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}
fatal: [192.168.10.149]: UNREACHABLE! => {"changed": false, "msg": "All items completed", "results": [{"ansible_loop_var": "item", "item": {"dest": "/root/copytest4.txt", "src": "/root/copytest4.txt"}, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}]}
failed: [192.168.10.150] (item={u'dest': u'/root/copytest4.txt', u'src': u'/root/copytest4.txt'}) => {"ansible_loop_var": "item", "item": {"dest": "/root/copytest4.txt", "src": "/root/copytest4.txt"}, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}
failed: [192.168.10.148] (item={u'dest': u'/root/copytest4.txt', u'src': u'/root/copytest4.txt'}) => {"ansible_loop_var": "item", "item": {"dest": "/root/copytest4.txt", "src": "/root/copytest4.txt"}, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}
fatal: [192.168.10.150]: UNREACHABLE! => {"changed": false, "msg": "All items completed", "results": [{"ansible_loop_var": "item", "item": {"dest": "/root/copytest4.txt", "src": "/root/copytest4.txt"}, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}]}
fatal: [192.168.10.148]: UNREACHABLE! => {"changed": false, "msg": "All items completed", "results": [{"ansible_loop_var": "item", "item": {"dest": "/root/copytest4.txt", "src": "/root/copytest4.txt"}, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}]}

 看到这个报错脑袋大,直到翻阅官网的github 找到解决

Failed to connect to the host via ssh: Permission denied (publickey,password) · Issue #19584 · ansible/ansible · GitHub

[root@k8s-master ~]# ansible all -m ping --ask-pass
SSH password:
192.168.10.148 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
192.168.10.150 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
192.168.10.149 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}