Files
vmn-ansible/roles/deploy_vm_on_proxmox/tasks/main.yaml
T

26 lines
722 B
YAML

---
- name: Check if VM already exists
community.proxmox.proxmox_kvm:
validate_certs: false
node: proxmox-server
api_user: root@pam
api_host: proxmox_1_host
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
ansible.builtin.include_tasks: create_vm.yaml
- name: Start the VM only if needed
when: '"does not exist in cluster" in vm_status.msg or vm_status.status != "running"'
ansible.builtin.include_tasks: start_vm.yaml