89 lines
4.4 KiB
YAML
89 lines
4.4 KiB
YAML
---
|
|
# main.yml - Orchestrate Debian VM template creation and cloning on Proxmox
|
|
# This playbook handles:
|
|
# 1. Pre-flight checks (environment validation)
|
|
# 2. Image download & caching
|
|
# 3. VM creation & configuration
|
|
# 4. Template conversion
|
|
# 5. Clone creation & deployment
|
|
|
|
- name: "Create Debian VM template and deploy clones on Proxmox"
|
|
ansible.builtin.debug:
|
|
msg: |
|
|
╔════════════════════════════════════════════════════════════╗
|
|
║ Proxmox VM Template & Clone Manager ║
|
|
║ Template VM: {{ hostname }} (ID: {{ vm_id }}) ║
|
|
║ Storage: {{ storage }} ║
|
|
║ CPU: {{ cores }} cores | RAM: {{ memory }}MB ║
|
|
╚════════════════════════════════════════════════════════════╝
|
|
|
|
##################################################################
|
|
# 1. PREFLIGHT CHECKS
|
|
##################################################################
|
|
- name: "STAGE 1: Run pre-flight environment checks"
|
|
ansible.builtin.include_tasks: preflight-checks.yml
|
|
tags: [preflight, always]
|
|
run_once: true
|
|
|
|
##################################################################
|
|
# 2. DOWNLOAD IMAGE
|
|
##################################################################
|
|
- name: "STAGE 2: Download and cache Debian GenericCloud image"
|
|
ansible.builtin.include_tasks: download-image.yml
|
|
tags: [image, always]
|
|
|
|
##################################################################
|
|
# 3. CREATE VM
|
|
##################################################################
|
|
- name: "STAGE 3: Create base VM"
|
|
ansible.builtin.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)"
|
|
ansible.builtin.include_tasks: configure-vm.yml
|
|
tags: [vm, configure, cloudinit]
|
|
|
|
##################################################################
|
|
# 5. CREATE TEMPLATE
|
|
##################################################################
|
|
- name: "STAGE 5: Convert VM to template"
|
|
ansible.builtin.include_tasks: create-template.yml
|
|
tags: [template, create]
|
|
when: make_template | default(false)
|
|
|
|
##################################################################
|
|
# 6. CREATE CLONES
|
|
##################################################################
|
|
- name: "STAGE 6: Create and configure clones"
|
|
ansible.builtin.include_tasks: create-clones.yml
|
|
tags: [clones, create]
|
|
when: create_clones | default(false)
|
|
|
|
- name: "Display completion summary"
|
|
ansible.builtin.debug:
|
|
msg: |
|
|
╔════════════════════════════════════════════════════════════╗
|
|
║ ✓ Playbook execution completed ║
|
|
║ ║
|
|
║ Template VM: {{ hostname }} (ID: {{ vm_id }}) ║
|
|
│ {% if make_template %}✓ Converted to template{% else %}✗ Template conversion disabled{% endif %}
|
|
│ {% if create_clones and clones %}✓ {{ clones | length }} clone(s) created{% else %}✗ Clone creation disabled{% endif %}
|
|
║ ║
|
|
║ Next steps: ║
|
|
║ - Verify VMs are running: qm list ║
|
|
║ - Connect to VM: ssh {{ ci_user }}@<vm-ip> ║
|
|
║ - Check Cloud-Init: cloud-init status ║
|
|
║ ║
|
|
╚════════════════════════════════════════════════════════════╝
|
|
|
|
# rescue:
|
|
# - name: "Handle playbook errors"
|
|
# ansible.builtin.debug:
|
|
# msg: |
|
|
# ✗ Playbook execution failed
|
|
# Check the error messages above for details.
|
|
# You may need to manually clean up partially created VMs.
|