ansiiiible
This commit is contained in:
parent
85d0217436
commit
a8aa633c49
12 changed files with 314 additions and 0 deletions
37
ansible/roles/create-template/tasks/main.yml
Normal file
37
ansible/roles/create-template/tasks/main.yml
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
- name: Set full image path on Proxmox
|
||||
ansible.builtin.set_fact:
|
||||
remote_image_path: "{{ dest_image_path }}{{ image_filename }}"
|
||||
delegate_to: localhost # Run this locally to set a fact accessible globally
|
||||
|
||||
- name: Destroy existing backup template VM (if it exists)
|
||||
ansible.builtin.shell: "qm destroy {{ vmid_backup_template }} --purge || true"
|
||||
# args:
|
||||
# warn: no
|
||||
# changed_when: false # Assume idempotency; if it didn't exist, no change
|
||||
failed_when: false # Don't fail if VM isn't found
|
||||
|
||||
- name: Clone 'lastest' template to 'backup' template VMID
|
||||
ansible.builtin.command: >
|
||||
qm clone {{ vmid_latest_template }} {{ vmid_backup_template }} --name {{ vmname_backup_template }} --full
|
||||
# args:
|
||||
# creates: "/etc/pve/qemu-server/{{ vmid_backup_template }}.conf" # Idempotency check: only run if config file doesn't exist
|
||||
# failed_when: false # Don't fail if VM isn't found
|
||||
|
||||
- name: Convert 'backup' template VM to a template
|
||||
ansible.builtin.command: "qm template {{ vmid_backup_template }}"
|
||||
|
||||
- name: Destroy existing backup template VM (if it exists)
|
||||
ansible.builtin.shell: "qm destroy {{ vmid_backup_template }} --purge || true"
|
||||
|
||||
- name: Restore VM from image to 'latest' template VMID
|
||||
ansible.builtin.command: >
|
||||
qmrestore {{ remote_image_path }} {{ vmid_latest_template }} --unique true
|
||||
# args:
|
||||
# creates: "/etc/pve/qemu-server/{{ vmid_latest_template }}.conf" # Idempotency check: only run if config file doesn't exist
|
||||
|
||||
- name: Set CPU and memory for the base template VM
|
||||
ansible.builtin.command: >
|
||||
qm set {{ vmid_latest_template }} --cores {{ cpu_cores }} --memory {{ memory_mb }} --name {{ vmname_latest_template }}
|
||||
|
||||
- name: Convert 'backup' template VM to a template
|
||||
ansible.builtin.command: "qm template {{ vmid_latest_template }}"
|
||||
29
ansible/roles/upload/tasks/main.yml
Normal file
29
ansible/roles/upload/tasks/main.yml
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
- name: Get built image file (.vma.zst) from result/
|
||||
ansible.builtin.find:
|
||||
paths: "{{ result_path }}"
|
||||
patterns: "*.vma.zst"
|
||||
file_type: file # Ensure it's a file
|
||||
register: built_image_files
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Fail if no image was built
|
||||
ansible.builtin.fail:
|
||||
msg: "No .vma.zst image file found in {{ result_path }}/"
|
||||
when: built_image_files.files | length == 0
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Set fact for built image path and filename
|
||||
ansible.builtin.set_fact:
|
||||
local_image_path: "{{ built_image_files.files[0].path | realpath }}"
|
||||
image_filename: "{{ built_image_files.files[0].path | basename }}"
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Display paths (for debugging)
|
||||
ansible.builtin.debug:
|
||||
msg: "Local image path: {{ local_image_path }}, Filename: {{ image_filename }}"
|
||||
|
||||
- name: Copy image to Proxmox server
|
||||
ansible.builtin.copy:
|
||||
src: "{{ local_image_path }}"
|
||||
dest: "{{ dest_image_path }}"
|
||||
mode: "0644" # Ensure correct permissions on the destination
|
||||
Loading…
Add table
Add a link
Reference in a new issue