From b32dbe3400f5df390daebd8dab9787937c50aced Mon Sep 17 00:00:00 2001 From: Maxim Vershinin Date: Fri, 14 Aug 2026 16:31:38 +0400 Subject: [PATCH] FEATURE: adds idempotency to vm creation in roles/deploy_vm_on_proxmox/tasks/main.yaml --- roles/deploy_vm_on_proxmox/tasks/main.yaml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/roles/deploy_vm_on_proxmox/tasks/main.yaml b/roles/deploy_vm_on_proxmox/tasks/main.yaml index a451dee..5cce14f 100644 --- a/roles/deploy_vm_on_proxmox/tasks/main.yaml +++ b/roles/deploy_vm_on_proxmox/tasks/main.yaml @@ -1,5 +1,22 @@ --- -- name: Create a new VM with minimal options + +- name: Check if VM already exists + community.proxmox.proxmox_kvm: + validate_certs: false + node: proxmox-server + api_user: root@pam + api_host: 192.168.0.2 + api_token_id: ansible + api_token_secret: "{{ proxmox_token_secret }}" + + name: "{{ vm_hostname }}" + state: current + ignore_errors: true + register: vm_status + + +- name: Create a new VM with minimal options only if it doesn't exist + when: vm_status is failed or 'does not exist in cluster' in vm_status.msg become: false community.proxmox.proxmox_kvm: validate_certs: false @@ -77,7 +94,7 @@ name: "{{ vm_hostname }}" state: started -- name: Sleep for 2 minutes to make sure that VM has started and cloud init has done its thing +- name: Sleep for 120 seconds just to make sure that all settings are applied become: false ansible.builtin.wait_for: timeout: 120