大网数据广告活动
服务器运维问答

Ansible ping fails - host unreachable

· 52CE 我爱测

I just started learning the basics of Ansible, and looked up why I am getting the above error but can't figure out how to sort it out. This is the trace: Me-Air:ansible me$ ansible all -m ping -vvv Using /private/etc/ansible/ansi…

问题原文

原帖链接 · David B. · CC BY-SA 3.0

I just started learning the basics of Ansible, and looked up why I am getting the above error but can't figure out how to sort it out. This is the trace:

Me-Air:ansible me$ ansible all -m ping -vvv
Using /private/etc/ansible/ansible.cfg as config file
<Public_IP> ESTABLISH SSH CONNECTION FOR USER: [my_user_name_on_EC2_instance]
<Public_IP> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/Users/me/.ansible/cp/ansible-ssh-%h-%p-%r -tt [Public_IP] '/bin/sh -c '"'"'( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-... `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-... `" )'"'"''
Public_IP | UNREACHABLE! => {
    "changed": false,
    "msg": "SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue",
    "unreachable": true
}

------

I was previously asked:

The authenticity of host 'public IP' can't be established.
RSA key fingerprint is ...[key].
Are you sure you want to continue connecting (yes/no)? yes

This is what I have in the hosts file:

[name_of_the_EC2_instance]
Public_IP 

And in the config file:

[defaults]
host_key_checking = False

I'm missing something there. Any ideas?

Thanks in advance.

已采纳解答

原帖链接 · 300D7309EF17 · CC BY-SA 3.0

As explored in the comments, the private key file was not being specified. The default files (.ssh/id_dsa, .ssh/id_dsa) were attempted but not found.

The private key file can be added in several ways:

(1) Using the ssh agent: ssh-add ~/.ssh/my-key.pem

(2) Defaulted in ansible.cfg:

[defaults]
private_key_file=~/.ssh/my-key.pem

(3) Specified per host in inventory:

my-host-ip ansible_ssh_private_key_file=~/.ssh/my-key.pem

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-03-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。