Ansible 报错 Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-w...

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

[root@k8s-master ~]# cat  /etc/ansible/zip.yml 
---
- hosts: webservers
  gather_facts: no 
  become: yes
  become_method: sudo
  tasks:
    - name: "copy files"
      copy:
        src: "{{ item.src }}"
        dest: "{{ item.dest }}"
        owner: root
        group: root
        mode: 755
      with_items:
         - {src: "/root/copytest4.txt", dest: "/root/copytest4.txt" }
         - {src: "/root/dist.zip", dest: "/root/dist.zip" }
    - name: "unzip files"
      shell: unzip  /root/dist.zip  -d /tmp

root@k8s-master ~]# cat /etc/ansible/hosts 
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
#   - Blank lines are ignored
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses
#   - A hostname/ip can be a member of multiple groups

# Ex 1: Ungrouped hosts, specify before any group headers.

## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10

# Ex 2: A collection of hosts belonging to the 'webservers' group

 [webservers]
## alpha.example.org
## beta.example.org
 192.168.10.149
 192.168.10.148
 192.168.10.150

  • 26
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值