ansible-collections / community.libvirt

Manage libvirt with Ansible
http://galaxy.ansible.com/community/libvirt
GNU General Public License v3.0
61 stars 42 forks source link

list_nets and facts commands from virt_net do not work as listed in examples #49

Closed guidugli closed 3 years ago

guidugli commented 3 years ago
SUMMARY

Both examples using list_nets and facts return with error: missing required arguments: name Specifying a name makes the example work, but these commands become quite useless.

Seems to be something simple to fix but I am not familiar with Ansible development. I believe the problem is related to line 605 of virt_net.py, but not sure.

ISSUE TYPE
COMPONENT NAME

community.libvirt.virt_net

ANSIBLE VERSION
ansible 2.9.14
  config file = /root/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.7.9 (default, Aug 19 2020, 17:05:11) [GCC 9.3.1 20200408 (Red Hat 9.3.1-2)]
CONFIGURATION
ANSIBLE_PIPELINING(/root/ansible/ansible.cfg) = True
COLLECTIONS_PATHS(/root/ansible/ansible.cfg) = ['/root/ansible']
DEFAULT_HOST_LIST(/root/ansible/ansible.cfg) = ['/root/ansible/inventory']
DEFAULT_ROLES_PATH(/root/ansible/ansible.cfg) = ['/root/ansible/roles']
OS / ENVIRONMENT

Fedora release 31

STEPS TO REPRODUCE
- name: Test playbook
  hosts: localhost
  tasks:

    - name: list nets
      community.libvirt.virt_net:
        command: list_nets
      register: result
      ignore_errors: yes

    - debug: var=result

    - name: facts
      community.libvirt.virt_net:
        command: facts
      register: result
      ignore_errors: yes

    - debug: var=result
EXPECTED RESULTS

Expecting receiving information of all libvirt networks.

ACTUAL RESULTS

These commands are requiring name argument.

PLAYBOOK: p.yml *****************************************************************************************************************************************************************************************************************
1 plays in p.yml

PLAY [Test playbook] ************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************
task path: /root/ansible/p.yml:2
Using module file /usr/lib/python3.7/site-packages/ansible/modules/system/setup.py
Pipelining is enabled.
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 && sleep 0'
ok: [localhost]
META: ran handlers

TASK [list nets] ****************************************************************************************************************************************************************************************************************
task path: /root/ansible/p.yml:12
Using module file /root/ansible/ansible_collections/community/libvirt/plugins/modules/virt_net.py
Pipelining is enabled.
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 && sleep 0'
The full traceback is:
  File "/tmp/ansible_community.libvirt.virt_net_payload_nc1t_aa4/ansible_community.libvirt.virt_net_payload.zip/ansible/module_utils/basic.py", line 1655, in _check_required_arguments
    check_required_arguments(spec, param)
  File "/tmp/ansible_community.libvirt.virt_net_payload_nc1t_aa4/ansible_community.libvirt.virt_net_payload.zip/ansible/module_utils/common/validation.py", line 193, in check_required_arguments
    raise TypeError(to_native(msg))
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "command": "list_nets",
            "uri": "qemu:///system"
        }
    },
    "msg": "missing required arguments: name"
}
...ignoring

TASK [debug] ********************************************************************************************************************************************************************************************************************
task path: /root/ansible/p.yml:18
ok: [localhost] => {
    "result": {
        "changed": false,
        "exception": "  File \"/tmp/ansible_community.libvirt.virt_net_payload_nc1t_aa4/ansible_community.libvirt.virt_net_payload.zip/ansible/module_utils/basic.py\", line 1655, in _check_required_arguments\n    check_required_arguments(spec, param)\n  File \"/tmp/ansible_community.libvirt.virt_net_payload_nc1t_aa4/ansible_community.libvirt.virt_net_payload.zip/ansible/module_utils/common/validation.py\", line 193, in check_required_arguments\n    raise TypeError(to_native(msg))\n",
        "failed": true,
        "msg": "missing required arguments: name"
    }
}

TASK [facts] ********************************************************************************************************************************************************************************************************************
task path: /root/ansible/p.yml:20
Using module file /root/ansible/ansible_collections/community/libvirt/plugins/modules/virt_net.py
Pipelining is enabled.
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 && sleep 0'
The full traceback is:
  File "/tmp/ansible_community.libvirt.virt_net_payload_mdgxaa3j/ansible_community.libvirt.virt_net_payload.zip/ansible/module_utils/basic.py", line 1655, in _check_required_arguments
    check_required_arguments(spec, param)
  File "/tmp/ansible_community.libvirt.virt_net_payload_mdgxaa3j/ansible_community.libvirt.virt_net_payload.zip/ansible/module_utils/common/validation.py", line 193, in check_required_arguments
    raise TypeError(to_native(msg))
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "command": "facts",
            "uri": "qemu:///system"
        }
    },
    "msg": "missing required arguments: name"
}
...ignoring

TASK [debug] ********************************************************************************************************************************************************************************************************************
task path: /root/ansible/p.yml:26
ok: [localhost] => {
    "result": {
        "changed": false,
        "exception": "  File \"/tmp/ansible_community.libvirt.virt_net_payload_mdgxaa3j/ansible_community.libvirt.virt_net_payload.zip/ansible/module_utils/basic.py\", line 1655, in _check_required_arguments\n    check_required_arguments(spec, param)\n  File \"/tmp/ansible_community.libvirt.virt_net_payload_mdgxaa3j/ansible_community.libvirt.virt_net_payload.zip/ansible/module_utils/common/validation.py\", line 193, in check_required_arguments\n    raise TypeError(to_native(msg))\n",
        "failed": true,
        "msg": "missing required arguments: name"
    }
}
tylerauerbeck commented 3 years ago

Could this just be because of the following line in virt_net.py?

https://github.com/ansible-collections/community.libvirt/blob/2185098fbb3851a107793909e7ff4d501d013829/plugins/modules/virt_net.py#L605

Happy to PR a change for this. I'm assuming the name attribute should be required for a majority of commands -- but perhaps just not these. So maybe we could do something like default the value to "" and then catch for that elsewhere?