I have 3 machines provisioned on KVM. Here is my inventory:

[local]
localhost ansible_connection=local


[dbservers]
server1 
server2
server3


When I run from the command line: 

$ ansible localhost -m virt -a "name=scylla3 command=status"

localhost | SUCCESS => {
    "changed": false, 
    "failed": false, 
    "status": "running"
}

It works perfectly fine.

But from my playbook

 - hosts: dbservers
   tasks:
      - name: Test command for VMs
        virt:
          command: status
          name: '{{ansible_host }}'

I get the following error:
An exception occurred during task execution. To see the full traceback, use 
-vvv. The error was: VMNotFound: virtual machine server1 not found
fatal: [server1]: FAILED! => {"changed": false, "failed": true, "msg": "virtual 
machine server1 not found"}
An exception occurred during task execution. To see the full traceback, use 
-vvv. The error was: VMNotFound: virtual machine server2 not found
fatal: [server2]: FAILED! => {"changed": false, "failed": true, "msg": "virtual 
machine server2 not found"}
An exception occurred during task execution. To see the full traceback, use 
-vvv. The error was: VMNotFound: virtual machine server3 not found
fatal: [server3]: FAILED! => {"changed": false, "failed": true, "msg": "virtual 
machine server3 not found"}

Running with -vvv the relevant part:

The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_WuP4hq/ansible_module_virt.py", line 540, in main
    rc, result = core(module)
  File "/tmp/ansible_WuP4hq/ansible_module_virt.py", line 506, in core
    res = getattr(v, command)(guest)
  File "/tmp/ansible_WuP4hq/ansible_module_virt.py", line 410, in status
    return self.conn.get_status(vmid)
  File "/tmp/ansible_WuP4hq/ansible_module_virt.py", line 236, in get_status
    state = self.find_vm(vmid).info()[0]
  File "/tmp/ansible_WuP4hq/ansible_module_virt.py", line 205, in find_vm
    raise VMNotFound("virtual machine %s not found" % vmid)
VMNotFound: virtual machine server3 not found


fatal: [server3]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "autostart": null, 
            "command": "status", 
            "name": "server3", 
            "state": null, 
            "uri": "qemu:///system", 
            "xml": null
        }
    }, 
    "msg": "virtual machine server3 not found"
}

Not sure what I'm doing wrong. Any help appreciated.





-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9f76338d-b84a-4564-ab22-067f709375d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to