prole/infrastructure/roles/netplan_static/tasks/main.yml
chrisfu 78a16f47e2 ansible: add merlin k3s host + USB-backed MariaDB bring-up
- Add merlin.prole.org (10.0.0.6) to inventory (k3s_hosts, mariadb_primary)

- Relax k3s preflight: /var/lib/rancher no longer requires iSCSI, only blocks SD-backed storage

- Add netplan static IP role (NetworkManager) and MariaDB primary/replica roles + site.yml ordering

- Add/upgrade USB prep tooling (prepare_mariadb_usb.sh + generated setup.sh + fstab-by-LABEL)

Co-authored-by: Junie <junie@jetbrains.com>
2026-03-05 19:17:40 -08:00

77 lines
2.7 KiB
YAML

---
- name: Skip static IP configuration when disabled
ansible.builtin.meta: end_host
when: not (netplan_static_enabled | default(false) | bool)
- name: Require netplan_static_address
ansible.builtin.assert:
that:
- netplan_static_address is defined
- netplan_static_address | length > 0
fail_msg: "netplan_static_address is required when netplan_static_enabled=true (example: 10.0.0.6/24)."
- name: Detect default interface
ansible.builtin.shell: "ip route show default | awk '/^default/ {print $5; exit}'"
register: _netplan_default_iface
changed_when: false
when: (netplan_static_iface | default('') | length) == 0
- name: Set effective interface
ansible.builtin.set_fact:
netplan_static_iface_effective: >-
{{ (netplan_static_iface | default(''))
if (netplan_static_iface | default('') | length) > 0
else (_netplan_default_iface.stdout | default('') | trim) }}
- name: Require detected interface
ansible.builtin.assert:
that:
- netplan_static_iface_effective | length > 0
fail_msg: "Unable to detect default interface for static IP. Set netplan_static_iface explicitly (e.g., eth0)."
- name: Detect default gateway
ansible.builtin.shell: "ip route show default | awk '/^default/ {print $3; exit}'"
register: _netplan_default_gw
changed_when: false
when: (netplan_static_gateway4 | default('') | length) == 0
- name: Set effective gateway
ansible.builtin.set_fact:
netplan_static_gateway4_effective: >-
{{ (netplan_static_gateway4 | default(''))
if (netplan_static_gateway4 | default('') | length) > 0
else (_netplan_default_gw.stdout | default('') | trim) }}
- name: Detect current DNS servers
ansible.builtin.shell: "awk '/^nameserver[[:space:]]+/ {print $2}' /etc/resolv.conf | head -n 5"
register: _netplan_dns_detect
changed_when: false
when: (netplan_static_nameservers | default([])) | length == 0
- name: Set effective DNS servers
ansible.builtin.set_fact:
netplan_static_nameservers_effective: >-
{{ (netplan_static_nameservers | default([]))
if ((netplan_static_nameservers | default([])) | length) > 0
else (_netplan_dns_detect.stdout_lines | default([])) }}
- name: Write netplan static config (NetworkManager)
ansible.builtin.template:
src: 99-ansible-static.yaml.j2
dest: /etc/netplan/99-ansible-static.yaml
owner: root
group: root
mode: "0644"
register: _netplan_cfg
- name: Validate netplan config
ansible.builtin.command: netplan generate
changed_when: false
when: _netplan_cfg is changed
- name: Apply netplan config
ansible.builtin.command: netplan apply
changed_when: false
when: _netplan_cfg is changed