0

I am trying to run a playbook on a selective host after it has been provisioned using earlier set of tasks

I am able to ping the host and the same is available in the /etc/ansible/hosts file however the play says skipping: no hosts matched and does not run.

Ansible hosts file looks like below

vm1  ansible_host=192.168.200.52

I have tried mentioning the inventory file using -i with no success, what could be wrong here ?

UPDATE: Added the /etc/ansible/hosts as default inventory however the playbook still says its not able to see the VM

screenshot

0

Ansible hosts file looks like below

vm1  ansible_host=192.168.200.52

Q: "I have tried mentioning the inventory file using -i with no success, what could be wrong here?"

A: To see what's wrong run the command below

$ ansible-inventory -i hosts --list

The output should give

{
    "_meta": {
        "hostvars": {
            "vm1": {
                "ansible_host": "192.168.200.52"
            }
        }
    }, 
    "all": {
        "children": [
            "ungrouped"
        ]
    }, 
    "ungrouped": {
        "hosts": [
            "vm1"
        ]
    }
}

A simple playbook

- hosts: vm1
  gather_facts: false
  tasks:
    - debug:
        var: ansible_host

should give

$ ansible-playbook -i hosts playbook.yml
...
ok: [vm1] => {
    "ansible_host": "192.168.200.52"
  • Mine gives a bit different output, not sure why its paring /home/neon/scripts/ansible/virtualbox/hosts. I am trying to use default /etc/ansible/hosts for inventory items [WARNING]: Unable to parse /home/neon/scripts/ansible/virtualbox/hosts as an inventory source [WARNING]: No inventory was parsed, only implicit localhost is available { "_meta": { "hostvars": {} }, "all": { "children": [ "ungrouped" ] } } – Atul Feb 2 '20 at 14:50
  • I see. You are in the right direction to find out what could be wrong here. – Vladimir Botka Feb 2 '20 at 14:55
  • Unfortunately, i am still stuck. Updated the question with more details – Atul Feb 5 '20 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.