Updated homelab hosts & structure

This commit is contained in:
Janic Voser
2026-08-14 00:17:50 +02:00
parent bb8b9602f2
commit 097ee79bed
23 changed files with 506 additions and 0 deletions
+93
View File
@@ -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 }}"
+8
View File
@@ -0,0 +1,8 @@
---
- name: Distribution not found
debug:
msg:
- "OS Family: {{ ansible_os_family }}"
- "OS Distro: {{ ansible_distribution }}"
- "OS Major Version: {{ ansible_distribution_major_version }}"
- "OS Version: {{ ansible_distribution_version }}"
+31
View File
@@ -0,0 +1,31 @@
---
# tasks file for ./playbooks/roles/proxmox-patching
- name: Import variables specific to distribution
include_vars: "{{ item }}"
with_first_found:
- "{{ role_path }}/vars/{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }}.yml"
- "{{ role_path }}/vars/{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }}.yml"
- "{{ role_path }}/vars/{{ ansible_facts['distribution'] }}.yml"
# ansible_os_family is used as a fallback for distros which are not currently
# supported, but are based on a supported distro family. For example,
# Oracle, Rocky, Alma and Alibaba linux, which are all "RedHat" based.
- "{{ role_path }}/vars/{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_version'] }}.yml"
- "{{ role_path }}/vars/{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_major_version'] }}.yml"
- "{{ role_path }}/vars/{{ ansible_facts['os_family'] }}.yml"
# If neither distro nor family is supported, try a default configuration.
- "{{ role_path }}/vars/default.yml"
- name: Update everything for distribution
include_tasks: "{{ item }}"
with_first_found:
- "{{ role_path }}/tasks/dist/{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }}.yml"
- "{{ role_path }}/tasks/dist/{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }}.yml"
- "{{ role_path }}/tasks/dist/{{ ansible_facts['distribution'] }}.yml"
# ansible_os_family is used as a fallback for distros which are not currently
# supported, but are based on a supported distro family. For example,
# Oracle, Rocky, Alma and Alibaba linux, which are all "RedHat" based.
- "{{ role_path }}/tasks/dist/{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_version'] }}.yml"
- "{{ role_path }}/tasks/dist/{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_major_version'] }}.yml"
- "{{ role_path }}/tasks/dist/{{ ansible_facts['os_family'] }}.yml"
# If neither distro nor family is supported, try a default configuration.
- "{{ role_path }}/tasks/dist/no_dist_found.yml"