# New to Ansible - Facing issue with ping to target host

**URL:** <https://forum.ansible.com/t/new-to-ansible-facing-issue-with-ping-to-target-host/32469>\
**Category:** Ansible Project\
**Tags:** ubuntu, aws\
**Created:** [March 16, 2020, 2:27am UTC](https://forum.ansible.com/t/new-to-ansible-facing-issue-with-ping-to-target-host/32469 "2020-03-16T02:27:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![P\_r1](https://avatars.discourse-cdn.com/v4/letter/p/b38774/32.png) [@P\_r1](https://forum.ansible.com/u/P_r1)\
**Post date:** [March 16, 2020, 2:27am UTC](https://forum.ansible.com/t/new-to-ansible-facing-issue-with-ping-to-target-host/32469/1 "2020-03-16T02:27:51Z")

</div>

Ansible Control Machine (ip = 1.1.1.1):

NAME=“Ubuntu”

VERSION=“18.04.3 LTS (Bionic Beaver)”

Target Node (ip = 2.2.2.2):

NAME=“Amazon Linux”

VERSION=“2”

I am able to ssh from Ansible Control Machine to Target node if I manually type the SSH commands (Which means the keys from Ansible Control machine are properly copied to Target node already)

ubuntu@ip-1.1.1.1:~/ansible$ ssh [ec2-user@2.2.2.2](mailto:ec2-user@2.2.2.2)

Last login: Mon Mar 16 02:13:42 2020 from ip-1.1.1.1.us-west-2.compute.internal

\_\_| \__|_ )

\_| ( / Amazon Linux 2 AMI

_ **|\_** |_\_\_|

[https://aws.amazon.com/amazon-linux-2/](https://aws.amazon.com/amazon-linux-2/)

[ec2-user@ip-2.2.2.2 ~]$

But when I run the ansible command to ping target node, I get error:

ubuntu@ip-1.1.1.1:~/ansible$ ansible -i hosts -m ping all -vvv

ansible 2.5.1

config file = /home/ubuntu/ansible/ansible.cfg

configured module search path = [u’/home/ubuntu/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]

ansible python module location = /usr/lib/python2.7/dist-packages/ansible

executable location = /usr/bin/ansible

python version = 2.7.17 (default, Nov 7 2019, 10:07:09) [GCC 7.4.0]

Using /home/ubuntu/ansible/ansible.cfg as config file

Parsed /home/ubuntu/ansible/hosts inventory source with ini plugin

META: ran handlers

Using module file /usr/lib/python2.7/dist-packages/ansible/modules/system/ping.py

\<1.1.1.1\> ESTABLISH SSH CONNECTION FOR USER: ubuntu

\<1.1.1.1\> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 -o ControlPath=/home/ubuntu/.ansible/cp/297a4ed557 1.1.1.1 ‘/bin/sh -c ‘"’“‘echo ~ && sleep 0’”’"‘’

\<1.1.1.1\> (255, ‘’, ‘ubuntu@1.1.1.1: Permission denied (publickey).\r\n’)

1.1.1.1 | UNREACHABLE! =\> {

“changed”: false,

“msg”: “Failed to connect to the host via ssh: [ubuntu@1.1.1.1](mailto:ubuntu@1.1.1.1): Permission denied (publickey).\r\n”,

“unreachable”: true

}

“hosts” file

[all]

2.2.2.2

"ansible.cfg: file

[default]

inventory = hosts

ansible.cfg (END)

Please suggest how to resolve the issue.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [March 16, 2020, 2:53am UTC](https://forum.ansible.com/t/new-to-ansible-facing-issue-with-ping-to-target-host/32469/2 "2020-03-16T02:53:06Z")

</div>

You're able to connect to "ec2-user@2.2.2.2". The same "REMOTE\_USER" must be  
specified in Ansible. For example

&nbsp;&nbsp;$ ansible -i hosts -m ping -vvv -u ec2-user all

See

"Hosts and Users" (remote\_user)  
[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_intro.html#hosts-and-users](https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html#hosts-and-users)

"Adding variables to inventory" (ansible\_user)  
[https://docs.ansible.com/ansible/latest/user\_guide/intro\_inventory.html#adding-variables-to-inventory](https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#adding-variables-to-inventory)

"Ansible remote\_user vs ansible\_user"  
[https://stackoverflow.com/questions/36668756/ansible-remote-user-vs-ansible-user](https://stackoverflow.com/questions/36668756/ansible-remote-user-vs-ansible-user)

HTH,

&nbsp;&nbsp;-vlado
