Alex111
Alex111

Reputation: 29

How do I get Ansible to ping other AWS servers?

I am using RHEL 7.x as my control server. I have installed Ansible 2.2.2.0. The managed nodes are running CentOS 6. I cannot upgrade Ansible because of an incompatibility.

Without Ansible, I can ping the managed servers from the control server. From the control server I can SSH to the managed nodes without password authentication. With Ansible from the control server, I cannot ping the managed servers. Why cannot I use basic Ansible operations (e.g., ansible -m ping all)?

Here are some details. As root, I run this:

ansible -m ping all -vvvv

I saw this:

| UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: Applying options for *\r\npercent_expand: unknown key %C\r\n", "unreachable": true

So I rebooted.

I tried it again. I saw this:

[WARNING]: scp transfer mechanism failed on [x.y.z.z]. Use ANSIBLE_DEBUG=1 to see detailed information

x.y.z.z | FAILED! => { "failed": true, "msg": "failed to transfer file to Please login as the user \"centos\" rather than the user \"root\"./ping.py:\n\nExecuting: program /usr/bin/ssh host x.y.z.z, user (unspecified), command scp -v -t 'Please login as the user \"centos\" rather than the user \"root\"./ping.py'\nOpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 10256\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 4\r\nPlease login as the user \"centos\" rather than the user \"root\".\n" } [WARNING]: scp transfer mechanism failed on [z.x.y.w]. Use ANSIBLE_DEBUG=1 to see detailed information

z.x.y.w | FAILED! => { "failed": true, "msg": "failed to transfer file to Please login as the user \"centos\" rather than the user \"root\"./ping.py:\n\nExecuting: program /usr/bin/ssh host z.x.y.w, user (unspecified), command scp -v -t 'Please login as the user \"centos\" rather than the user \"root\"./ping.py'\nOpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 10259\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 4\r\nPlease login as the user \"centos\" rather than the user \"root\".\n" }

I then assumed the Linux user "centos" (su centos). I then tried the ansible commands again. I ran this command:

ansible -m ping all -vvvv

I saw this:

x.y.z.z | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: OpenSSH_6.6.1, OpenSSL 1.0.1e
-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\nd
ebug1: /etc/ssh/ssh_config line 56: Applying options for *\r\ndebug1: auto-mux:
Trying existing master\r\ndebug1: Control socket \"/home/centos/.ansible/cp/ansi
ble-ssh-x.y.z.z-22-centos\" does not exist\r\ndebug2: ssh_connect: needpri
v 0\r\ndebug1: Connecting to x.y.z.z [x.y.z.z] port 22.\r\ndebug2: f
d 3 setting O_NONBLOCK\r\ndebug1: fd 3 clearing O_NONBLOCK\r\ndebug1:

... partially removed because it "looked like spam"

est\r\ndebug2: we sent a publickey packet, wait for reply\r\ndebug1: Authenticat
ions that can continue: publickey,gssapi-keyex,gssapi-with-mic\r\ndebug1: Trying
private key: /home/centos/.ssh/id_dsa\r\ndebug3: no such identity: /home/centos
/.ssh/id_dsa: No such file or directory\r\ndebug1: Trying private key: /home/cen
tos/.ssh/id_ecdsa\r\ndebug3: no such identity: /home/centos/.ssh/id_ecdsa: No su
ch file or directory\r\ndebug1: Trying private key: /home/centos/.ssh/id_ed25519
\r\ndebug3: no such identity: /home/centos/.ssh/id_ed25519: No such file or dire
ctory\r\ndebug2: we did not send a packet, disable method\r\ndebug1: No more aut
hentication methods to try.\r\nPermission denied (publickey,gssapi-keyex,gssapi-
with-mic).\r\n", "unreachable": true }

My ansible.cfg file looks like this:

[defaults]
host_key_checking = False
library = ../extra_modules
roles_path = ../roles
pipelining = True
remote_user = centos
forks = 20
log_path = ./ansible.log


[ssh_connection]
control_path = ~/.ssh/ansible-ssh-%%C

What is wrong? Why cannot I ping Ansible managed nodes?

Upvotes: 0

Views: 967

Answers (1)

Berlin
Berlin

Reputation: 1464

Can you please share your Ansible hosts/inventory file and.ssh folder (ls ~/.ssh)?

Also please try do to something like that and passing the ssh private key and the user name variables via cli:

ansiblie.cfg

[ssh_connection]
pipelining = True
ssh_args = -o ControlMaster=auto -o ControlPersist=30m -o StrictHostKeyChecking=no
control_path = /tmp/ansible-ssh-%%h-%%p-%%r

command:

ansible -m ping all -i <inventory_file> --private-key=~/.ssh/<your pem key.pem> -u <login user ubuntu/centos>

Upvotes: 2

Related Questions