--- # ============================================================================= # proxmox_upgrade — restore.yml # Optionally migrate guests back to their original node after upgrade # Only runs if migration_restore: true # ============================================================================= - name: Restore | Skip restore ansible.builtin.debug: msg: "migration_restore=false — leaving guests on their current nodes" when: not migration_restore | bool - name: Restore | Migrate guests back to {{ current_node }} when: migration_restore | bool block: - name: Restore | Get guests currently on other nodes that originated from {{ current_node }} ansible.builtin.debug: msg: >- Restoring {{ migration_plan | rejectattr('needs_fallback') | list | length + (migration_plan | selectattr('needs_fallback') | list | length if live_migrate_fallback != 'skip' else 0) }} guests back to {{ current_node }} - name: Restore | Migrate each guest back ansible.builtin.uri: url: "https://{{ api_host }}:{{ api_port }}/api2/json/nodes/{{ migration_targets | first }}/{{ 'qemu' if guest.type == 'qemu' else 'lxc' }}/{{ guest.vmid }}/migrate" method: POST headers: Authorization: "PVEAPIToken={{ api_token_id }}={{ api_token_secret }}" body_format: json body: target: "{{ current_node }}" online: "{{ 0 if (guest.needs_fallback and live_migrate_fallback == 'shutdown') else 1 }}" validate_certs: false register: restore_task loop: "{{ migration_plan | rejectattr('needs_fallback') | list }}" loop_var: guest delegate_to: localhost - name: Restore | Wait for all restore migrations to complete ansible.builtin.uri: url: "https://{{ api_host }}:{{ api_port }}/api2/json/nodes/{{ migration_targets | first }}/tasks/{{ item.json.data }}/status" method: GET headers: Authorization: "PVEAPIToken={{ api_token_id }}={{ api_token_secret }}" validate_certs: false register: restore_status until: restore_status.json.data.status == 'stopped' retries: 60 delay: 10 loop: "{{ restore_task.results }}" delegate_to: localhost - name: Restore | Check all restores succeeded ansible.builtin.fail: msg: "Restore migration failed — {{ item.json.data.exitstatus }}" loop: "{{ restore_status.results }}" when: item.json.data.exitstatus != 'OK' delegate_to: localhost - name: Restore | Complete ansible.builtin.debug: msg: "All guests restored to {{ current_node }}"