# ansible ping fails, but can SSH to host just fine

**URL:** <https://forum.ansible.com/t/ansible-ping-fails-but-can-ssh-to-host-just-fine/32638>\
**Category:** Ansible Project\
**Created:** [April 8, 2020, 7:33pm UTC](https://forum.ansible.com/t/ansible-ping-fails-but-can-ssh-to-host-just-fine/32638 "2020-04-08T19:33:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Egloff](https://avatars.discourse-cdn.com/v4/letter/r/e274bd/32.png) [@Robert\_Egloff](https://forum.ansible.com/u/Robert_Egloff)\
**Post date:** [April 8, 2020, 7:33pm UTC](https://forum.ansible.com/t/ansible-ping-fails-but-can-ssh-to-host-just-fine/32638/1 "2020-04-08T19:33:17Z")

</div>

I’m sure it’s something I’m doing… but I managed to create a playbook to create my ansible user, add the SSH key, and all of that to a remote server.  
However, to get it to run - I need to use the --ask-pass parameter.

ansible-playbook -i “remote\_server,” add\_ans\_user.yml -b --ask-pass \<\< That works and creates the user just fine, which makes sense as it needs to create the account as root.

After running the playbook to create the user, I can SSH without issues as the user to the remote server, no password required - which means it should be using the SSH key just fine.

The playbook adds the public key (key\_file: “/opt/ansible\_account/.ssh/id\_rsa.pub”) - which seems to work for authentication for this account.

[ansible\_account@remote\_server linux\_small\_plays]$ ssh remote\_server  
Last login: Wed Apr 8 11:09:20 2020 from remote\_server.domain.com  
[ansible\_account@remote\_server ~]$

But when I attempt a ping with this account, it fails.

[ansible\_account@ansible\_controller linux\_small\_plays]$ ansible -m ping remote\_server  
Wednesday 08 April 2020 14:14:38 -0500 (0:00:00.077) 0:00:00.077 \*\*\*\*\*\*\*  
remote\_server | UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).”,  
“unreachable”: true  
}  
Wednesday 08 April 2020 14:14:39 -0500 (0:00:00.335) 0:00:00.413 \*\*\*\*\*\*\*

---

<div class="post-metadata">

**Author:** ![Robert\_Egloff](https://avatars.discourse-cdn.com/v4/letter/r/e274bd/32.png) [@Robert\_Egloff](https://forum.ansible.com/u/Robert_Egloff)\
**Post date:** [April 8, 2020, 7:45pm UTC](https://forum.ansible.com/t/ansible-ping-fails-but-can-ssh-to-host-just-fine/32638/2 "2020-04-08T19:45:44Z")

</div>

Right after I posted this - I found the answer and I’ll update it in case anyone else runs into this.  
As I was closing some of my many open tabs (bad about that) - I ran across this:

[https://github.com/ansible/ansible/issues/19584](https://github.com/ansible/ansible/issues/19584)

Someone suggested in this person’s case to run this command: ansible all -u ec2-user -m ping -vvv

So I tried that command defining the user and it worked immediately.

After a little more digging, the directory I was running Ansible in had an ‘ansible.cfg’ file that was defining the user as ‘root’. So it seems it was attempting to connect as root, but using the SSH key file for the ansible\_account. After that, just moving out of my test directory proved that running the command ‘vanilla’ worked just fine.

**[ansible\_account@ansible\_controller ~]$ ansible -m ping remote\_server Wednesday 08 April 2020 14:39:18 -0500 (0:00:00.075) 0:00:00.075 \*\*\*\*\*\*\* remote\_server | SUCCESS =\> { "changed": false, "ping": "pong" } Wednesday 08 April 2020 14:39:20 -0500 (0:00:01.487) 0:00:01.562 \*\*\*\*\*\*\***
