Files
ansible_proxmox_VM/tasks/create-vm.yml
Jose f62750fe2f feat: Implement Debian VM template creation and cloning on Proxmox
- Added default configuration for VM creation in defaults/main.yml.
- Created tasks for configuring the VM with UEFI, TPM, disks, GPU, and Cloud-Init in tasks/configure-vm.yml.
- Implemented clone creation and configuration logic in tasks/create-clones.yml.
- Added template conversion functionality in tasks/create-template.yml.
- Developed base VM creation logic in tasks/create-vm.yml.
- Included image download and caching tasks in tasks/download-image.yml.
- Introduced utility tasks for common operations in tasks/helpers.yml.
- Organized main orchestration logic in tasks/main.yml, with clear stages for each operation.
- Added pre-flight checks to validate the environment before execution in tasks/preflight-checks.yml.
2025-11-15 17:22:21 +01:00

47 lines
1.2 KiB
YAML

---
# create-vm.yml - Create base VM on Proxmox
- name: "[VM] Check if VM already exists"
stat:
path: "/etc/pve/qemu-server/{{ vm_id }}.conf"
register: vm_conf
changed_when: false
- name: "[VM] Display VM status"
debug:
msg: "VM {{ vm_id }} ({{ hostname }}) - Status: {{ 'ALREADY EXISTS' if vm_conf.stat.exists else 'WILL BE CREATED' }}"
- name: "[VM] Create base VM"
command: >
qm create {{ vm_id }}
--name {{ hostname }}
--memory {{ memory }}
--cores {{ cores }}
--cpu {{ cpu_type }}
--net0 virtio,bridge={{ bridge }},macaddr={{ mac_address }}
--agent 1
register: vm_create
when: not vm_conf.stat.exists
changed_when: vm_create.rc == 0
- name: "[VM] Handle VM creation error"
fail:
msg: |
Failed to create VM {{ vm_id }}:
{{ vm_create.stderr | default('No error message') }}
when:
- not vm_conf.stat.exists
- vm_create is failed
- name: "[VM] Verify VM was created"
stat:
path: "/etc/pve/qemu-server/{{ vm_id }}.conf"
register: vm_conf_verify
changed_when: false
failed_when: not vm_conf_verify.stat.exists
- name: "[VM] Display VM creation result"
debug:
msg: "✓ VM {{ vm_id }} created successfully"
when: not vm_conf.stat.exists