Score:0

Deploying VM from VM template on vmware vCenter with Ansible makes network unreachable

cn flag

OS: Oracle Linux 8.7 vCenter: 7.0.3 build 20051473 hypervisor: VMware ESXi, 7.0.3, 19193900 ansible-playbook [core 2.13.5] python version = 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0] jinja version = 3.1.2 libyaml = True

I'm deploying a VM from a template using the following Ansible task:

- name: Create a new virtual machine {{ hostname }} on vCenter {{ vcenter_hostname }} from template {{ source_template }}
  community.vmware.vmware_guest:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    validate_certs: false
    datacenter: "{{ datacenter_name }}"
    folder: /{{ datacenter_name }}/vm/
    name: "{{ hostname }}"
    state: present
    template: "{{ source_template }}"
    esxi_hostname: "{{ esxi_hostname }}"
    disk:
      - size_gb: "{{ size_disk }}"
        type: "{{ disk_type }}"
        datastore: "{{ datastore_name }}"
    hardware:
      memory_mb: "{{ memory }}"
      memory_reservation_lock: true
      num_cpus: "{{ vcpu }}"
      cpu_reservation: "{{ reserved_cpu }}"
      scsi: paravirtual
      nested_virt: true
    networks:
    - name: VM Network
      ip: "{{ ip_address }}"
      netmask: "{{ ip_netmask }}"
      gateway: "{{ default_gateway }}"
      device_type: vmxnet3
      type: static
      state: present
    customization:
      dns_servers:
        - "{{ dns_1 }}"
        - "{{ dns_2 }}"
    wait_for_ip_address: true
  delegate_to: localhost
  register: deploy_vm

after deploying the VM, the ansible playbook cannot continue with following tasks:

fatal: [template-common]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.24.76.35 port 22: Connection refused", "unreachable": true}

I accessed the VM and I noticed that it is not able to reach the network. I solved it removing the MAC address from Address field, via nmtui:

nmtui interface

However, if I do this in the VM template when I deploy the VM from it I have the same issue. even the mac address is correct.

I also tried:

  • Removing HWADDR parameter from /etc/sysconfig/network-scripts/ifcfg-ens192
  • Removing /etc/udev/rules.d/70.persistent-ipoib.rules
  • Removing the network adapter before converting the source VM to a VM template

With all those modifications the VM created from VM template is still unable use the interface.

I would like to highlight that even the mac address is well set in HWADDR parameter and in the interface shown by nmtui command (as displayed above) the network interface won't work until I remove the mac address from nmtui config.

Is there a way to prevent the mac address being written in nmtui automatically?

Any other solutions or configurations are valid, the only requirement is that the deployed VM has a working interface without any extra interaction.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.