Update roles/proxmox_upgrade/tasks/drain.yml
This commit is contained in:
@@ -45,12 +45,16 @@
|
|||||||
when: migration_target is not defined or migration_target == ''
|
when: migration_target is not defined or migration_target == ''
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
|
- name: "Drain | Log raw guest data (for debugging)"
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "Guests on {{ current_node }}: {{ node_guests.proxmox_vms | map(attribute='vmid') | list }} — tags sample: {{ node_guests.proxmox_vms | map(attribute='tags') | list }}"
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: "Drain | Build KVM migration list"
|
- name: "Drain | Build KVM migration list"
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
kvm_guests: >-
|
kvm_guests: >-
|
||||||
{{ node_guests.proxmox_vms
|
{{ node_guests.proxmox_vms
|
||||||
| selectattr('type', 'equalto', 'qemu')
|
| selectattr('type', 'equalto', 'qemu')
|
||||||
| rejectattr('tags', 'intersect', migrate_exclude_tags)
|
|
||||||
| list }}
|
| list }}
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
@@ -59,7 +63,6 @@
|
|||||||
lxc_guests: >-
|
lxc_guests: >-
|
||||||
{{ node_guests.proxmox_vms
|
{{ node_guests.proxmox_vms
|
||||||
| selectattr('type', 'equalto', 'lxc')
|
| selectattr('type', 'equalto', 'lxc')
|
||||||
| rejectattr('tags', 'intersect', migrate_exclude_tags)
|
|
||||||
| list }}
|
| list }}
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
@@ -67,8 +70,8 @@
|
|||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: >-
|
msg: >-
|
||||||
Drain plan for {{ current_node }} → {{ migration_target }}:
|
Drain plan for {{ current_node }} → {{ migration_target }}:
|
||||||
KVM: {{ kvm_guests | map(attribute='vmid') | list }}
|
KVM ({{ kvm_guests | length }}): {{ kvm_guests | map(attribute='vmid') | list }}
|
||||||
LXC: {{ lxc_guests | map(attribute='vmid') | list }}
|
LXC ({{ lxc_guests | length }}): {{ lxc_guests | map(attribute='vmid') | list }}
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
# ── KVM migrations ────────────────────────────────────────────────────────────
|
# ── KVM migrations ────────────────────────────────────────────────────────────
|
||||||
@@ -86,13 +89,13 @@
|
|||||||
vmid: "{{ item.vmid }}"
|
vmid: "{{ item.vmid }}"
|
||||||
migrate: true
|
migrate: true
|
||||||
target_node: "{{ migration_target }}"
|
target_node: "{{ migration_target }}"
|
||||||
online: "{{ true if item.status == 'running' and not item.get('needs_fallback', false) else false }}"
|
online: "{{ true if item.status == 'running' else false }}"
|
||||||
timeout: "{{ vm_shutdown_timeout }}"
|
timeout: "{{ vm_shutdown_timeout }}"
|
||||||
loop: "{{ kvm_guests }}"
|
loop: "{{ kvm_guests }}"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
when: not migration_bulk | bool
|
when: not migration_bulk | bool
|
||||||
|
|
||||||
- name: "Drain | KVM | Bulk migrate (fire and wait)"
|
- name: "Drain | KVM | Bulk migrate (fire all simultaneously)"
|
||||||
community.proxmox.proxmox_kvm:
|
community.proxmox.proxmox_kvm:
|
||||||
api_host: "{{ api_host }}"
|
api_host: "{{ api_host }}"
|
||||||
api_user: "{{ api_user }}"
|
api_user: "{{ api_user }}"
|
||||||
@@ -131,37 +134,34 @@
|
|||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: >-
|
msg: >-
|
||||||
LXC {{ item.vmid }} ({{ item.name | default('unknown') }}) will be
|
LXC {{ item.vmid }} ({{ item.name | default('unknown') }}) will be
|
||||||
stopped, migrated to {{ migration_target }}, and restarted
|
stopped, migrated to {{ migration_target }}, and restarted.
|
||||||
(LXC live migration is not supported by Proxmox).
|
(LXC live migration is not supported by Proxmox)
|
||||||
loop: "{{ lxc_guests | selectattr('status', 'equalto', 'running') | list }}"
|
loop: "{{ lxc_guests | selectattr('status', 'equalto', 'running') | list }}"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: "Drain | LXC | Warn about skipped containers"
|
- name: "Drain | LXC | Skip warning"
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: >-
|
msg: >-
|
||||||
WARNING — LXC {{ item.vmid }} ({{ item.name | default('unknown') }})
|
WARNING — LXC {{ item.vmid }} ({{ item.name | default('unknown') }})
|
||||||
live_migrate_fallback=skip — this container WILL GO DOWN during node reboot.
|
live_migrate_fallback=skip — THIS CONTAINER WILL GO DOWN during node reboot.
|
||||||
loop: "{{ lxc_guests | selectattr('status', 'equalto', 'running') | list }}"
|
loop: "{{ lxc_guests | selectattr('status', 'equalto', 'running') | list }}"
|
||||||
when: live_migrate_fallback == 'skip'
|
when: live_migrate_fallback == 'skip'
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: "Drain | LXC | Migrate via pct migrate --restart"
|
- name: "Drain | LXC | Migrate via pct migrate"
|
||||||
ansible.builtin.command: >
|
ansible.builtin.command: >
|
||||||
pct migrate {{ item.vmid }} {{ migration_target }}
|
pct migrate {{ item.vmid }} {{ migration_target }}
|
||||||
{{ '--restart' if item.status == 'running' else '' }}
|
{% if item.status == 'running' %}--restart{% endif %}
|
||||||
--timeout {{ lxc_migrate_timeout }}
|
--timeout {{ lxc_migrate_timeout }}
|
||||||
loop: "{{ lxc_guests }}"
|
loop: "{{ lxc_guests }}"
|
||||||
when: live_migrate_fallback != 'skip'
|
when: live_migrate_fallback != 'skip'
|
||||||
register: lxc_migrate_result
|
|
||||||
changed_when: true
|
changed_when: true
|
||||||
|
|
||||||
- name: "Drain | LXC | Log migration results"
|
- name: "Drain | LXC | Log migration results"
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: "LXC {{ item.item.vmid }} migrated to {{ migration_target }}"
|
msg: "LXC {{ item.item.vmid }} migrated to {{ migration_target }}"
|
||||||
loop: "{{ lxc_migrate_result.results }}"
|
loop: "{{ lxc_migrate_result.results | default([]) }}"
|
||||||
when:
|
when: item.rc is defined and item.rc == 0
|
||||||
- live_migrate_fallback != 'skip'
|
|
||||||
- item.rc == 0
|
|
||||||
|
|
||||||
- name: "Drain | {{ current_node }} drained successfully"
|
- name: "Drain | {{ current_node }} drained successfully"
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
@@ -169,4 +169,3 @@
|
|||||||
Node {{ current_node }} drained —
|
Node {{ current_node }} drained —
|
||||||
{{ kvm_guests | length }} KVM + {{ lxc_guests | length }} LXC guests
|
{{ kvm_guests | length }} KVM + {{ lxc_guests | length }} LXC guests
|
||||||
migrated to {{ migration_target }}
|
migrated to {{ migration_target }}
|
||||||
|
|
||||||
Reference in New Issue
Block a user