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

vmware_guest is not allowing MAC customization using 'random_mac' filter if template is having the network attached

Open Udayendu opened this issue 3 years ago • 2 comments

SUMMARY

Newly cloned vms are not having desired MAC via random_mac if the template is attached with a nic. Its taking the MAC from the same prefix as its attached in the template.

ISSUE TYPE
  • Bug Report
COMPONENT NAME
  • vmware_guest
ANSIBLE VERSION
$ pip3 show ansible
Name: ansible
Version: 4.5.0
Summary: Radically simple IT automation
Home-page: https://ansible.com/
Author: Ansible, Inc.
Author-email: [email protected]
License: GPLv3+
Location: /usr/local/lib/python3.8/dist-packages
Requires: ansible-core
Required-by:

$ pip3 show ansible-core
Name: ansible-core
Version: 2.11.4
Summary: Radically simple IT automation
Home-page: https://ansible.com/
Author: Ansible, Inc.
Author-email: [email protected]
License: GPLv3+
Location: /usr/local/lib/python3.8/dist-packages
Requires: packaging, cryptography, PyYAML, jinja2, resolvelib
Required-by: ansible
COLLECTION VERSION
$ ansible-galaxy collection list community.vmware
# /usr/local/lib/python3.8/dist-packages/ansible_collections
Collection       Version
---------------- -------
community.vmware 1.13.0
OS / ENVIRONMENT
  • Ubuntu 20.04 LTS
STEPS TO REPRODUCE
  • Use the below ansible play to deploy a vm from template using vmware_guest module which will have a NIC attached to it.
---
- name: Deploying vm from '{{ win_temp }}'
  vmware_guest:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter: '{{ vsphere_datacenter }}'
    cluster: '{{ vsphere_cluster }}'
    datastore: '{{ vsphere_datastore }}'
    name: '{{ inventory_hostname }}'
    template: '{{ win_temp }}'
    folder: '{{ folder }}'
    validate_certs: 'no'
    networks:
    - name: '{{ Mgmt_network }}'
      ip: "{{ Mgmt_network_ipv4 }}"
      netmask: '{{ Mgmt_network_nmv4 }}'
      gateway: '{{ Mgmt_network_gwv4 }}'
      mac: "{{ '00:0d:1e' | community.general.random_mac(seed=inventory_hostname) }}"
      dns_servers:
        - '{{ dns_server1 }}'
        - '{{ dns_server2 }}'
    state: poweredon
    wait_for_ip_address: yes
    customization:
      hostname: "{{ vsphere_vm_hostname }}"
      dns_suffix: '{{ ad_domain }}'
      domainadmin: '{{ ad_domain_admin }}'
      domainadminpassword: '{{ ad_domain_password }}'
      joindomain: '{{ ad_domain }}'
      timezone: '{{ timezone }}'
    wait_for_customization: yes
  delegate_to: localhost
EXPECTED RESULTS
  • New VM should have a MAC starting with '00:0d:1e'
ACTUAL RESULTS
  • If the template is associated with a NIC having a MAC starting with '00:50:56', then vmware_guest is not creating the MAC starting with '00:0d:1e' but with '00:50:56'.

Udayendu avatar Dec 15 '21 14:12 Udayendu

Only solution is to make a template without a NIC and then vmware_guest is able to attach the nic with correct MAC prefix as expected.

Udayendu avatar Dec 15 '21 14:12 Udayendu

@goneri @Akasurde Can some one take a look into this ? This is an important one as ansible is not able to handle the multiple vms very well with MAC assignment while cloning from a template.

Udayendu avatar Jun 23 '22 11:06 Udayendu