我的本地
/etc/ansible/hosts
文件刚刚有
[example]
172.31.nn.nnn
为什么我会得到这个
host_list declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
留言?
如果我把它改成
[local]
localhost ansible_connection=local
看起来工作正常。 但这仅限于本地。我想从本地计算机 ping 我的 aws 实例。
完整讯息:
ansible 2.8.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/michael/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /home/michael/.local/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
Loading callback plugin minimal of type stdout, v2.0 from /home/michael/.local/lib/python2.7/site-packages/ansible/plugins/callb
ack/minimal.pyc
META: ran handlers
<172.31.40.133> ESTABLISH SSH CONNECTION FOR USER: ubuntu
<172.31.40.133> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/home/michael/Dropbox/90_201
9/work/aws/rubymd2.pem"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,p
ublickey -o PasswordAuthentication=no -o 'User="ubuntu"' -o ConnectTimeout=10 -o ControlPath=/home/michael/.ansible/cp/7e7a30892
f 172.31.40.133 '/bin/sh -c '"'"'echo ~ubuntu && sleep 0'"'"''
<172.31.40.133> (255, '', 'OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017\r\ndebug1: Reading configuration data /et
c/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\nd
ebug1: Control socket "/home/michael/.ansible/cp/7e7a30892f" does not exist\r\ndebug2: resolving "172.31.40.133" port 22\r\ndebu
g2: ssh_connect_direct: needpriv 0\r\ndebug1: Connecting to 172.31.40.133 [172.31.40.133] port 22.\r\ndebug2: fd 3 setting O_NON
BLOCK\r\ndebug1: connect to address 172.31.40.133 port 22: Connection timed out\r\nssh: connect to host 172.31.40.133 port 22: C
onnection timed out\r\n')
172.31.40.133 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017\r\ndebug1: Readin
g configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: Applying options for *\r\ndebug1: auto-mux: Try
ing existing master\r\ndebug1: Control socket \"/home/michael/.ansible/cp/7e7a30892f\" does not exist\r\ndebug2: resolving \"172
.31.40.133\" port 22\r\ndebug2: ssh_connect_direct: needpriv 0\r\ndebug1: Connecting to 172.31.40.133 [172.31.40.133] port 22.\r
\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug1: connect to address 172.31.40.133 port 22: Connection timed out\r\nssh: connect to h
ost 172.31.40.133 port 22: Connection timed out",
"unreachable": true
}
我尝试在顶部添加 [inventory] 并且启用_plugins = ini。 第一个没有帮助,第二个给出了解析消息。
仅供参考安全组信息:
有关拒绝解析的消息仅供参考。库存文件有多种不同的插件,您可以从输出中看到
ini
插件已成功解析您的库存 (Parsed /etc/ansible/hosts inventory source with ini plugin
)。
此问题与 Ansible 无关。您需要首先建立与受管节点的 ssh 连接。
就其价值而言,安全组设置看起来很好(假设它们应用于您的主机),因此主机本身可能存在问题(即内部防火墙或 sshd 未运行)。
我也面临同样的问题。
解决方案: 在主机中而不是私有 IP 中,按以下格式粘贴目标服务器的公共 IP:
[server-name]
<public-ip> ansible_user=ubuntu ansible_ssh_private_key_file=/home/user/ansible.pem ansible_connection=ssh
注意:
ansible.pem
与目标服务器相同的PEM文件。
我尝试了上述解决方案并解决了同样的问题! 但我没有尝试普通用户,而是尝试使用 Sudo 并且节点已连接。
╰─ sudo ansible all -m ping -v
─╯ 使用 /home/Ansible/Ansible-doc/ansible.cfg 作为配置文件
13.234.48.140 |成功=> {“ansible_facts”:{
“discovered_interpreter_python”:“/usr/bin/python3”
},
“改变”:假,
“乒”:“乒”
}