Ansible ping Unreachable TimeOut解决

Ansible ping Unreachable解决

  • 问题描述
  • 尝试方法
  • 解决

问题描述

环境:
虚拟机:192.168.131.107
虚拟机:192.168.131.108
虚拟机:192.168.131.109

配置Ansible与multnode后,使用命令:

ansible -i multinode all -m ping

报错:
192.168.131.108 | UNREACHABLE! => {
    "changed": false,
    "msg": "Data could not be sent to remote host \"192.168.131.108\". Make sure this host can be reached over ssh: ssh: connect to host 192.168.131.108 port 1756: No route to host\r\n",
    "unreachable": true
}
192.168.131.107 | UNREACHABLE! => {
    "changed": false,
    "msg": "Data could not be sent to remote host \"192.168.131.107\". Make sure this host can be reached over ssh: [email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n",
    "unreachable": true
}

尝试方法

查看网上一些教程,尝试过修改multnode的端口,报错

"msg": "Data could not be sent to remote host \"192.168.131.107\". Make sure this host can be reached over ssh: [email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n",

解决

原因:ssh服务未正确配置

在其中一台虚拟机输入命令:

ssh-keygen

一路回车

 ssh-copy-id [email protected]


#输出
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/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
[email protected]'s password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.



 ssh-copy-id [email protected]
#输出类似
ssh-keyscan remote_servers >> ~/.ssh/known_hosts

#输出
getaddrinfo remote_servers: Name or service not known
getaddrinfo remote_servers: Name or service not known
getaddrinfo remote_servers: Name or service not known

重新运行:

(venv) [root@localhost ~]# ansible -i multinode all -m ping
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Sep 10 2021, 09:13:53) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)].
This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
/path/to/venv/lib64/python3.6/site-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
  from cryptography.exceptions import InvalidSignature
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
[DEPRECATION WARNING]: Distribution centos 8.5.2111 on host localhost should use /usr/libexec/platform-python, but is using /usr/bin/python for backward compatibility with prior Ansible releases. A future
Ansible release will default to using the discovered platform python for this host. See https://docs.ansible.com/ansible-core/2.11/reference_appendices/interpreter_discovery.html for more information. This
feature will be removed in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
localhost | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
[DEPRECATION WARNING]: Distribution centos 8.5.2111 on host 192.168.131.107 should use /usr/libexec/platform-python, but is using /usr/bin/python for backward compatibility with prior Ansible releases. A
future Ansible release will default to using the discovered platform python for this host. See https://docs.ansible.com/ansible-core/2.11/reference_appendices/interpreter_discovery.html for more
information. This feature will be removed in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
192.168.131.107 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
[DEPRECATION WARNING]: Distribution centos 8.5.2111 on host 192.168.131.109 should use /usr/libexec/platform-python, but is using /usr/bin/python for backward compatibility with prior Ansible releases. A
future Ansible release will default to using the discovered platform python for this host. See https://docs.ansible.com/ansible-core/2.11/reference_appendices/interpreter_discovery.html for more
information. This feature will be removed in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
192.168.131.109 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
[DEPRECATION WARNING]: Distribution centos 8.5.2111 on host 192.168.131.108 should use /usr/libexec/platform-python, but is using /usr/bin/python for backward compatibility with prior Ansible releases. A
future Ansible release will default to using the discovered platform python for this host. See https://docs.ansible.com/ansible-core/2.11/reference_appendices/interpreter_discovery.html for more
information. This feature will be removed in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
192.168.131.108 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}

问题解决!

你可能感兴趣的:(Ansible,ssh,bash,Ansible)