prole/infrastructure/roles/iscsi/tasks/mount.yml
chrisfu 5dcd3b9581 ansible: treat /var/lib/rancher as local K3s state
Update inventory/roles to keep K3s state on local storage and prevent iSCSI from managing /var/lib/rancher.

Also add a single-host k3s install playbook, a systemd override template, and docs describing the installer ↔ Ansible boundary and slow-storage knobs.

Co-authored-by: Junie <junie@jetbrains.com>
2026-03-15 23:20:55 -07:00

52 lines
1.8 KiB
YAML

---
- name: Unmount stale iSCSI mounts
ansible.builtin.mount:
path: "{{ item.path | default(item) }}"
state: unmounted
loop: "{{ iscsi_absent_mounts | default([]) }}"
loop_control:
label: "{{ item.path | default(item) }}"
tags:
- iscsi_cleanup
- name: Guardrail - iSCSI must not manage /var/lib/rancher
ansible.builtin.assert:
that:
- >-
(iscsi_targets | default([])
| map(attribute='mounts') | list | flatten
| selectattr('path', 'equalto', '/var/lib/rancher')
| list | length) == 0
fail_msg: >-
Inventory attempts to mount `/var/lib/rancher` via iSCSI. K3s state storage is
intended to be local host storage (e.g. USB3 SSD on myrddin). Remove
`/var/lib/rancher` from `iscsi_targets[*].mounts` (or set
`iscsi_allow_rancher_mount: true` if you are intentionally overriding this).
when: not (iscsi_allow_rancher_mount | default(false) | bool)
- name: Remove stale iSCSI fstab entries
ansible.builtin.lineinfile:
path: /etc/fstab
state: absent
regexp: "^\\s*\\S+\\s+{{ (item.path | default(item)) | regex_escape }}\\s+"
loop: "{{ iscsi_absent_mounts | default([]) }}"
loop_control:
label: "{{ item.path | default(item) }}"
tags:
- iscsi_cleanup
- name: Mount filesystems for iSCSI targets
ansible.builtin.include_tasks: iscsi_mount.yml
loop: "{{ iscsi_targets | default([]) | map(attribute='mounts') | list | flatten }}"
loop_control:
loop_var: m
- name: Guardrail - ensure required mountpoints are mounted
ansible.builtin.command: "findmnt -n {{ item.path }}"
register: _findmnt
changed_when: false
failed_when: _findmnt.rc != 0
loop: "{{ iscsi_targets | default([]) | map(attribute='mounts') | list | flatten }}"
loop_control:
label: "{{ item.path }}"