When replacing a VM with another VM, we would like to gather the MAC address of the old VM, delete that VM, create a new VM, and re-use the MAC address for the new VM.
The playbook happily creates a new VM but it will not customize the MAC address. We took a step back and tried just updating the MAC address on an existing VM, using a hardcoded MAC address instead of trying to pick up a variable and setting state
to present
so the VM won’t be powered on. The task succeeds, but we still don’t get the MAC address we want.
If I run it with -v
, the output of the task clearly shows the automatically-assigned MAC address:
{
"changed": true,
"instance": {
"module_hw": true,
"hw_name": "my-test",
"hw_power_status": "poweredOff",
. . .
"hw_processor_count": 2,
"hw_cores_per_socket": 1,
"hw_memtotal_mb": 8192,
"hw_interfaces": [
"eth0"
],
. . .
"hw_eth0": {
"addresstype": "assigned",
"label": "Network adapter 1",
"macaddress": "00:33:44:uv:wx:yz", # redacted, not a real MAC address
"ipaddresses": null,
"summary": "Virtual Machine Network",
},
Even though the invocation clearly shows the MAC address we want to apply:
"invocation": {
"module_args": {
"hostname": "redacted",
"username": "redacted",
. . .
"name": "my-test",
"state": "present",
. . .
}
],
"networks": [
{
"name": "Our Fancy Network",
"mac": "00:11:22:ab:cd:ef", # redacted, not a real MAC address, but not the same as the one above
"type": "dhcp"
}
],
If I manually log into vSphere I have to open Edit Settings, then change from Automatic
to Manual
in the Network section before I can update the MAC address - is there an equivalent flag in the Ansible module I need to set?
I hope someone out there has pointers for me!
Thanks!