Ansible ping not giving an output

156 views
Skip to first unread message

Eoghan O'Hara

unread,
Sep 11, 2020, 11:57:12 AM9/11/20
to Ansible Project
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

Eoghan O'Hara

unread,
Sep 11, 2020, 11:59:38 AM9/11/20
to Ansible Project
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

Luca 'remix_tj' Lorenzetto

unread,
Sep 11, 2020, 12:02:41 PM9/11/20
to ansible...@googlegroups.com
Run ansible with more verbosity (-vvv) and then we should have enough informations.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/84b8ca84-c6c2-4d20-9860-a9c81ed3658bn%40googlegroups.com.

Eoghan O'Hara

unread,
Sep 11, 2020, 12:05:45 PM9/11/20
to Ansible Project
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

Luca 'remix_tj' Lorenzetto

unread,
Sep 11, 2020, 12:26:44 PM9/11/20
to ansible...@googlegroups.com
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

Eoghan O'Hara

unread,
Sep 11, 2020, 12:59:56 PM9/11/20
to Ansible Project
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 

Eoghan O'Hara

unread,
Sep 14, 2020, 4:58:02 AM9/14/20
to Ansible Project
Any other suggestions would be greatly appreciated

Tej Singh Rana

unread,
Sep 14, 2020, 5:02:11 AM9/14/20
to ansible...@googlegroups.com
You need to add the ICMP option in the security groups.



--
---------------------
Tej Singh Rana

Eoghan O'Hara

unread,
Sep 14, 2020, 5:49:02 AM9/14/20
to Ansible Project
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

Tej Singh Rana

unread,
Sep 14, 2020, 6:11:49 AM9/14/20
to ansible...@googlegroups.com
Are you able to ping other ec2 instances without ansible?
What is the output of the below command:----
ansible localhost -m ping

Tej Singh Rana

unread,
Sep 14, 2020, 6:15:09 AM9/14/20
to ansible...@googlegroups.com
Try to define under the absolute path 
inventory = /home/eohara/ansible/hosts

Raju Das

unread,
Sep 14, 2020, 6:15:23 AM9/14/20
to ansible...@googlegroups.com
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

 

Tej Singh Rana

unread,
Sep 14, 2020, 6:21:49 AM9/14/20
to ansible...@googlegroups.com
Try with 
ansible all -m ping -i hosts
It will work.

Eoghan O'Hara

unread,
Sep 14, 2020, 6:24:26 AM9/14/20
to Ansible Project
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
$

Eoghan O'Hara

unread,
Sep 14, 2020, 6:26:06 AM9/14/20
to Ansible Project
Tried this, no change

Eoghan O'Hara

unread,
Sep 14, 2020, 6:32:23 AM9/14/20
to Ansible Project
Hi,

It does not work with -i hosts

eohara@LPTP630 ~/ansible
$ ansible all --list-hosts
  hosts (1):

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

Eoghan O'Hara

unread,
Sep 14, 2020, 6:33:35 AM9/14/20
to Ansible Project
Unfortunately,  ansible all -m ping -i hosts  still gives the same result 

Tej Singh Rana

unread,
Sep 14, 2020, 6:52:14 AM9/14/20
to ansible...@googlegroups.com
Any special purpose to define this ec2-18-132-46-235.eu-west-2.compute.amazonaws.com instead of IP of the ec2 instance ?

Dick Visser

unread,
Sep 14, 2020, 7:34:18 AM9/14/20
to ansible...@googlegroups.com
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
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CADBoQTpf4nHm0vHRQGmyeH8ixdNeXfdeCrSV0M-Q0cDHNJp10w%40mail.gmail.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Eoghan O'Hara

unread,
Sep 14, 2020, 7:35:58 AM9/14/20
to Ansible Project
Hi Tej,

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

Raju Das

unread,
Sep 14, 2020, 7:46:54 AM9/14/20
to ansible...@googlegroups.com


Hi ,

ansible -i hosts --private-key=urspemfile.pem -u username -m ping

Please check

With Regards
Raju Das

Eoghan O'Hara

unread,
Sep 14, 2020, 7:51:30 AM9/14/20
to ansible...@googlegroups.com
Hi Dick,

Thanks, I'll look through this again
Eoghan O'Hara | Data Scientist | Kx | +353 858398926 | eoh...@kx.com | Pronounced "own"



You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/68khBsHOHiY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAL8fbwOuKWNRP0TP%2BV7JcKyRGRnyy4BT%2BdWuch6Yf8gRo5hkVQ%40mail.gmail.com.

Eoghan O'Hara

unread,
Sep 14, 2020, 7:57:46 AM9/14/20
to ansible...@googlegroups.com
Hi Raju,

eohara@LPTP630 ~/ansible
$ ansible -vvv -i hosts exampleUBUNTU --private-key ~/.ssh/keypairfile.pem -u ubuntu -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
$

Eoghan O'Hara | Data Scientist | Kx | +353 858398926 | eoh...@kx.com | Pronounced "own"


You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/68khBsHOHiY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAApSnDAQbYhOr4gr_5FEUdW9inW%2B3Y69B5V0QfWYu1LWRSUWtQ%40mail.gmail.com.

Raju Das

unread,
Sep 14, 2020, 8:02:07 AM9/14/20
to ansible...@googlegroups.com
use this 

ansible  -i hosts --private-key=/home/eohara/.ssh/keypairfile.pem -u ubuntu -m ping

Eoghan O'Hara

unread,
Sep 14, 2020, 8:25:07 AM9/14/20
to Ansible Project
eohara@LPTP630 ~/ansible
$ ansible -vvv -i hosts --private-key=/home/eohara/.ssh/keypairfile.pem -u ubuntu -m ping
Usage: ansible <host-pattern> [options]

Define and run a single task 'playbook' against a set of hosts

Options:
  -a MODULE_ARGS, --args=MODULE_ARGS
                        module arguments
  --ask-vault-pass      ask for vault password
  -B SECONDS, --background=SECONDS
                        run asynchronously, failing after X seconds
                        (default=N/A)
  -C, --check           don't make any changes; instead, try to predict some
                        of the changes that may occur
  -D, --diff            when changing (small) files and templates, show the
                        differences in those files; works great with --check
  -e EXTRA_VARS, --extra-vars=EXTRA_VARS
                        set additional variables as key=value or YAML/JSON, if
                        filename prepend with @
  -f FORKS, --forks=FORKS
                        specify number of parallel processes to use
                        (default=5)
  -h, --help            show this help message and exit
  -i INVENTORY, --inventory=INVENTORY, --inventory-file=INVENTORY
                        specify inventory host path or comma separated host
                        list. --inventory-file is deprecated
  -l SUBSET, --limit=SUBSET
                        further limit selected hosts to an additional pattern
  --list-hosts          outputs a list of matching hosts; does not execute
                        anything else
  -m MODULE_NAME, --module-name=MODULE_NAME
                        module name to execute (default=command)
  -M MODULE_PATH, --module-path=MODULE_PATH
                        prepend colon-separated path(s) to module library (def
                        ault=~/.ansible/plugins/modules:/usr/share/ansible/plu
                        gins/modules)
  -o, --one-line        condense output
  --playbook-dir=BASEDIR
                        Since this tool does not use playbooks, use this as a
                        substitute playbook directory.This sets the relative
                        path for many features including roles/ group_vars/
                        etc.
  -P POLL_INTERVAL, --poll=POLL_INTERVAL
                        set the poll interval if using -B (default=15)
  --syntax-check        perform a syntax check on the playbook, but do not
                        execute it
  -t TREE, --tree=TREE  log output to this directory
  --vault-id=VAULT_IDS  the vault identity to use
  --vault-password-file=VAULT_PASSWORD_FILES
                        vault password file
  -v, --verbose         verbose mode (-vvv for more, -vvvv to enable
                        connection debugging)
  --version             show program's version number, config file location,
                        configured module search path, module location,
                        executable location and exit

  Privilege Escalation Options:
    control how and which user you become as on target hosts

    -b, --become        run operations with become (does not imply password
                        prompting)
    --become-method=BECOME_METHOD
                        privilege escalation method to use (default=sudo), use
                        `ansible-doc -t become -l` to list valid choices.
    --become-user=BECOME_USER
                        run operations as this user (default=root)
    -K, --ask-become-pass
                        ask for privilege escalation password

  Connection Options:
    control as whom and how to connect to hosts

    -k, --ask-pass      ask for connection password
    --private-key=PRIVATE_KEY_FILE, --key-file=PRIVATE_KEY_FILE
                        use this file to authenticate the connection
    -u REMOTE_USER, --user=REMOTE_USER
                        connect as this user (default=None)
    -c CONNECTION, --connection=CONNECTION
                        connection type to use (default=smart)
    -T TIMEOUT, --timeout=TIMEOUT
                        override the connection timeout in seconds
                        (default=10)
    --ssh-common-args=SSH_COMMON_ARGS
                        specify common arguments to pass to sftp/scp/ssh (e.g.
                        ProxyCommand)
    --sftp-extra-args=SFTP_EXTRA_ARGS
                        specify extra arguments to pass to sftp only (e.g. -f,
                        -l)
    --scp-extra-args=SCP_EXTRA_ARGS
                        specify extra arguments to pass to scp only (e.g. -l)
    --ssh-extra-args=SSH_EXTRA_ARGS
                        specify extra arguments to pass to ssh only (e.g. -R)

Some modules do not make sense in Ad-Hoc (include, meta, etc)
ERROR! Missing target hosts

eohara@LPTP630 ~/ansible
$ ansible -vvv -i hosts all --private-key=/home/eohara/.ssh/keypairfile.pem -u ubuntu -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
$

Raju Das

unread,
Sep 14, 2020, 8:27:19 AM9/14/20
to ansible...@googlegroups.com
See i think you have ssh config problem. either you have to do passwordless or using private keyfile(update inventory)

[server]
Pub_Private_IP ansible_user=username ansible_ssh_private_key_file=key.pem

With Regards
Raju Das

Raju Das

unread,
Sep 14, 2020, 8:46:49 AM9/14/20
to ansible...@googlegroups.com
Hi Eoghan,

You can also check if it is plugin issue. As it is showing "Parsed /home/eohara/ansible/hosts inventory source with ini plugin"

Adding to ansible.cfg.
[inventory]
enable_plugins = host_list, script, auto, yaml, ini, toml

Eoghan O'Hara

unread,
Sep 14, 2020, 1:25:15 PM9/14/20
to ansible...@googlegroups.com
Hi Raju,

I tried that as well.

I am now investigating my ssh configuration.

Thank you all for the help!

Eoghan

Eoghan O'Hara | Data Scientist | Kx | +353 858398926 | eoh...@kx.com | Pronounced "own"


Tej Singh Rana

unread,
Sep 14, 2020, 1:29:28 PM9/14/20
to ansible...@googlegroups.com
Please let us know what is the actual cause.

Eoghan O'Hara

unread,
Sep 15, 2020, 11:38:51 AM9/15/20
to ansible...@googlegroups.com
Hi all,

Still investigating this issue. Does anyone have any experience of correcting such an ssh issue?

Dick, I looked at your second link. It doesn't have any tips on how to fix an issue unfortunately.

Thanks everyone,
Eoghan
Eoghan O'Hara | Data Scientist | Kx | +353 858398926 | eoh...@kx.com | Pronounced "own"


Reply all
Reply to author
Forward
0 new messages