Run Multiple hosts error

I have a playbook called multiple.yml that tests for ping:

  • name: Playbook for multiple hosts
    hosts: bgrsuistg
    tasks:
  • name: ping
    win_ping:

My host file for bgrsuistg looks like this:

[bgrsuistg]
server1 ansible_host=10.125.xx.xx

server2 ansible_host=10.125.xx.xx
server3 ansible_host=10.125.xx.xx

server4 ansible_host=10.125.xx.xx
server5 ansible_host=10.125.xx.xx
When I run:

ansible-playbook playbooks/multiple.yml -i bgrsuistg -vvvv, I get the below error:

root@ansiblectrl01:/etc/ansible# ansible-playbook playbooks/multiple.yml -i bgrsuistg -vvvv
ansible-playbook [core 2.12.0]
config file = /etc/ansible/ansible.cfg
configured module search path = [‘/root/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-playbook
python version = 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
jinja version = 2.10.1
libyaml = True
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /etc/ansible/bgrsuistg as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/bgrsuistg as it did not pass its verify_file() method
auto declined parsing /etc/ansible/bgrsuistg as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/bgrsuistg as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/bgrsuistg as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/bgrsuistg as it did not pass its verify_file() method
[WARNING]: Unable to parse /etc/ansible/bgrsuistg as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ‘all’
redirecting (type: modules) ansible.builtin.win_ping to ansible.windows.win_ping
Loading collection ansible.windows from /usr/local/lib/python3.8/dist-packages/ansible_collections/ansible/windows
Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python3.8/dist-packages/ansible/plugins/callback/default.py
Skipping callback ‘default’, as we already have a stdout callback.
Skipping callback ‘minimal’, as we already have a stdout callback.
Skipping callback ‘oneline’, as we already have a stdout callback.

PLAYBOOK: multiple.yml *********************************************************************************************************************************************************************************
Positional arguments: playbooks/multiple.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: (‘all’,)
inventory: (‘/etc/ansible/bgrsuistg’,)
forks: 5
1 plays in playbooks/multiple.yml
[WARNING]: Could not match supplied host pattern, ignoring: bgrsuistg

PLAY [ping windows hosts] ******************************************************************************************************************************************************************************
skipping: no hosts matched

PLAY RECAP ************************************************************************************************************************************************

What am I doing wrong?

Thanks

Hey,

It works here so its likely your inventory is not in the path you think it is, its for some reason unreadable but unlikely as it looks like your logged in as root.

Regards

Thanks, where can I specify the path to the inventory?

We usually just add a list of VMs and their IP in the /etc/ansible/host file.

Use ansible-config dump to see what’s being set where.

The command you ran is looking for your inventory at /etc/ansible/bgrsuistg. If that’s wrong, list the full path or relative path in the parameter to the -i option, like -i ./bgrsuistg

This is what ansible dump shows:

root@ansiblectrl01:/etc/ansible/playbooks# ansible-config dump
ACTION_WARNINGS(default) = True
AGNOSTIC_BECOME_PROMPT(default) = True
ALLOW_WORLD_READABLE_TMPFILES(default) = False
ANSIBLE_CONNECTION_PATH(default) = None
ANSIBLE_COW_ACCEPTLIST(default) = [‘bud-frogs’, ‘bunny’, ‘cheese’, ‘daemon’, ‘default’, ‘dragon’, ‘elephant-in-snake’, ‘elephant’, ‘eyes’, ‘hellokitty’, ‘kitty’, ‘luke-koala’, ‘meow’, ‘milk’, ‘moofas>
ANSIBLE_COW_PATH(default) = None
ANSIBLE_COW_SELECTION(default) = default
ANSIBLE_FORCE_COLOR(default) = False
ANSIBLE_NOCOLOR(default) = False
ANSIBLE_NOCOWS(default) = False
ANSIBLE_PIPELINING(default) = False
ANY_ERRORS_FATAL(default) = False
BECOME_ALLOW_SAME_USER(default) = False
BECOME_PASSWORD_FILE(default) = None
BECOME_PLUGIN_PATH(default) = [’/root/.ansible/plugins/become’, ‘/usr/share/ansible/plugins/become’]
CACHE_PLUGIN(default) = memory
CACHE_PLUGIN_CONNECTION(default) = None
CACHE_PLUGIN_PREFIX(default) = ansible_facts
CACHE_PLUGIN_TIMEOUT(default) = 86400

There is no file at /etc/ansible/bgrsuistg, I usually use host file to specify VMs, for e.g:

[bgrsuistg]
server1 ansible_host=10.125.xx.xx

server2 ansible_host=10.125.xx.xx
server3 ansible_host=10.125.xx.xx

server4 ansible_host=10.125.xx.xx
server5 ansible_host=10.125.xx.xx

What do you get if you use -i ./bgrsuistg instead of -i bgrsuistg ?

Thanks Everyone.

Ok, I think I managed to figure this out, the below works:

root@ansiblectrl01:/etc/ansible# ansible-playbook -i hosts playbooks/multiple.yml