Skip to content

Defining VM generates new MAC address on second run but doesnt change the VM. #186

Open
@rujschafer

Description

@rujschafer
SUMMARY

Using community.libvirt.virt to define a new VM from a template with no MAC addresses statically assigned. On first run, everything seems to work fine. The VM gets created. The network interfaces seem good. However on the second run of the playbook, that task says it will update the ethernet address for the VM but looking at the XML from virsh, it didnt change. This renders the task not idempotent. The template didnt change between the two runs.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.libvirt.virt

ANSIBLE VERSION
ansible [core 2.15.8]
  config file = $HOME/ansible.cfg
  configured module search path = ['$HOME/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.11/site-packages/ansible
  ansible collection location = $HOME/collections
  executable location = /usr/local/bin/ansible
  python version = 3.11.2 (main, Sep 12 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True

COLLECTION VERSION
# $HOME/collections/ansible_collections
Collection        Version
----------------- -------
community.libvirt 1.3.1

# /usr/local/lib/python3.11/site-packages/ansible_collections
Collection        Version
----------------- -------
community.libvirt 1.3.0

CONFIGURATION
Here is the generated XML devices stanza for interfaces:
  <!--  Set Network options - New version  -->  
	<interface type='bridge'>
		<source bridge='br1'/>
		<model type='virtio'/>
	</interface>
	<interface type='bridge'>
		<source bridge='br2'/>
		<model type='virtio'/>
	</interface>

OS / ENVIRONMENT

RHEL9.5 running libvirt 10.5.0-7

STEPS TO REPRODUCE

using the XML above I was able to use it with the task:

- name: config_vms | ensure the VM is defined
  community.libvirt.virt:
    command: define
    xml: "{{ lookup('template', vm.xml_file | default('vm-template.xml.RHEL9.j2')) }}"
    uri: "{{ libvirt_vm_uri | default(omit, true) }}"
--- before
+++ after
@@ -34,13 +34,13 @@
     </controller>
     <controller type='pci' index='0' model='pci-root'/>
     <interface type='bridge'>
-      <mac address='52:54:00:cd:fb:e5'/>
+      <mac address='52:54:00:91:19:10'/>
       <source bridge='br1'/>
       <model type='virtio'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
     </interface>
     <interface type='bridge'>
-      <mac address='52:54:00:bf:90:5e'/>
+      <mac address='52:54:00:cc:fb:72'/>
       <source bridge='br2'/>
       <model type='virtio'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
EXPECTED RESULTS

I expected the second run of the playbook to yield idempotency.

ACTUAL RESULTS
from ansible output:
    "ansible_loop_var": "item",
    "change_reason": "domain definition changed",
    "changed": true,
...
    "invocation": {
        "module_args": {
            "autostart": null,
            "command": "define",
            "flags": null,
            "force": null,
            "mutate_flags": [
                "ADD_UUID"
            ],
            "name": null,
            "state": null,
            "uri": "qemu:///system",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions