Ansible ping not giving an output

Hi,

I am learning to use Ansible, and am at the stage of pinging a remote host, an AWS EC2 instance in this case.

However, when I run ansible ping I get no output, as below:

$ ssh ec2-user@ec2-DNS
This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register

Last login: Fri Sep 11 15:10:27 2020 from ...
[ec2-user@ip-bla ~]$ logout
Connection to ec2-DNS closed.

$ ls

ansible.cfg hosts

$ ansible -m ping all

$

Any ideas what I may be causing this? I have my ec2-DNS defined in my hosts file, and in ansible.cfg inventory is pointing at hosts in the current working directory. I also have remote_user = ec2-user in ansible.cfg

Thanks in advance,
Eoghan

More information…

$ ansible --version
ansible 2.8.4
config file = /home/eohara/ansible/ansible.cfg
configured module search path = [‘/home/eohara/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python3.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.7.7 (default, Apr 10 2020, 07:59:19) [GCC 9.3.0]

I do not have Python installed on my EC2 instance yet, but if this was the issue I would expect an error message of some kind

Run ansible with more verbosity (-vvv) and then we should have enough informations.

Hi Luca,

Thank you for the response!

$ ansible -vvv -m ping all
ansible 2.8.4
config file = /home/eohara/ansible/ansible.cfg
configured module search path = [‘/home/eohara/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python3.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.7.7 (default, Apr 10 2020, 07:59:19) [GCC 9.3.0]
Using /home/eohara/ansible/ansible.cfg as config file
host_list declined parsing /home/eohara/ansible/hosts as it did not pass it’s verify_file() method
script declined parsing /home/eohara/ansible/hosts as it did not pass it’s verify_file() method
auto declined parsing /home/eohara/ansible/hosts as it did not pass it’s verify_file() method
Parsed /home/eohara/ansible/hosts inventory source with ini plugin

Looks like you’re having an issue with your inventory file, please check if file specified in -i parameter is a valid inventory file.

Luca

The file specified in -i is hosts in the current working directory

See below

$ head -15 ansible.cfg

config file for ansible – https://ansible.com/

===============================================

nearly all parameters can be overridden in ansible-playbook

or with command line flags. ansible will read ANSIBLE_CONFIG,

ansible.cfg in the current working directory, .ansible.cfg in

the home directory or /etc/ansible/ansible.cfg, whichever it

finds first

[defaults]

some basic default values…

inventory = hosts
#library = /usr/share/my_modules/

$ cat hosts

[example]
public.IP.of.EC2instance

$

I can not see anything wrong with this

Any other suggestions would be greatly appreciated

You need to add the ICMP option in the security groups.

Hi Tej,

I have tried that on my inbound rules, to no avail.

As a test, I set inbound and outbound rules in my security group to accept all traffic on all protocols. Still, I am seeing the same output

Are you able to ping other ec2 instances without ansible?
What is the output of the below command:----
ansible localhost -m ping

Try to define under the absolute path
inventory = /home/eohara/ansible/hosts

Hi Eoghan,

Are you able to run it explicitly using ( -i hosts)? And are u able to check --list-host? permission of the hosts file? password less auth has been configured?

WIth Regards
Raju Das

Try with
ansible all -m ping -i hosts
It will work.

I can ping the current ec2 instance and another one without ansible.

The output of that command is below

eohara@LPTP630 ~/ansible
$ ansible -vvv localhost -m ping
ansible 2.8.4
config file = /home/eohara/ansible/ansible.cfg
configured module search path = [‘/home/eohara/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python3.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.7.7 (default, Apr 10 2020, 07:59:19) [GCC 9.3.0]
Using /home/eohara/ansible/ansible.cfg as config file
host_list declined parsing /home/eohara/ansible/hosts as it did not pass it’s verify_file() method
script declined parsing /home/eohara/ansible/hosts as it did not pass it’s verify_file() method
auto declined parsing /home/eohara/ansible/hosts as it did not pass it’s verify_file() method
Parsed /home/eohara/ansible/hosts inventory source with ini plugin

eohara@LPTP630 ~/ansible
$

Tried this, no change

Hi,

It does not work with -i hosts

eohara@LPTP630 ~/ansible
$ ansible all --list-hosts
hosts (1):
ec2-18-132-46-235.eu-west-2.compute.amazonaws.com

eohara@LPTP630 ~/ansible
$

eohara@LPTP630 ~/ansible
$ ls -lart
total 25
-rw-r–r-- 1 eohara FD+Group(513) 50 Sep 14 10:46 hosts
-rw-r–r-- 1 eohara FD+Group(513) 19983 Sep 14 11:25 ansible.cfg

By password-less auth, you mean I have an ssh key added and I can ssh to the instance without entering a password? Then yes that is configured

Unfortunately, ansible all -m ping -i hosts still gives the same result

Any special purpose to define this ec2-18-132-46-235.eu-west-2.compute.amazonaws.com instead of IP of the ec2 instance ?

As stated on https://docs.ansible.com/ansible/latest/modules/ping_module.html,
it is NOT ICMP ping, this is just a trivial test module that requires
Python on the remote-node.
If ansible ping fails, this means that your SSH config/setup is wrong.
This needs to be fixed before you can do anything.
It is covered in the 'getting started' pages:
https://docs.ansible.com/ansible/latest/user_guide/intro_getting_started.html#getting-started

Hi Tej,

No special purpose. I changed to IP now, no change