From ea19d544801fe3eea1c59947568b2e42375dadaa Mon Sep 17 00:00:00 2001 From: Evgenii D Date: Tue, 9 Apr 2024 15:20:36 +0500 Subject: [PATCH] Shutting down VMs done asynchronously: Send shutdown command to all VMs simultaneously and wait until they finish. If there are a lot of VMs in the cluster, this can help to speed up the shutdown proccess: for 50 VMs infrastructure it takes 3 minutes instead of 40. --- roles/shutdown_env/tasks/main.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/roles/shutdown_env/tasks/main.yml b/roles/shutdown_env/tasks/main.yml index 8b6db1e6..ca728665 100644 --- a/roles/shutdown_env/tasks/main.yml +++ b/roles/shutdown_env/tasks/main.yml @@ -104,8 +104,20 @@ when: "item.origin != 'managed_hosted_engine'" with_items: - "{{ vm_result.ovirt_vms }}" + async: 300 + poll: 0 + register: _alias_vmshutdown_0 failed_when: false + - name: Wait for all VMs to shutdown + async_status: + jid: "{{ item.ansible_job_id }}" + register: _jobs_alias_vmshutdown_0 + retries: 60 + delay: 5 + until: _jobs_alias_vmshutdown_0.finished + loop: "{{_alias_vmshutdown_0.results}}" + - name: Refresh VM list ovirt_vm_info: auth: "{{ ovirt_auth }}" @@ -122,6 +134,18 @@ when: "item.origin != 'managed_hosted_engine' and item.status != 'down'" with_items: - "{{ vm_result.ovirt_vms }}" + async: 300 + poll: 0 + register: _alias_vmshutdown_1 + + - name: Wait for all remaining VMs to shutdown + async_status: + jid: "{{ item.ansible_job_id }}" + register: _jobs_alias_vmshutdown_1 + retries: 60 + delay: 5 + until: _jobs_alias_vmshutdown_1.finished + loop: "{{_alias_vmshutdown_1.results}}" - name: Shutdown hosts, except HE ones, via IPMI (if configured) ovirt_host: