community.libvirt icon indicating copy to clipboard operation
community.libvirt copied to clipboard

Update of libvirt network default fails

Open simsiem opened this issue 5 years ago • 5 comments

SUMMARY

I want to update the default network of libvirt (purpose: add IPv6). Ansible reports that no change is necessary: ok: [localhost], although the XML definition is different from what I get from sudo virsh net-dumpxml default.

If I change the name in the ansible code but not in the XML definition, the default network gets updated as wanted.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.libvirt.virt_net

ANSIBLE VERSION
ansible 2.9.13
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/walter/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.5 (default, Aug 12 2020, 00:00:00) [GCC 10.2.1 20200723 (Red Hat 10.2.1-1)]
CONFIGURATION
empty output, no change.
OS / ENVIRONMENT

Fedora 32 (Workstation Edition)

STEPS TO REPRODUCE

(1) Create a new file network_default.xml with the current XML definition of the default network.

sudo virsh net-dumpxml default

Modify the file.

(2) Run an ansible playbook containing the tasks:

    - name: Network default is inactive
      community.libvirt.virt_net:
        state: inactive
        name: default
    - name: Default network defined correctly
      community.libvirt.virt_net:
        command: define
        name: default
        xml: '{{ lookup("template", "network_default.xml") }}'

Ansible reports that no change is necessary: ok: [localhost], although the XML definition is different from what I get from sudo virsh net-dumpxml default.

(3) Change the name of the network in the playbook but not in the network_default.xml.

    - name: Network default is inactive
      community.libvirt.virt_net:
        state: inactive
        name: default
    - name: Default network defined correctly
      community.libvirt.virt_net:
        command: define
        name: xyz
        xml: '{{ lookup("template", "network_default.xml") }}'

The default network gets updated as wanted. sudo virsh net-dumpxml default shows the change.

EXPECTED RESULTS
  • Ansible can update the network default.
  • Most likely the network name should not be necessary in the playbook as it is already given in the XML file for the network definition.

simsiem avatar Oct 30 '20 08:10 simsiem

I analysed the code. The root cause is in the following snipped.

https://github.com/ansible-collections/community.libvirt/blob/0e7873a9e167617969f5d2673daef770632df39e/plugins/modules/virt_net.py#L552-L564

A playbook define command is only executed, if the network does not exist. It cannot overwrite an existing network definition. This is different to the define command in virt for domains.

The same logic is implemented for state == 'present'.

https://github.com/ansible-collections/community.libvirt/blob/0e7873a9e167617969f5d2673daef770632df39e/plugins/modules/virt_net.py#L522-L529

Since the documentation is very sparse, I am not sure whether this is defined behaviour or not.

I would propose a patch, when I clarified the target behaviour. At the moment, I am not sure with whom to clarify it.

simsiem avatar Nov 01 '20 17:11 simsiem

Looking at the definitions in the libvirt API:

  • Define creates/updates a persistant entity, but does not start it.
  • Create creates a non-persistant entity.

There is no 'modify' in libvirt - so that is legacy in this module from my point of view and I'd rather see that become an alias for 'define' than carry extra unnecessary logic. I haven't done a good look through the effects of this suggestion, so please do that if you can.

odyssey4me avatar Nov 02 '20 12:11 odyssey4me

I'm experiencing the same problem. Interestingly enough, redefining default with virsh net-define --file ./net.xml does update the stored network configuration (as visible in /etc/libvirt/qemu/networks/default.xml), so I presume if this Ansible plugin did the same, that'd be better than nothing. The fact that it doesn't update the running instance, I read, is by design (https://serverfault.com/questions/571795/why-i-cant-save-network-changes-with-virsh).

moll avatar Mar 10 '22 18:03 moll

Same problem for me, but not for default network only - just for any network. Still no updates/plans since 2020?

Collection        Version
----------------- -------
community.libvirt 1.3.0

imThief avatar Apr 05 '24 01:04 imThief