首页 > 解决方案 > 由于“无法通过 ssh 连接到主机”,我无法执行我的 ansible playbook

问题描述

我可以通过 ssh 连接我的主节点,但是当我启动我的 ansible playbook 时,它说“无法通过 ssh 连接到主机”。我不懂为什么。有人可以帮我解决这个问题。

[ansadmin@ip-172-31-52-198 ssh]$ cd /home/ansadmin/.ssh/
[ansadmin@ip-172-31-52-198 .ssh]$ ssh -i  /home/ansadmin/.ssh/id_rsa2 opc@132.145.209.167
Oracle Linux Server 7.8
Last login: Tue Jun 30 16:42:47 2020 from 132.145.169.136
[opc@oke-c3doyjxha4g-nrtgmbsgq3d-srmrh4en3ga-2 ~]$ exit
logout
Connection to 132.145.209.167 closed.
[ansadmin@ip-172-31-52-198 .ssh]$ cd /opt/kubernetes/
[ansadmin@ip-172-31-52-198 kubernetes]$ ansible-playbook -i hosts kubernetes-valaxy-deployment.yml -vvv
ansible-playbook 2.9.9
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/ansadmin/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 2.7.18 (default, May  7 2020, 09:20:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /opt/kubernetes/hosts as it did not pass its verify_file() method
script declined parsing /opt/kubernetes/hosts as it did not pass its verify_file() method
auto declined parsing /opt/kubernetes/hosts as it did not pass its verify_file() method
[DEPRECATION WARNING]: The TRANSFORM_INVALID_GROUP_CHARS settings is set to allow bad characters in group names by default, this will change, but still be user configurable on deprecation. This feature 
will be removed in version 2.10. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
Parsed /opt/kubernetes/hosts inventory source with ini plugin

PLAYBOOK: kubernetes-valaxy-deployment.yml *****************************************************************************************************************************************************************
1 plays in kubernetes-valaxy-deployment.yml

PLAY [Create pods using deployment] ************************************************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************************************************
task path: /opt/kubernetes/kubernetes-valaxy-deployment.yml:3
<132.145.209.167> ESTABLISH SSH CONNECTION FOR USER: root
<132.145.209.167> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/ansadmin/.ansible/cp/b09c8a513c 132.145.209.167 '/bin/sh -c '"'"'echo ~root && sleep 0'"'"''
<132.145.209.167> (255, '', 'Oracle Linux Server 7.8\nPermission denied (publickey).\r\n')
fatal: [132.145.209.167]: UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: Oracle Linux Server 7.8\nPermission denied (publickey).", 
    "unreachable": true
}

PLAY RECAP *************************************************************************************************************************************************************************************************
132.145.209.167            : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0   

[ansadmin@ip-172-31-52-198 kubernetes]$ cat /etc/ansible/ansible.cfg
[defaults]
privatekeyfile = /home/ansadmin/.ssh/id_rsa2

标签: sshansible

解决方案


推荐阅读