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

Get VM primary mac address after VM power on #529

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions common/vm_get_vm_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
vm_hardware_version_num: "{{ vm_config.config.version.split('-')[-1] }}"
vm_firmware: "{{ vm_config.config.firmware }}"

- name: "Wait for mac address is available"
include_tasks: vm_wait_primary_nic_mac.yml

- name: "Display VM's basic information"
ansible.builtin.debug:
msg:
Expand Down
11 changes: 7 additions & 4 deletions common/vm_wait_primary_nic_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
- gather_network_facts.network_data['0'].mac_addr is defined
- gather_network_facts.network_data['0'].mac_addr

- name: "Display VM's primary network adapter MAC address"
ansible.builtin.debug:
msg:
- "VM primary network adapter MAC address: {{ vm_primary_nic_mac }}"
- name: "Assert VM primary network adapter has MAC address"
ansible.builtin.assert:
that:
- vm_primary_nic_mac
keirazhang marked this conversation as resolved.
Show resolved Hide resolved
- vm_primary_nic_mac | ansible.utils.hwaddr
fail_msg: "VM primary network adapter has No MAC address"
success_msg: "VM primary network adapter MAC address is {{ vm_primary_nic_mac }}"
12 changes: 12 additions & 0 deletions env_setup/env_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@

- name: "Get existing VM info"
include_tasks: ../common/vm_get_vm_info.yml

- name: "Get VM's power state"
include_tasks: ../common/vm_get_power_state.yml

- name: "Power on VM"
include_tasks: ../common/vm_set_power_state.yml
vars:
vm_power_state_set: "powered-on"
when: vm_power_state_get == "poweredOff"

- name: "Wait for VM primary network adapter has MAC address"
include_tasks: ../common/vm_wait_primary_nic_mac.yml
when: vm_exists is defined and vm_exists

- name: Set fact of the VM datastore path
Expand Down
5 changes: 5 additions & 0 deletions linux/deploy_vm/deploy_vm_from_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@
vars:
vm_take_screenshot_local_path: "{{ current_test_log_folder }}"

# For only ESXi managed VM, its MAC address is generated after power on
# not at VM creation
- name: "Get VM's primary network adapter MAC address"
include_tasks: ../../common/vm_wait_primary_nic_mac.yml

# VMware Photon OS kickstart file can't add shutdown action,
# so here needs to shutdown it separately
- name: "Shutdown VMware Photon OS VM after auto install completes"
Expand Down
3 changes: 3 additions & 0 deletions linux/deploy_vm/deploy_vm_from_ova.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
- name: "Add a serial port for VM"
include_tasks: ../../common/vm_add_serial_port.yml

- name: "Get VM's primary network adapter MAC address"
include_tasks: ../../common/vm_wait_primary_nic_mac.yml

- name: "Reconfigure VM with cloud-init"
include_tasks: reconfigure_vm_with_cloudinit.yml
when: ova_guest_os_type in ['photon', 'ubuntu', 'amazon']
Expand Down
1 change: 0 additions & 1 deletion windows/deploy_vm/deploy_vm_from_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@

- name: "Get VM's primary network adapter MAC address after poweron VM"
include_tasks: ../../common/vm_wait_primary_nic_mac.yml
when: vm_primary_nic_mac is undefined or not vm_primary_nic_mac

- name: "Get VM IP address"
include_tasks: ../../common/vm_get_ip.yml
Expand Down
3 changes: 3 additions & 0 deletions windows/deploy_vm/deploy_vm_from_ova.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@

- name: "Get VM info"
include_tasks: ../../common/vm_get_vm_info.yml

#- name: "Get VM's primary network adapter MAC address"
keirazhang marked this conversation as resolved.
Show resolved Hide resolved
# include_tasks: ../../common/vm_wait_primary_nic_mac.yml
# - include_tasks: ../../common/vm_get_ip_from_vmtools.yml

# Copy script ConfigureRemotingForAnsible.ps1 to guest OS
Expand Down