Initial update config
This commit is contained in:
commit
190f56770a
3 changed files with 69 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
.DS_Store
|
||||
**/.DS_Store
|
||||
._.DS_Store
|
||||
**/._.DS_Store
|
||||
10
inventory.ini
Normal file
10
inventory.ini
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[k3s_servers]
|
||||
birdfeeder1.home.nest # rpi5-1
|
||||
birdfeeder2.home.nest # rpi5-2
|
||||
birdfeeder3.home.nest # rpi5-3
|
||||
|
||||
[k3s_agents_raspbian]
|
||||
chickadee.home.nest # rpi4-1
|
||||
|
||||
[k3s_agents_nixos]
|
||||
robin.home.nest # nixos-1
|
||||
55
playbooks/update-k3s-nodes.yaml
Normal file
55
playbooks/update-k3s-nodes.yaml
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
---
|
||||
- name: Update Cluster Nodes
|
||||
hosts: all
|
||||
serial: 1 # CRITICAL: Processes one node entirely before moving to the next
|
||||
become: yes
|
||||
tasks:
|
||||
- name: Determine an available k3s control plane node
|
||||
set_fact:
|
||||
# Picks the first server node that is NOT the one currently being updated
|
||||
active_master: "{{ groups['k3s_servers'] | difference([inventory_hostname]) | first }}"
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Check if updates are needed (Debian/Raspbian)
|
||||
apt:
|
||||
upgrade: dist
|
||||
update_cache: yes
|
||||
register: apt_status
|
||||
when: inventory_hostname in groups['k3s_servers'] or inventory_hostname in groups['k3s_agents_raspbian']
|
||||
|
||||
# For NixOS, we just run the upgrade and check if a reboot is flagged.
|
||||
- name: Run NixOS update command
|
||||
command: nixos-rebuild switch --upgrade
|
||||
register: nixos_status
|
||||
when: inventory_hostname in groups['k3s_agents_nixos']
|
||||
|
||||
- name: Check for Raspbian reboot required flag
|
||||
stat:
|
||||
path: /var/run/reboot-required
|
||||
register: reboot_required
|
||||
when: inventory_hostname not in groups['k3s_agents_nixos']
|
||||
|
||||
# --- THE KUBERNETES DRAIN PHASE ---
|
||||
- name: Drain the node safely
|
||||
command: >
|
||||
k3s kubectl drain {{ inventory_hostname }}
|
||||
--ignore-daemonsets
|
||||
--delete-emptydir-data
|
||||
--force
|
||||
--grace-period=90
|
||||
--timeout=5m
|
||||
delegate_to: "{{ active_master }}"
|
||||
when: (reboot_required.stat.exists | default(false)) or ('changed' in nixos_status | default({}))
|
||||
ignore_errors: yes # Prevents a stubborn pod from halting the entire cluster update
|
||||
|
||||
# --- THE REBOOT PHASE ---
|
||||
- name: Reboot the node
|
||||
reboot:
|
||||
post_reboot_delay: 180 # Give k3s and Longhorn time to initialize
|
||||
when: (reboot_required.stat.exists | default(false)) or ('changed' in nixos_status | default({}))
|
||||
|
||||
# --- THE UNCORDON PHASE ---
|
||||
- name: Uncordon the node
|
||||
command: k3s kubectl uncordon {{ inventory_hostname }}
|
||||
delegate_to: "{{ active_master }}"
|
||||
when: (reboot_required.stat.exists | default(false)) or ('changed' in nixos_status | default({}))
|
||||
Loading…
Add table
Reference in a new issue