Updated homelab hosts & structure
This commit is contained in:
+93
@@ -0,0 +1,93 @@
|
||||
---
|
||||
# Ensure Ceph is healthy, before starting to patch
|
||||
- name: Ensure Ceph is HEALTH_OK and no rebalancing
|
||||
shell: |
|
||||
ceph status | grep 'HEALTH_OK' && ! ceph status | grep -q -e 'degraded' -e 'remapped'
|
||||
register: ceph_health
|
||||
failed_when: ceph_health.rc != 0
|
||||
delegate_to: "{{ play_hosts[0] }}"
|
||||
# Ensure no node is in Maintenance Mode before patching
|
||||
- name: Ensure no node is in mainteance mode
|
||||
shell: ha-manager status | grep '^lrm ' | grep -e maintenance | wc -l
|
||||
register: no_node_maintenance
|
||||
failed_when: no_node_maintenance.stdout|int != 0
|
||||
delegate_to: "{{ play_hosts[0] }}"
|
||||
# Check that all VMs are in a HA Group, so they will be migrated when the host gets set to maintenance Mode
|
||||
- name: Ensure all VMs are in a HA Group
|
||||
shell: |
|
||||
for res in $(pvesh get /cluster/resources -type vm --output-format json|jq '.[]|select(has("hastate")|not)|.vmid'); do ha-manager add $res ;done
|
||||
|
||||
- block:
|
||||
# Set the noout flag to ensure no data on ceph is moved, while a host is unavailable
|
||||
- name: Set Ceph noout flag (only first run)
|
||||
shell: ceph osd set noout
|
||||
# Enable the maintenance Mode of the Host
|
||||
- name: Enable maintenance mode and migrate VMs
|
||||
shell: ha-manager crm-command node-maintenance enable {{ inventory_hostname }}
|
||||
ignore_errors: false
|
||||
|
||||
# Wait till all resources are migrate away
|
||||
- name: Wait until no VMs are running on this host
|
||||
shell: |
|
||||
qm list | grep running | wc -l
|
||||
register: vm_count
|
||||
changed_when: false
|
||||
retries: "{{ long_task.retries }}"
|
||||
delay: "{{ long_task.delay }}"
|
||||
until: vm_count.stdout|int == 0
|
||||
- name: Wait until no LXCs are running on this host
|
||||
shell: |
|
||||
pct list | grep running | wc -l
|
||||
register: lxc_count
|
||||
changed_when: false
|
||||
retries: "{{ long_task.retries }}"
|
||||
delay: "{{ long_task.delay }}"
|
||||
until: lxc_count.stdout|int == 0
|
||||
|
||||
# Install latest Packages
|
||||
- name: Update apt packages
|
||||
apt:
|
||||
update_cache: yes
|
||||
upgrade: dist
|
||||
autoremove: yes
|
||||
|
||||
# Compare if the current running kernel is the same as the latest kernel
|
||||
- name: Get expected boot kernel version
|
||||
shell: |
|
||||
grep vmlinuz /boot/grub/grub.cfg | head -1 | awk '{ print $2 }' | sed -e 's%/boot/vmlinuz-%%;s%/ROOT/pve-1@%%'
|
||||
register: boot_kernel
|
||||
changed_when: false
|
||||
- name: Get currently running kernel version
|
||||
shell: uname -r
|
||||
register: running_kernel
|
||||
changed_when: false
|
||||
# If a newer kernel is on the system, then reboot
|
||||
- name: Reboot if required
|
||||
reboot:
|
||||
reboot_timeout: 600
|
||||
post_reboot_delay: 60
|
||||
when: boot_kernel.stdout.strip() != running_kernel.stdout.strip()
|
||||
|
||||
|
||||
# Disable Ceph noout, as soon as the host is online
|
||||
- name: Unset Ceph noout flag
|
||||
shell: ceph osd unset noout
|
||||
|
||||
- name: Ensure Ceph is HEALTH_OK again
|
||||
shell: |
|
||||
ceph status | grep 'HEALTH_OK' && ! ceph status | grep -q -e 'degraded' -e 'remapped'
|
||||
register: ceph_health
|
||||
retries: "{{ long_task.retries }}"
|
||||
delay: "{{ long_task.delay }}"
|
||||
failed_when: ceph_health.rc != 0
|
||||
delegate_to: "{{ play_hosts[0] }}"
|
||||
|
||||
- name: Disable maintenance mode and migrate VMs
|
||||
shell: ha-manager crm-command node-maintenance disable {{ inventory_hostname }}
|
||||
ignore_errors: false
|
||||
- name: Ensure no node is in mainteance mode
|
||||
shell: ha-manager status | grep '^lrm ' | grep -e maintenance | wc -l
|
||||
register: no_node_maintenance
|
||||
failed_when: no_node_maintenance.stdout|int != 0
|
||||
retries: "{{ long_task.retries }}"
|
||||
delay: "{{ long_task.delay }}"
|
||||
Reference in New Issue
Block a user