From 0fcfd8f3636695e9973504792e9102e01571a6a7 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Thu, 18 Dec 2025 16:50:37 +0200 Subject: Improvements --- playbook.yml | 27 ++++++------ tasks/jails.yml | 49 ++++------------------ tasks/jails_dataset.yml | 41 ++++++++++++++++++ tasks/jails_single.yml | 2 +- templates/ingress/usr_local_bin_hetzner_ddns.sh.j2 | 4 +- 5 files changed, 66 insertions(+), 57 deletions(-) diff --git a/playbook.yml b/playbook.yml index ef51dcb..93b4cb1 100644 --- a/playbook.yml +++ b/playbook.yml @@ -19,20 +19,21 @@ lan_ipv4_network: 192.168.0.0/16 lan_ipv4_gateway: 192.168.0.1 lan_search_domain: local.jan.systems - jail_userland_version: 14.3-RELEASE + jail_userland_14_3: 14.3-RELEASE + jail_userland_15_0: 15.0-RELEASE jails: - - { num: 1, name: ingress } - - { num: 2, name: postgres } - - { num: 3, name: irc_thelounge } - - { num: 4, name: taulubot } - - { num: 5, name: homepage } - - { num: 6, name: hommabot } - - { num: 7, name: aggro } - - { num: 8, name: diddle } - - { num: 11, name: spliit } - - { num: 13, name: ente } - - { num: 14, name: freshrss } - - { num: 15, name: paste } + - { userland: "{{ jail_userland_14_3 }}", num: 1, name: ingress } + - { userland: "{{ jail_userland_14_3 }}", num: 2, name: postgres } + - { userland: "{{ jail_userland_14_3 }}", num: 3, name: irc_thelounge } + - { userland: "{{ jail_userland_14_3 }}", num: 4, name: taulubot } + - { userland: "{{ jail_userland_14_3 }}", num: 5, name: homepage } + - { userland: "{{ jail_userland_14_3 }}", num: 6, name: hommabot } + - { userland: "{{ jail_userland_14_3 }}", num: 7, name: aggro } + - { userland: "{{ jail_userland_14_3 }}", num: 8, name: diddle } + - { userland: "{{ jail_userland_14_3 }}", num: 11, name: spliit } + - { userland: "{{ jail_userland_15_0 }}", num: 13, name: immich } + - { userland: "{{ jail_userland_14_3 }}", num: 14, name: freshrss } + - { userland: "{{ jail_userland_14_3 }}", num: 15, name: paste } ingress_routes: - { host: jan.systems, jail: homepage } - { host: jantuomi.fi, redirect: jan.systems } diff --git a/tasks/jails.yml b/tasks/jails.yml index fe94126..58d22d8 100644 --- a/tasks/jails.yml +++ b/tasks/jails.yml @@ -11,52 +11,19 @@ - { name: "zroot/jails", mountpoint: "/usr/local/jails" } - { name: "zroot/jails/media" } - { name: "zroot/jails/templates" } - - { name: "zroot/jails/templates/{{ jail_userland_version }}" } + - { + name: "zroot/jails/templates/{{ jail_userland_14_3 }}", + userland: "{{ jail_userland_14_3 }}", + } + - { + name: "zroot/jails/templates/{{ jail_userland_15_0 }}", + userland: "{{ jail_userland_15_0 }}", + } - { name: "zroot/jails/containers" } loop_control: loop_var: dataset include_tasks: jails_dataset.yml -- name: Check if userland snapshot already exists - shell: zfs list -t snapshot -o name | grep -Fxq "zroot/jails/templates/{{ jail_userland_version }}@base" - failed_when: false - changed_when: false - register: zfs_userland_check - -- name: Set up userland - when: zfs_userland_check.rc != 0 - block: - - name: Download userland - get_url: - url: https://download.freebsd.org/ftp/releases/amd64/amd64/{{ jail_userland_version }}/base.txz - dest: /usr/local/jails/media/{{ jail_userland_version }}-base.txz - owner: root - group: wheel - mode: "0644" - - - name: Unarchive userland - shell: tar -xzf /usr/local/jails/media/{{ jail_userland_version }}-base.txz -C /usr/local/jails/templates/{{ jail_userland_version }} - - - name: Copy localtime to jail userland - copy: - remote_src: true - src: /etc/localtime - dest: /usr/local/jails/templates/{{ jail_userland_version }}/etc/localtime - - - name: Copy resolv.conf to jail userland - shell: | - cat /etc/resolv.conf > /usr/local/jails/templates/{{ jail_userland_version }}/etc/resolv.conf - chmod 644 /usr/local/jails/templates/{{ jail_userland_version }}/etc/resolv.conf - - - name: Update userland to latest patch level - shell: freebsd-update -b /usr/local/jails/templates/{{ jail_userland_version }}/ fetch install - - - name: Disable syslogd in the template - shell: echo 'syslogd_enable="NO"' >> /usr/local/jails/templates/{{ jail_userland_version }}/etc/rc.conf - - - name: Create userland ZFS snapshot - shell: zfs snapshot zroot/jails/templates/{{ jail_userland_version }}@base - - name: Configure jails block: - name: Configure jail.conf diff --git a/tasks/jails_dataset.yml b/tasks/jails_dataset.yml index 9466c46..c97e14a 100644 --- a/tasks/jails_dataset.yml +++ b/tasks/jails_dataset.yml @@ -12,3 +12,44 @@ zfs create -p "{{ dataset.name }}" {% endif %} when: check_dataset_exists.rc != 0 + +- name: Check if userland snapshot already exists + shell: zfs list -t snapshot -o name | grep -Fxq "{{ dataset.name }}@base" + failed_when: false + changed_when: false + register: zfs_userland_check + when: dataset.userland is defined + +- name: Set up userland + when: dataset.userland is defined and zfs_userland_check.rc != 0 + block: + - name: Download userland + get_url: + url: https://download.freebsd.org/ftp/releases/amd64/amd64/{{ dataset.userland }}/base.txz + dest: /usr/local/jails/media/{{ dataset.userland }}-base.txz + owner: root + group: wheel + mode: "0644" + + - name: Unarchive userland + shell: tar -xzf /usr/local/jails/media/{{ dataset.userland }}-base.txz -C /usr/local/jails/templates/{{ dataset.userland }} + + - name: Copy localtime to jail userland + copy: + remote_src: true + src: /etc/localtime + dest: /usr/local/jails/templates/{{ dataset.userland }}/etc/localtime + + - name: Copy resolv.conf to jail userland + shell: | + cat /etc/resolv.conf > /usr/local/jails/templates/{{ dataset.userland }}/etc/resolv.conf + chmod 644 /usr/local/jails/templates/{{ dataset.userland }}/etc/resolv.conf + + - name: Update userland to latest patch level + shell: freebsd-update -b /usr/local/jails/templates/{{ dataset.userland }}/ fetch install + + - name: Disable syslogd in the template + shell: echo 'syslogd_enable="NO"' >> /usr/local/jails/templates/{{ dataset.userland }}/etc/rc.conf + + - name: Create userland ZFS snapshot + shell: zfs snapshot zroot/jails/templates/{{ dataset.userland }}@base diff --git a/tasks/jails_single.yml b/tasks/jails_single.yml index 043086d..274688b 100644 --- a/tasks/jails_single.yml +++ b/tasks/jails_single.yml @@ -5,7 +5,7 @@ register: check_jail_directory - name: "ZFS clone snapshot to jail directory for {{ jail.name }}" - shell: zfs clone zroot/jails/templates/{{ jail_userland_version }}@base "zroot/jails/containers/{{ jail.name }}" + shell: zfs clone zroot/jails/templates/{{ jail.userland }}@base "zroot/jails/containers/{{ jail.name }}" when: check_jail_directory.rc != 0 - name: Make resolv.conf immutable diff --git a/templates/ingress/usr_local_bin_hetzner_ddns.sh.j2 b/templates/ingress/usr_local_bin_hetzner_ddns.sh.j2 index eec12d7..ee3573e 100644 --- a/templates/ingress/usr_local_bin_hetzner_ddns.sh.j2 +++ b/templates/ingress/usr_local_bin_hetzner_ddns.sh.j2 @@ -101,11 +101,11 @@ HTTP_CODE=$( -H "Content-Type: application/json" \ -H "Authorization: Bearer ${API_TOKEN}" \ --data "${BODY}" \ - "${API_BASE}/zones/${ZONE}/rrsets/${RR_ID}/actions/update_records" + "${API_BASE}/zones/${ZONE}/rrsets/${RR_ID}/actions/set_records" ) case "${HTTP_CODE}" in - 200) + 20*) info "Updated zone ${ZONE} RRSet ${RR_ID} -> ${IFACE_IP}" exit 0 ;; -- cgit v1.3