Kai, thanks a lot for taking the time to reply.

Tried with delegate_to

"msg": "Unsupported parameters for (virt) module: delegate_to Supported 
parameters include: autostart,command,name,state,uri,xml"

I already tried with localhost on the playbook, let me try again.

Changing the name to localhost:

 - hosts: dbservers
   tasks:

      - name: Test command for VMs
        virt:
          command: status
          name: localhost


<server3> (0, '\r\n{"msg": "virtual machine localhost not found", "failed": 
true, "exception": "Traceback (most recent call last):\\n  File 
\\"/tmp/ansible_mQLcdU/ansible_module_virt.py\\", line 540, in main\\n   
 rc, result = core(module)\\n  File 
\\"/tmp/ansible_mQLcdU/ansible_module_virt.py\\", line 506, in core\\n   
 res = getattr(v, command)(guest)\\n  File 
\\"/tmp/ansible_mQLcdU/ansible_module_virt.py\\", line 410, in status\\n   
 return self.conn.get_status(vmid)\\n  File 
\\"/tmp/ansible_mQLcdU/ansible_module_virt.py\\", line 236, in 
get_status\\n    state = self.find_vm(vmid).info()[0]\\n  File 
\\"/tmp/ansible_mQLcdU/ansible_module_virt.py\\", line 205, in find_vm\\n   
 raise VMNotFound(\\"virtual machine %s not found\\" % vmid)\\nVMNotFound: 
virtual machine localhost not found\\n", "invocation": {"module_args": 
{"xml": null, "name": "localhost", "uri": "qemu:///system", "state": null, 
"command": "status", "autostart": null}}}\r\n', 'Shared connection to 
server3 closed.\r\n')
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_mQLcdU/ansible_module_virt.py", line 540, in main
    rc, result = core(module)
  File "/tmp/ansible_mQLcdU/ansible_module_virt.py", line 506, in core
    res = getattr(v, command)(guest)
  File "/tmp/ansible_mQLcdU/ansible_module_virt.py", line 410, in status
    return self.conn.get_status(vmid)
  File "/tmp/ansible_mQLcdU/ansible_module_virt.py", line 236, in get_status
    state = self.find_vm(vmid).info()[0]
  File "/tmp/ansible_mQLcdU/ansible_module_virt.py", line 205, in find_vm
    raise VMNotFound("virtual machine %s not found" % vmid)
VMNotFound: virtual machine localhost not found


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


Changing hosts and removing name:


 - hosts: local
   tasks:
      - name: Test command for VMs
        virt:
          command: status


TASK [Test command for VMs] 
*****************************************************************************************************************************************************************************************
task path: /home/bfranklin/bin/test.test/tasks/test3.yml:20
Using module file /home/bfranklin/.local/lib/python2.7/site-packages/ansible
/modules/cloud/misc/virt.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: bfranklin
<localhost> EXEC /bin/sh -c 'echo ~ && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo 
/home/bfranklin/.ansible/tmp/ansible-tmp-1510956849.89-176724624375677 `" 
&& echo ansible-tmp-1510956849.89-176724624375677="` echo 
/home/bfranklin/.ansible/tmp/ansible-tmp-1510956849.89-176724624375677 `" ) 
&& sleep 0'
<localhost> PUT /tmp/tmpgNSjwP TO /home/bfranklin/.ansible/tmp/ansible-tmp-
1510956849.89-176724624375677/virt.py
<localhost> EXEC /bin/sh -c 'chmod u+x 
/home/bfranklin/.ansible/tmp/ansible-tmp-1510956849.89-176724624375677/ 
/home/bfranklin/.ansible/tmp/ansible-tmp-1510956849.89-176724624375677/virt.py 
&& sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python 
/home/bfranklin/.ansible/tmp/ansible-tmp-1510956849.89-176724624375677/virt.py; 
rm -rf 
"/home/bfranklin/.ansible/tmp/ansible-tmp-1510956849.89-176724624375677/" > 
/dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "autostart": null, 
            "command": "status", 
            "name": null, 
            "state": null, 
            "uri": "qemu:///system", 
            "xml": null
        }
    }, 
    "msg": "status requires 1 argument: guest"

It seem to "work" but then how to iterate through my list of guests?

On Friday, November 17, 2017 at 7:24:16 PM UTC-2, Kai Stian Olstad wrote:
>
> On Friday, 17 November 2017 11.55.01 CET Moreno Garcia wrote: 
> > 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. 
>
> Here the virt module is running on localhost. 
>
>
> > 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"} 
>
> Here you are running the virt module on the VM, and the VM is not running 
> KVM the host is. 
>
>
> > 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! => { 
>
> This last line say you are running on server3 an not localhost. 
>
>
> >     "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 need to add delegate_to: localhost  or set connection: local 
>
>
> -- 
> Kai Stian Olstad 
>

-- 
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/4571f958-f2cb-4d38-af0f-11059caa608d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to