67 lines
2.6 KiB
YAML
67 lines
2.6 KiB
YAML
---
|
|
- name: Create pre-patch snapshot (Proxmox)
|
|
community.general.proxmox_snap:
|
|
api_host: "{{ PROXMOX_HOST }}"
|
|
api_user: "{{ PROXMOX_TOKEN_ID | split('!') | first }}"
|
|
api_token_id: "{{ PROXMOX_TOKEN_ID | split('!') | last }}"
|
|
api_token_secret: "{{ PROXMOX_TOKEN_SECRET }}"
|
|
vmid: "{{ proxmox_vmid }}"
|
|
state: present
|
|
snapname: "{{ snapshot_name_prefix }}-{{ ansible_date_time.date }}-{{ ansible_date_time.hour }}{{ ansible_date_time.minute }}"
|
|
description: "Ansible pre-patch snapshot {{ ansible_date_time.iso8601 }}"
|
|
register: proxmox_snapshot_result
|
|
when: hypervisor_type == "proxmox"
|
|
delegate_to: localhost
|
|
|
|
- name: Store Proxmox snapshot name
|
|
ansible.builtin.set_fact:
|
|
snapshot_id: "{{ snapshot_name_prefix }}-{{ ansible_date_time.date }}-{{ ansible_date_time.hour }}{{ ansible_date_time.minute }}"
|
|
when: hypervisor_type == "proxmox"
|
|
|
|
- name: Create pre-patch snapshot (XCP-NG)
|
|
ansible.builtin.shell: |
|
|
xe vm-snapshot vm={{ xcpng_vm_uuid }} new-name-label="{{ snapshot_name_prefix }}-{{ ansible_date_time.date }}-{{ ansible_date_time.hour }}{{ ansible_date_time.minute }}"
|
|
register: xcpng_snapshot_result
|
|
changed_when: xcpng_snapshot_result.rc == 0
|
|
when: hypervisor_type == "xcpng"
|
|
delegate_to: "{{ xcpng_host }}"
|
|
|
|
- name: Store XCP-NG snapshot UUID
|
|
ansible.builtin.set_fact:
|
|
snapshot_id: "{{ xcpng_snapshot_result.stdout | trim }}"
|
|
when: hypervisor_type == "xcpng"
|
|
|
|
- name: Verify snapshot was created (Proxmox)
|
|
community.general.proxmox_snap:
|
|
api_host: "{{ PROXMOX_HOST }}"
|
|
api_user: "{{ PROXMOX_TOKEN_ID | split('!') | first }}"
|
|
api_token_id: "{{ PROXMOX_TOKEN_ID | split('!') | last }}"
|
|
api_token_secret: "{{ PROXMOX_TOKEN_SECRET }}"
|
|
vmid: "{{ proxmox_vmid }}"
|
|
snapname: "{{ snapshot_id }}"
|
|
state: present
|
|
register: proxmox_snap_verify
|
|
when: hypervisor_type == "proxmox"
|
|
delegate_to: localhost
|
|
|
|
- name: Verify snapshot was created (XCP-NG)
|
|
ansible.builtin.shell: |
|
|
xe snapshot-list uuid={{ snapshot_id }} | grep uuid
|
|
register: xcpng_snap_verify
|
|
changed_when: false
|
|
failed_when: xcpng_snap_verify.stdout == ""
|
|
when: hypervisor_type == "xcpng"
|
|
delegate_to: "{{ xcpng_host }}"
|
|
|
|
- name: Assert snapshot exists before proceeding
|
|
ansible.builtin.assert:
|
|
that:
|
|
- snapshot_id is defined
|
|
- snapshot_id != ""
|
|
fail_msg: "SNAPSHOT: Failed to create or verify snapshot for {{ inventory_hostname }}. Aborting patch run."
|
|
success_msg: "Snapshot verified: {{ snapshot_id }}"
|
|
|
|
- name: Log snapshot ID
|
|
ansible.builtin.debug:
|
|
msg: "Pre-patch snapshot created: {{ snapshot_id }} for {{ inventory_hostname }}"
|