Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update of libvirt network default fails #47

Open
simsiem opened this issue Oct 30, 2020 · 4 comments
Open

Update of libvirt network default fails #47

simsiem opened this issue Oct 30, 2020 · 4 comments

Comments

@simsiem
Copy link

simsiem commented Oct 30, 2020

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
Copy link
Author

simsiem commented Nov 1, 2020

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

if command in ('define', 'modify'):
if not xml:
module.fail_json(msg=command + " requires xml argument")
try:
v.get_net(name)
except EntryNotFound:
v.define(name, xml)
res = {'changed': True, 'created': name}
else:
if command == 'modify':
mod = v.modify(name, xml)
res = {'changed': mod, 'modified': name}
return VIRT_SUCCESS, res

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'.

elif state in ['present']:
try:
v.get_net(name)
except EntryNotFound:
if not xml:
module.fail_json(msg="network '" + name + "' not present, but xml not specified")
v.define(name, xml)
res = {'changed': True, 'created': name}

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.

@odyssey4me
Copy link
Collaborator

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.

@moll
Copy link

moll commented Mar 10, 2022

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).

@imThief
Copy link

imThief commented Apr 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants