Skip to content
Closed
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
31 changes: 11 additions & 20 deletions playbooks/utils/replace_vm_host.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# Optional; not used for disk shape, but can be helpful for visibility
# since we have different sizes and controllers it helps with output
- name: Gather disk info on VM to replace (optional)
community.vmware.vmware_guest_disk:
community.vmware.vmware_guest_disk_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
Expand All @@ -51,8 +51,8 @@

- name: Debug disk info structure (optional)
debug:
var: old_vm_disk_info
when: old_vm_disk_info is defined
var: old_vm_disk_info.guest_disk_info
when: old_vm_disk_info is defined and old_vm_disk_info.guest_disk_info is defined

# Compute DNS domain / FQDN
- name: Derive DNS domain from old guest_name (fallback to lib.princeton.edu)
Expand Down Expand Up @@ -133,8 +133,6 @@
{%- set controller_type = 'nvme' if 'nvme' in (device.backing._vimtype | default('') | lower) else 'paravirtual' -%}
{%- set _ = disks.append({
'size_gb': disk_size_gb,
'controller_type': controller_type,
'controller_number': 0,
'unit_number': unit_num,
'datastore': vm_datastore_name
}) -%}
Expand All @@ -145,9 +143,6 @@
{%- set disk_size_gb = (total_storage_kb / 1024 / 1024) | round(0, 'ceil') | int -%}
{%- set _ = disks.append({
'size_gb': disk_size_gb,
'controller_type': 'paravirtual',
'controller_number': 0,
'unit_number': 0,
'datastore': vm_datastore_name
}) -%}
{%- endif -%}
Expand All @@ -158,7 +153,7 @@
msg:
- "Number of disks to create: {{ vm_disk_config | length }}"
- "Disk configuration:"
- "{% for disk in vm_disk_config %} Disk {{ loop.index }}: {{ disk.size_gb }}GB on unit {{ disk.unit_number }} ({{ disk.controller_type }}){% endfor %}"
- "{% for disk in vm_disk_config %} Disk {{ loop.index }}: {{ disk.size_gb }}GB on unit {{ disk.unit_number }} {% endfor %}"

- name: Print out warning
ansible.builtin.debug:
Expand Down Expand Up @@ -214,19 +209,15 @@
memory_mb: "{{ old_vm_info.virtual_machines[0].allocated.memory | int | default(16384) }}"
num_cpus: "{{ old_vm_info.virtual_machines[0].allocated.cpu | int | default(2) }}"
num_cpu_cores_per_socket: "{{ vm_cpu_cores | default(1) }}"
scsi: paravirtual
version: latest # Hardware version of virtual machine
boot_firmware: "efi"
cdrom:
- controller_number: 0
unit_number: 0
state: present
networks:
- connected: true
name: "{{ old_vm_net_info.network_info[0].network_name }}"
mac: "{{ old_vm_net_info.network_info[0].mac_address }}"
wait_for_ip_address: true
wait_for_ip_address_timeout: 120
register: new_vm_info

- name: Print out relevant details of old VM
vars:
Expand All @@ -243,15 +234,15 @@
ansible.builtin.debug:
msg: "{{ msg.split('\n') }}"

- name: Gather details on new VM
community.vmware.vmware_vm_info:
- name: Gather disk info on new VM
community.vmware.vmware_guest_disk_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
show_allocated: true
vm_name: "{{ replacement_vm }}"
register: new_vm_info
datacenter: "{{ vcenter_datacenter }}"
name: "{{ replacement_vm }}"
register: new_vm_disk_info

- name: Gather network info new VM
community.vmware.vmware_guest_network:
Expand Down Expand Up @@ -578,7 +569,7 @@
- Memory: {{ (new_vm_info.virtual_machines[0].allocated.memory | int / 1024) }}GB
- Disks: {{ vm_disk_config | length }}
{% for disk in vm_disk_config %}
- Disk {{ loop.index }}: {{ disk.size_gb }}GB ({{ disk.controller_type }})
- Disk {{ loop.index }}: {{ disk.size_gb }}GB
{% endfor %}

POST-CREATION TASKS:
Expand Down