Files
kayobe/ansible/roles/infra-vms/tasks/main.yml
Jack Hodgkiss 0137015e6c infra-vm: efficiently handle hostvars during deploy and destroy
Pass only the required variables from `hostvars` for a given infra vm to
significantly reduce wait time during `kayobe infra vm provision` and
`kayobe infra vm deprovision`. Time to create and destroy a VM now take
a minute or less.

Closes-Bug: #2093255
Change-Id: I15d17f45d15c04aced0a4c0fe97e1d798ff46799
2025-01-10 13:44:40 +00:00

32 lines
1.3 KiB
YAML

---
- import_tasks: prerequisites.yml
- name: list all VMs on hypervisor
virt:
command: list_vms
register: all_vms
become: true
- name: "{{ infra_vm_action | capitalize }} infra VMs (loop)"
include_tasks: "{{ infra_vm_action }}.yml"
vars:
vm_name: "{{ hostvars[vm_item].infra_vm_name }}"
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 }}"
when: (infra_vm_action == "deploy" and vm_name not in all_vms.list_vms) or infra_vm_action == "destroy"
loop_control:
loop_var: vm_item