使用Ansible Ping AWS EC2实例时遭遇Port 22连接超时问题求助
Ansible Ping AWS EC2实例时遭遇Port 22连接超时问题求助
我目前在WSL2环境下学习Ansible,同时使用了一台AWS EC2实例,镜像采用的是RHEL-9.3.0_HVM-20231101-x86_64-5-Hourly2-GP2 AMI。
直接通过SSH连接EC2实例完全正常,命令如下:
ssh -i "my_keys.pem" ec2-user@ec2-xx-xx-xx-x.region-nb.compute.amazonaws.com
但当我运行Ansible的ping模块命令时:
ansible all --key-file ../my_keys.pem -i inventory -m ping
却收到了连接超时的错误:
xx.xx.xx.xx| UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host xx.xxx.xxx.xx port 22: Connection timed out", "unreachable": true }
我已经仔细检查了以下两项内容:
- Ansible的配置文件
- EC2实例的安全组端口规则(22端口)以及允许访问的IP范围
下面是加上-vvvv参数后的详细调试输出:
<xx.xxx.xxx.xx> ESTABLISH SSH CONNECTION FOR USER: None <xx.xxx.xxx.xx> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/home/xyz/xyz/my_keys.pem"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/xyz/.ansible/cp/1f201fc9f0 xx.xxx.xxx.xx'/bin/sh -c '"'"'echo ~ && sleep 0'"'"'' <xx.xxx.xxx.xx> (255, b'', b'OpenSSH_8.2p1 Ubuntu-4ubuntu0.11, OpenSSL 1.1.1f 31 Mar 2020\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug2: resolve_canonicalize: hostname xx.xxx.xxx.xx is address\r\ndebug1: auto-mux: Trying existing master\r\ndebug1: Control socket "/home/xyz/.ansible/cp/1f201fc9f0" does not exist\r\ndebug2: ssh_connect_direct\r\ndebug1: Connecting to xx.xxx.xxx.xx [xx.xxx.xxx.xx] port 22.\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug1: connect to address xx.xxx.xxx.xx port 22: Connection timed out\r\nssh: connect to host xx.xxx.xxx.xxx port 22: Connection timed out\r\n') "msg": "Failed to connect to the host via ssh: OpenSSH_8.2p1 Ubuntu-4ubuntu0.11, OpenSSL 1.1.1f 31 Mar 2020 ndebug1: Reading configuration data /etc/ssh/ssh_config ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for * ndebug2: resolve_canonicalize: hostname xx.xx.xxx.xx is address ndebug1: auto-mux: Trying existing master ndebug1: Control socket \"/home/xyz/.ansible/cp/1f201fc9f0\" does not exist ndebug2: ssh_connect_direct\r\ndebug1: Connecting to xx.xxx.xxx.xx [xx.xxx.xxx.xx] port 22. ndebug2: fd 3 setting O_NONBLOCK ndebug1: connect to address xx.xxx.xx.xx port 22: Connection timed out nssh: connect to host xx.xxx.xxx.xx port 22: Connection timed out",
有没有大佬能给点排查思路或者解决建议?万分感谢!
备注:内容来源于stack exchange,提问作者marcin2x4
相关产品推荐
相关产品推荐

