refactor ♻️: Refactored playbook to improve readability and maintainability

Simplified the playbook structure by removing unnecessary tasks and adding comments for clarity. Also, added a rescue block to handle potential errors during execution.
This commit is contained in:
2025-11-15 19:18:45 +01:00
parent c204a0a3b7
commit ec2b3b7edc

View File

@@ -8,12 +8,6 @@
# 5. Clone creation & deployment
- name: "Create Debian VM template and deploy clones on Proxmox"
hosts: localhost
become: true
gather_facts: false
pre_tasks:
- name: "Display playbook banner"
debug:
msg: |
╔════════════════════════════════════════════════════════════╗
@@ -23,53 +17,52 @@
║ CPU: {{ cores }} cores | RAM: {{ memory }}MB ║
╚════════════════════════════════════════════════════════════╝
tasks:
##################################################################
# 1. PREFLIGHT CHECKS
##################################################################
- name: "STAGE 1: Run pre-flight environment checks"
##################################################################
# 1. PREFLIGHT CHECKS
##################################################################
- name: "STAGE 1: Run pre-flight environment checks"
include_tasks: preflight-checks.yml
tags: [preflight, always]
run_once: true
##################################################################
# 2. DOWNLOAD IMAGE
##################################################################
- name: "STAGE 2: Download and cache Debian GenericCloud image"
##################################################################
# 2. DOWNLOAD IMAGE
##################################################################
- name: "STAGE 2: Download and cache Debian GenericCloud image"
include_tasks: download-image.yml
tags: [image, always]
##################################################################
# 3. CREATE VM
##################################################################
- name: "STAGE 3: Create base VM"
##################################################################
# 3. CREATE VM
##################################################################
- name: "STAGE 3: Create base VM"
include_tasks: create-vm.yml
tags: [vm, create]
##################################################################
# 4. CONFIGURE VM (Disk, Cloud-Init, GPU, TPM, etc.)
##################################################################
- name: "STAGE 4: Configure VM (disk, Cloud-Init, optional features)"
##################################################################
# 4. CONFIGURE VM (Disk, Cloud-Init, GPU, TPM, etc.)
##################################################################
- name: "STAGE 4: Configure VM (disk, Cloud-Init, optional features)"
include_tasks: configure-vm.yml
tags: [vm, configure, cloudinit]
##################################################################
# 5. CREATE TEMPLATE
##################################################################
- name: "STAGE 5: Convert VM to template"
##################################################################
# 5. CREATE TEMPLATE
##################################################################
- name: "STAGE 5: Convert VM to template"
include_tasks: create-template.yml
tags: [template, create]
when: make_template | default(false)
##################################################################
# 6. CREATE CLONES
##################################################################
- name: "STAGE 6: Create and configure clones"
##################################################################
# 6. CREATE CLONES
##################################################################
- name: "STAGE 6: Create and configure clones"
include_tasks: create-clones.yml
tags: [clones, create]
when: create_clones | default(false)
post_tasks:
- name: "Display completion summary"
- name: "Display completion summary"
debug:
msg: |
╔════════════════════════════════════════════════════════════╗
@@ -86,10 +79,10 @@
║ ║
╚════════════════════════════════════════════════════════════╝
rescue:
- name: "Handle playbook errors"
debug:
msg: |
✗ Playbook execution failed
Check the error messages above for details.
You may need to manually clean up partially created VMs.
# rescue:
# - name: "Handle playbook errors"
# debug:
# msg: |
# ✗ Playbook execution failed
# Check the error messages above for details.
# You may need to manually clean up partially created VMs.