Ansible ping 失败 - 主机无法访问

Dav*_* B. 6 ssh ansible

我刚刚开始学习 Ansible 的基础知识,并查找了为什么会出现上述错误但不知道如何解决。这是跟踪:

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
}

------
Run Code Online (Sandbox Code Playgroud)

之前有人问我:

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
Run Code Online (Sandbox Code Playgroud)

这是我在主机文件中的内容:

[name_of_the_EC2_instance]
Public_IP 
Run Code Online (Sandbox Code Playgroud)

并在配置文件中:

[defaults]
host_key_checking = False
Run Code Online (Sandbox Code Playgroud)

我在那里遗漏了一些东西。有任何想法吗?

提前致谢。

ted*_*r42 8

正如评论中所探讨的,未指定私钥文件。已尝试使用默认文件 ( .ssh/id_dsa, .ssh/id_dsa) 但未找到。

可以通过多种方式添加私钥文件:

(1) 使用ssh代理: ssh-add ~/.ssh/my-key.pem

(2) 违约ansible.cfg

[defaults]
private_key_file=~/.ssh/my-key.pem
Run Code Online (Sandbox Code Playgroud)

(3) 为清单中的每个主机指定:

my-host-ip ansible_ssh_private_key_file=~/.ssh/my-key.pem
Run Code Online (Sandbox Code Playgroud)