Ansible "provided hosts list is empty" error
Solution 1
I found the problem and solution:
There is a section named [inventory] in the ansible.cfg file. Remove # character at the start of line "enable inventory plugins...". Then .yml and .yaml inventory files will been activated.
Also, ":" character is necessary after every line else hostnames too.
Solution 2
In the example on the following link every line, including the server names, ends with a colon character:
https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html
Related videos on Youtube
Jo Shepherd
Unix Specialist, Bash Scripter, Automation Lover, Cartoon Drawer, 3D asset Creator
Updated on September 18, 2022Comments
-
Jo Shepherd over 1 year
I created an inventory file has .yml extension like below:
--- all: server1 hosts: server2 children: hana: prod: client1: hosts: server3 client2: hosts: server4 test: client1: hosts: server5 client1: hosts: server6 ...
Then I ran ping ad-hoc for all hosts with below command:
ansible -m ping -i /etc/ansible/inventories/linuxall.yml all
And I saw these warnings and ping didn't work:
[WARNING]: Unable to parse /etc/ansible/inventories/linuxall.yml 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'
Why ansible cannot parse my inventory? Should I do anything for this?
-
Jo Shepherd over 4 yearsthanks. I saw this tutorial. I found the the reason of the problem. I'll add an solution asap. It's not about the file, it's about config file.
-
Myer about 3 yearsdocs.ansible.com/ansible/latest/cli/… says that
-K
is the "ask for privilege escalation password" switch, not the switch to specify the location of playbook.yml