Merge "infra-vm: efficiently handle hostvars during deploy and destroy"

This commit is contained in:
Zuul
2025-01-14 14:03:15 +00:00
committed by Gerrit Code Review
4 changed files with 39 additions and 23 deletions

View File

@@ -4,7 +4,7 @@
include_role: include_role:
name: jriguera.configdrive name: jriguera.configdrive
vars: vars:
configdrive_os_family: "{{ vm_hostvars.infra_vm_os_family }}" configdrive_os_family: "{{ vm_os_family }}"
configdrive_uuid: "{{ vm_name | to_uuid }}" configdrive_uuid: "{{ vm_name | to_uuid }}"
# Must set configdrive_instance_dir when using a loop # Must set configdrive_instance_dir when using a loop
# https://github.com/jriguera/ansible-role-configdrive/blob/8438592c84585c86e62ae07e526d3da53629b377/tasks/main.yml#L17 # https://github.com/jriguera/ansible-role-configdrive/blob/8438592c84585c86e62ae07e526d3da53629b377/tasks/main.yml#L17
@@ -16,13 +16,10 @@
configdrive_volume_path: "{{ image_cache_path }}" configdrive_volume_path: "{{ image_cache_path }}"
configdrive_config_dir_delete: False configdrive_config_dir_delete: False
configdrive_resolv: configdrive_resolv:
domain: "{{ vm_hostvars.resolv_domain | default }}" domain: "{{ vm_resolv_domain | default }}"
search: "{{ vm_hostvars.resolv_search | default }}" search: "{{ vm_resolv_search | default }}"
dns: "{{ vm_hostvars.resolv_nameservers | default([]) }}" dns: "{{ vm_resolv_nameservers | default([]) }}"
configdrive_network_device_list: > configdrive_network_device_list: "{{ vm_network_device_list }}"
{{ vm_hostvars.network_interfaces |
map('net_configdrive_network_device', vm_hostvars.inventory_hostname) |
list }}
- name: "[{{ vm_name }}] Set a fact containing the configdrive image path" - name: "[{{ vm_name }}] Set a fact containing the configdrive image path"
set_fact: set_fact:
@@ -56,7 +53,7 @@
- name: "[{{ vm_name }}] Stat image files" - name: "[{{ vm_name }}] Stat image files"
stat: stat:
path: "{{ image_cache_path }}/{{ item.image | basename }}" path: "{{ image_cache_path }}/{{ item.image | basename }}"
with_items: "{{ vm_hostvars.infra_vm_volumes | selectattr('image', 'defined') }}" with_items: "{{ vm_volumes | selectattr('image', 'defined') }}"
register: image_stat_result register: image_stat_result
- name: "[{{ vm_name }}] Fix image ownership" - name: "[{{ vm_name }}] Fix image ownership"
@@ -75,7 +72,7 @@
vm_configdrive_device: cdrom vm_configdrive_device: cdrom
vm_configdrive_volume: vm_configdrive_volume:
name: "{{ vm_name }}-configdrive" name: "{{ vm_name }}-configdrive"
pool: "{{ vm_hostvars.infra_vm_pool }}" pool: "{{ vm_pool }}"
# Round size up to next multiple of 4096. # Round size up to next multiple of 4096.
capacity: "{{ (stat_result.stat.size + 4095) // 4096 * 4096 }}" capacity: "{{ (stat_result.stat.size + 4095) // 4096 * 4096 }}"
device: "{{ vm_configdrive_device }}" device: "{{ vm_configdrive_device }}"
@@ -85,10 +82,10 @@
libvirt_vm_image_cache_path: "{{ image_cache_path }}" libvirt_vm_image_cache_path: "{{ image_cache_path }}"
libvirt_vms: libvirt_vms:
- name: "{{ vm_name }}" - name: "{{ vm_name }}"
boot_firmware: "{{ vm_hostvars.infra_vm_boot_firmware | default }}" boot_firmware: "{{ vm_boot_firmware | default }}"
machine: "{{ vm_hostvars.infra_vm_machine | default }}" machine: "{{ vm_machine | default }}"
memory_mb: "{{ vm_hostvars.infra_vm_memory_mb }}" memory_mb: "{{ vm_memory_mb }}"
vcpus: "{{ vm_hostvars.infra_vm_vcpus }}" vcpus: "{{ vm_vcpus }}"
volumes: "{{ vm_hostvars.infra_vm_volumes + [vm_configdrive_volume] }}" volumes: "{{ vm_volumes + [vm_configdrive_volume] }}"
interfaces: "{{ vm_hostvars.infra_vm_interfaces }}" interfaces: "{{ vm_interfaces }}"
console_log_enabled: true console_log_enabled: true

View File

@@ -6,12 +6,12 @@
vars: vars:
infra_vm_configdrive_volume: infra_vm_configdrive_volume:
name: "{{ vm_name }}-configdrive" name: "{{ vm_name }}-configdrive"
pool: "{{ hostvars[vm_hostvars.infra_vm_hypervisor].infra_vm_pool }}" pool: "{{ vm_pool }}"
libvirt_vms: libvirt_vms:
- name: "{{ vm_name }}" - name: "{{ vm_name }}"
boot_firmware: "{{ vm_hostvars.infra_vm_boot_firmware | default }}" boot_firmware: "{{ vm_boot_firmware | default }}"
memory_mb: "{{ vm_hostvars.infra_vm_memory_mb }}" memory_mb: "{{ vm_memory_mb }}"
vcpus: "{{ vm_hostvars.infra_vm_vcpus }}" vcpus: "{{ vm_vcpus }}"
volumes: "{{ vm_hostvars.infra_vm_volumes + [infra_vm_configdrive_volume] }}" volumes: "{{ vm_volumes + [infra_vm_configdrive_volume] }}"
state: "absent" state: "absent"
become: True become: True

View File

@@ -10,8 +10,21 @@
- name: "{{ infra_vm_action | capitalize }} infra VMs (loop)" - name: "{{ infra_vm_action | capitalize }} infra VMs (loop)"
include_tasks: "{{ infra_vm_action }}.yml" include_tasks: "{{ infra_vm_action }}.yml"
vars: vars:
vm_name: "{{ vm_hostvars.infra_vm_name }}" vm_name: "{{ hostvars[vm_item].infra_vm_name }}"
vm_hostvars: "{{ hostvars[vm_item] }}" vm_os_family: "{{ hostvars[vm_item].infra_vm_os_family }}"
vm_resolv_domain: "{{ hostvars[vm_item].resolv_domain }}"
vm_resolv_search: "{{ hostvars[vm_item].resolv_search }}"
vm_resolv_nameservers: "{{ hostvars[vm_item].resolv_nameservers }}"
vm_network_device_list: "{{ hostvars[vm_item].network_interfaces |
map('net_configdrive_network_device', hostvars[vm_item].inventory_hostname) |
list }}"
vm_volumes: "{{ hostvars[vm_item].infra_vm_volumes }}"
vm_pool: "{{ hostvars[vm_item].infra_vm_pool }}"
vm_boot_firmware: "{{ hostvars[vm_item].infra_vm_boot_firmware }}"
vm_machine: "{{ hostvars[vm_item].infra_vm_machine }}"
vm_memory_mb: "{{ hostvars[vm_item].infra_vm_memory_mb }}"
vm_vcpus: "{{ hostvars[vm_item].infra_vm_vcpus }}"
vm_interfaces: "{{ hostvars[vm_item].infra_vm_interfaces }}"
loop: "{{ infra_vm_vms }}" loop: "{{ infra_vm_vms }}"
when: (infra_vm_action == "deploy" and vm_name not in all_vms.list_vms) or infra_vm_action == "destroy" when: (infra_vm_action == "deploy" and vm_name not in all_vms.list_vms) or infra_vm_action == "destroy"
loop_control: loop_control:

View File

@@ -0,0 +1,6 @@
---
features:
- |
Deploying and destroying infrastructure VMs is now significantly faster
as only the required variables are passed to the relevant tasks as opposed
to the entire collection of hostvars for each VM.