Ansible "provided hosts list is empty" error

15,536

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

Share:
15,536

Related videos on Youtube

Jo Shepherd
Author by

Jo Shepherd

Unix Specialist, Bash Scripter, Automation Lover, Cartoon Drawer, 3D asset Creator

Updated on September 18, 2022

Comments

  • Jo Shepherd
    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
    Jo Shepherd over 4 years
    thanks. 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
    Myer about 3 years
    docs.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