Merge branch 'main' into ci/432-two-lanes
Build / build (pull_request) Successful in 28s
Lint / lint (pull_request) Successful in 2m44s
Molecule / molecule (pull_request) Successful in 29m36s

This commit is contained in:
Defame1297 committed 2026-11-29 08:07:17 +00:00
commit 2b221b69a5
21 files changed
+273 -313

No files matched your search

@@ -0,0 +1,4 @@
---
trivial:
- >-
system_baseline - Purge the unwanted packages that are installed in one apt call instead of one call per package.
@@ -0,0 +1,6 @@
---
minor_changes:
- >-
traefik - The prerequisites install refreshes the APT cache only when it is older than an hour;
before, every run refreshed it. A consumer who adds an APT source just before the role must
refresh the cache first.
+42 -52
View File
@@ -297,48 +297,7 @@
changed_when: false changed_when: false
failed_when: docker_verify_start_run.rc != 2 failed_when: docker_verify_start_run.rc != 2
# Switching an input back to false removes that unit and script and leaves the other alone. # Converge's daemon.json, read before the role runs below change it.
- name: Verify that a unit is removed when its input is false
hosts: all
vars:
docker_gpg_url: file:///srv/docker-stub-repo/docker.asc
docker_keyring_checksum: "{{ docker_stub_key.stat.checksum }}"
docker_repo_base_url: file:///srv/docker-stub-repo
docker_users: [moleculeuser]
docker_start_missed: false
docker_stop_at_shutdown: true
docker_stop_at_shutdown_timeout: 20
tasks:
- name: Stat the stand-in repository key
ansible.builtin.stat:
path: /srv/docker-stub-repo/docker.asc
checksum_algorithm: sha256
register: docker_stub_key
- name: Apply the role with the boot unit off
ansible.builtin.include_role:
name: mortis.kamino.docker
- name: Stat the boot unit's files and the shutdown unit's script
ansible.builtin.stat:
path: "{{ item }}"
loop:
- /usr/local/sbin/docker-start-missed
- /etc/systemd/system/docker-start-missed.service
- /usr/local/sbin/docker-stop-at-shutdown
register: docker_verify_off
- name: The boot unit is gone and the shutdown unit is still there
ansible.builtin.assert:
that: docker_verify_off.results | map(attribute='stat.exists') | list == [false, false, true]
quiet: true
- name: Apply the role again with both inputs on
ansible.builtin.include_role:
name: mortis.kamino.docker
vars:
docker_start_missed: true
- name: Verify the daemon settings - name: Verify the daemon settings
hosts: all hosts: all
gather_facts: false gather_facts: false
@@ -369,22 +328,26 @@
- docker_verify_daemon_stat.stat.pw_name == 'root' - docker_verify_daemon_stat.stat.pw_name == 'root'
quiet: true quiet: true
# The stand-in docker.service runs for real, so a restart shows in its start time: a changed file with docker_daemon_restart false leaves # The stand-in docker.service runs for real, so a restart shows in its start time. The first run turns the boot unit off and changes
# it alone, and with true restarts it. # daemon.json with docker_daemon_restart false: the unit goes, the other stays and dockerd keeps running. The second turns everything
- name: Verify that dockerd restarts only when asked # back on with docker_daemon_restart true: the boot unit returns and dockerd restarts.
- name: Verify the unit inputs and that dockerd restarts only when asked
hosts: all hosts: all
vars: vars:
docker_gpg_url: file:///srv/docker-stub-repo/docker.asc docker_gpg_url: file:///srv/docker-stub-repo/docker.asc
docker_keyring_checksum: "{{ docker_stub_key.stat.checksum }}" docker_keyring_checksum: "{{ docker_stub_key.stat.checksum }}"
docker_repo_base_url: file:///srv/docker-stub-repo docker_repo_base_url: file:///srv/docker-stub-repo
docker_users: [moleculeuser] docker_users: [moleculeuser]
docker_start_missed: true
docker_stop_at_shutdown: true docker_stop_at_shutdown: true
docker_stop_at_shutdown_timeout: 20 docker_stop_at_shutdown_timeout: 20
docker_log_driver: local docker_log_driver: local
docker_log_max_size: 10m docker_log_max_size: 10m
docker_log_max_file: "3" docker_log_max_file: "3"
docker_live_restore: true docker_live_restore: true
docker_verify_unit_paths:
- /usr/local/sbin/docker-start-missed
- /etc/systemd/system/docker-start-missed.service
- /usr/local/sbin/docker-stop-at-shutdown
tasks: tasks:
- name: Stat the stand-in repository key - name: Stat the stand-in repository key
ansible.builtin.stat: ansible.builtin.stat:
@@ -397,10 +360,11 @@
register: docker_verify_before register: docker_verify_before
changed_when: false changed_when: false
- name: Apply a changed setting with docker_daemon_restart false - name: Apply the boot unit off and a changed setting with docker_daemon_restart false
ansible.builtin.include_role: ansible.builtin.include_role:
name: mortis.kamino.docker name: mortis.kamino.docker
vars: vars:
docker_start_missed: false
docker_daemon_options: {max-concurrent-downloads: 5} docker_daemon_options: {max-concurrent-downloads: 5}
docker_daemon_restart: false docker_daemon_restart: false
@@ -409,10 +373,30 @@
register: docker_verify_kept register: docker_verify_kept
changed_when: false changed_when: false
- name: Apply another change with docker_daemon_restart true - name: Stat the boot unit's files and the shutdown unit's script
ansible.builtin.stat:
path: "{{ item }}"
loop: "{{ docker_verify_unit_paths }}"
register: docker_verify_off
- name: Read daemon.json
ansible.builtin.slurp:
src: /etc/docker/daemon.json
register: docker_verify_daemon_kept
- name: The boot unit is gone, the shutdown unit is still there, and the changed file left dockerd running
ansible.builtin.assert:
that:
- docker_verify_off.results | map(attribute='stat.exists') | list == [false, false, true]
- (docker_verify_daemon_kept.content | b64decode | from_json)['max-concurrent-downloads'] == 5
- docker_verify_kept.stdout == docker_verify_before.stdout
quiet: true
- name: Apply both units on and another change with docker_daemon_restart true
ansible.builtin.include_role: ansible.builtin.include_role:
name: mortis.kamino.docker name: mortis.kamino.docker
vars: vars:
docker_start_missed: true
docker_daemon_options: {max-concurrent-downloads: 6} docker_daemon_options: {max-concurrent-downloads: 6}
docker_daemon_restart: true docker_daemon_restart: true
@@ -421,17 +405,23 @@
register: docker_verify_restarted register: docker_verify_restarted
changed_when: false changed_when: false
- name: Read daemon.json - name: Stat the unit files again
ansible.builtin.stat:
path: "{{ item }}"
loop: "{{ docker_verify_unit_paths }}"
register: docker_verify_on
- name: Read daemon.json again
ansible.builtin.slurp: ansible.builtin.slurp:
src: /etc/docker/daemon.json src: /etc/docker/daemon.json
register: docker_verify_daemon_after register: docker_verify_daemon_after
- name: The first change left dockerd alone and the second restarted it - name: Both units are back and the second change restarted dockerd
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- docker_verify_kept.stdout == docker_verify_before.stdout - docker_verify_on.results | map(attribute='stat.exists') | unique | list == [true]
- docker_verify_restarted.stdout != docker_verify_kept.stdout
- (docker_verify_daemon_after.content | b64decode | from_json)['max-concurrent-downloads'] == 6 - (docker_verify_daemon_after.content | b64decode | from_json)['max-concurrent-downloads'] == 6
- docker_verify_restarted.stdout != docker_verify_kept.stdout
quiet: true quiet: true
# A key that does not match docker_keyring_checksum fails at the key download, so the source line and packages are untouched. It goes to a separate path, so # A key that does not match docker_keyring_checksum fails at the key download, so the source line and packages are untouched. It goes to a separate path, so
+38 -38
View File
@@ -359,23 +359,26 @@
loop_var: gitea_runner_test_path loop_var: gitea_runner_test_path
# 6.0.2 has a wrong checksum file (prepare.yml): the download must fail before anything is # 6.0.2 has a wrong checksum file (prepare.yml): the download must fail before anything is
# stopped, so the runner keeps running 6.0.1. # stopped, so the runner keeps running 6.0.1. The same run sets the disk threshold to 0: prune
- name: Verify a failed download leaves the runner running # runs before update, so the pressure units are already removed when the download fails.
- name: Verify a failed download leaves the runner running, and turning the pressure prune off
hosts: all hosts: all
gather_facts: false gather_facts: false
tasks: tasks:
- name: Update to a release whose checksum does not match - name: Update to a release whose checksum does not match
block: block:
- name: Include the role with gitea_runner_version 6.0.2 - name: Include the role with gitea_runner_version 6.0.2 and the disk threshold at 0
ansible.builtin.include_role: ansible.builtin.include_role:
name: mortis.kamino.gitea_runner name: mortis.kamino.gitea_runner
vars: vars:
gitea_runner_version: 6.0.2 gitea_runner_version: 6.0.2
gitea_runner_docker_prune_disk_threshold_percent: 0
- name: Fail because the include returned - name: Fail because the include returned
ansible.builtin.fail: ansible.builtin.fail:
msg: The role accepted a binary with a wrong checksum msg: The role accepted a binary with a wrong checksum
rescue: rescue:
# The message comes only from the staging rescue, so a prune error fails this assert.
- name: The staging failed, and nothing else failed first - name: The staging failed, and nothing else failed first
ansible.builtin.assert: ansible.builtin.assert:
that: that:
@@ -407,6 +410,31 @@
- not gitea_runner_test_staged.stat.exists - not gitea_runner_test_staged.stat.exists
quiet: true quiet: true
- name: Stat the pressure units and script
ansible.builtin.stat:
path: "{{ gitea_runner_test_path }}"
loop:
- /etc/systemd/system/gitea-runner-docker-prune-pressure.service
- /etc/systemd/system/gitea-runner-docker-prune-pressure.timer
- /usr/local/sbin/gitea-runner-docker-prune-disk-check
loop_control:
loop_var: gitea_runner_test_path
register: gitea_runner_test_pressure_off
- name: Ask systemd about the pressure timer after turning it off
ansible.builtin.systemd:
name: gitea-runner-docker-prune-pressure.timer
register: gitea_runner_test_pressure_timer_off
# The module errors for a unit that no longer exists, which is also a pass.
failed_when: false
- name: The pressure units are gone and the timer is not active
ansible.builtin.assert:
that:
- gitea_runner_test_pressure_off.results | map(attribute='stat') | map(attribute='exists') | select | list | length == 0
- gitea_runner_test_pressure_timer_off.status.ActiveState | default('inactive') != 'active'
quiet: true
# Each input assert, through the main entry point. Every one runs in validate.yml, before any # Each input assert, through the main entry point. Every one runs in validate.yml, before any
# change. # change.
- name: Verify the input asserts - name: Verify the input asserts
@@ -448,8 +476,9 @@
label: "{{ gitea_runner_test_refused.name }}" label: "{{ gitea_runner_test_refused.name }}"
# The CI guard and the mint-before-drop order of a forced re-registration, through a child # The CI guard and the mint-before-drop order of a forced re-registration, through a child
# ansible-playbook against this instance (see force_register.yml). Neither case may touch the # ansible-playbook against one instance (see force_register.yml). Neither case may touch the
# registration or stop the runner. # registration or stop the runner. The children run once: what they check is controller state
# and group_vars, the same for every host, and run_once gives every host their results.
- name: Verify the forced re-registration guards - name: Verify the forced re-registration guards
hosts: all hosts: all
gather_facts: false gather_facts: false
@@ -465,6 +494,7 @@
- name: Force a re-registration under each CI variable, as a child process with only that one set - name: Force a re-registration under each CI variable, as a child process with only that one set
delegate_to: localhost delegate_to: localhost
run_once: true
ansible.builtin.command: ansible.builtin.command:
argv: argv:
- ansible-playbook - ansible-playbook
@@ -497,6 +527,7 @@
- name: Force a re-registration outside CI with no token host, as a child process - name: Force a re-registration outside CI with no token host, as a child process
delegate_to: localhost delegate_to: localhost
run_once: true
ansible.builtin.command: ansible.builtin.command:
argv: argv:
- ansible-playbook - ansible-playbook
@@ -550,43 +581,12 @@
- gitea_runner_test_unit.status.ActiveState == 'active' - gitea_runner_test_unit.status.ActiveState == 'active'
quiet: true quiet: true
# A threshold of 0 removes the pressure units; the run after it, with the scenario's inputs, # The failed-download run above removed the pressure units; this run, with the scenario's inputs,
# puts them back, so the remove path below still has them to remove. # puts them back, so the remove path below still has them to remove.
- name: Verify turning the pressure prune off - name: Verify turning the pressure prune on again
hosts: all hosts: all
gather_facts: false gather_facts: false
tasks: tasks:
- name: Run the role with the disk threshold at 0
ansible.builtin.include_role:
name: mortis.kamino.gitea_runner
vars:
gitea_runner_docker_prune_disk_threshold_percent: 0
- name: Stat the pressure units and script
ansible.builtin.stat:
path: "{{ gitea_runner_test_path }}"
loop:
- /etc/systemd/system/gitea-runner-docker-prune-pressure.service
- /etc/systemd/system/gitea-runner-docker-prune-pressure.timer
- /usr/local/sbin/gitea-runner-docker-prune-disk-check
loop_control:
loop_var: gitea_runner_test_path
register: gitea_runner_test_pressure_off
- name: Ask systemd about the pressure timer after turning it off
ansible.builtin.systemd:
name: gitea-runner-docker-prune-pressure.timer
register: gitea_runner_test_pressure_timer_off
# The module errors for a unit that no longer exists, which is also a pass.
failed_when: false
- name: The pressure units are gone and the timer is not active
ansible.builtin.assert:
that:
- gitea_runner_test_pressure_off.results | map(attribute='stat') | map(attribute='exists') | select | list | length == 0
- gitea_runner_test_pressure_timer_off.status.ActiveState | default('inactive') != 'active'
quiet: true
- name: Run the role again with the scenario's inputs - name: Run the role again with the scenario's inputs
ansible.builtin.include_role: ansible.builtin.include_role:
name: mortis.kamino.gitea_runner name: mortis.kamino.gitea_runner
+2 -2
View File
@@ -134,8 +134,8 @@ The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_
- Verify checks the installed and removed packages, the journal size cap, the apt settings in `20auto-upgrades` and `50unattended-upgrades`, the locale, and that systemd loaded the `apt-daily.service` timeout. - Verify checks the installed and removed packages, the journal size cap, the apt settings in `20auto-upgrades` and `50unattended-upgrades`, the locale, and that systemd loaded the `apt-daily.service` timeout.
- Verify checks the tmux snippet: root-owned, valid shell, the session and quoted window command, no effect without a terminal, a session name or window command ending in a newline refused, and the file removed when autostart is off. - Verify checks the tmux snippet: root-owned, valid shell, the session and quoted window command, no effect without a terminal, a session name or window command ending in a newline refused, and the file removed when autostart is off.
- Verify refuses bad items in `system_baseline_extra_packages` and `system_baseline_extra_remove_packages` (whitespace, a null, an empty string, a trailing minus, upper case, a bare string) and a package that one input installs and another purges; converge applies the `ubuntu_lxc` profile with `jq` as an extra package and `ed` as an extra removal; verify checks that `jq` is installed, `ed` is gone and the profile's packages are still there, and that an extra `tmux` installs the snippet where a flat list without it installs none. - Verify refuses bad items in `system_baseline_extra_packages` and `system_baseline_extra_remove_packages` (whitespace, a null, an empty string, a trailing minus, upper case, a bare string) and a package that one input installs and another purges; converge applies the `ubuntu_lxc` profile with `jq` as an extra package and `ed` as an extra removal; verify checks that `jq` is installed, `ed` is gone and the profile's packages are still there, and that an extra `tmux` installs the snippet where a flat list without it installs none.
- Verify also checks that a bad `system_baseline_apt_tmpdir` (under `/tmp` or `/var/tmp`, relative, with `..`, empty) is refused in the main flow and in the `update` entry point. It reads `tasks/update.yml` and checks that the scratch directory is created with mode `0700`, that both apt tasks set `TMPDIR` to it, and that the connection is reset afterwards: the scenario skips the `update` tag, so the upgrade itself never runs there. - Verify also checks that a bad `system_baseline_apt_tmpdir` (under `/tmp` or `/var/tmp`, relative, with `..`, empty) is refused in the main flow and in the `update` entry point. It reads `tasks/update.yml` and checks that the scratch directory is created with mode `0700`, that both apt tasks set `TMPDIR` to it, that the connection is reset afterwards, and that the vzdump guard is imported before the upgrade, whose `when` reads the guard's fact: the scenario skips the `update` tag, so the upgrade itself never runs there.
- Verify runs the `update` entry point in check mode on the Ubuntu container with `system_baseline_system_type: pve` and a `pvesh` stub, in seven cases (a running, a finished or no vzdump task, the input off, `ubuntu_lxc`), and asserts the fact that decides the upgrade and that `pvesh` was run, with `--source active`, only when it should be. It does not assert that the apt task itself was skipped. The stub stands for the real answer, which no CI image has. - Verify runs the vzdump guard in check mode on the Ubuntu container with `system_baseline_system_type: pve` and a `pvesh` stub, in seven cases (a running, a finished or no vzdump task, the input off, `ubuntu_lxc`); six run the guard's task file alone and the `ubuntu_lxc` case runs the whole `update` entry point. Each case asserts the fact that decides the upgrade and that `pvesh` was run, with `--source active`, only when it should be. It does not assert that the apt task itself was skipped. The stub stands for the real answer, which no CI image has.
- Verify ends by running the role once with `system_baseline_journal_max_use: ""` after removing the drop-in, and asserts that no drop-in is written and that `systemd-journald` was not restarted. - Verify ends by running the role once with `system_baseline_journal_max_use: ""` after removing the drop-in, and asserts that no drop-in is written and that `systemd-journald` was not restarted.
- Verify runs the `reboot` entry point with `system_baseline_reboot_if_required: false`, without and with `/var/run/reboot-required`, and checks the fact and that the host did not reboot. - Verify runs the `reboot` entry point with `system_baseline_reboot_if_required: false`, without and with `/var/run/reboot-required`, and checks the fact and that the host did not reboot.
- The `pve` origins pin is applied to the Ubuntu container and read back with `apt-config dump`, then removed again. The package blacklist is written, read back as a list, left alone by a second run and removed by an empty list. - The `pve` origins pin is applied to the Ubuntu container and read back with `apt-config dump`, then removed again. The package blacklist is written, read back as a list, left alone by a second run and removed by an empty list.
@@ -2,6 +2,7 @@
- name: Converge the LXC profile - name: Converge the LXC profile
hosts: all hosts: all
gather_facts: true gather_facts: true
gather_subset: [min]
vars: vars:
system_baseline_system_type: ubuntu_lxc system_baseline_system_type: ubuntu_lxc
system_baseline_extra_packages: [jq] system_baseline_extra_packages: [jq]
@@ -1,7 +1,7 @@
--- ---
# One case of the vzdump guard: a pvesh stub answers with system_baseline_case_answer, the update entry point runs in check mode, and the # One case of the vzdump guard: a pvesh stub answers with system_baseline_case.answer, the role's tasks_from file (the guard alone unless the
# fact that decides the upgrade, and whether pvesh was asked at all, are compared with what the case expects. Kept outside the role's own tasks: # case names update) runs in check mode, and the fact that decides the upgrade, and whether pvesh was asked at all, are compared with what the
# no CI image is a Proxmox node, so the stub stands for the real `pvesh get /nodes/<node>/tasks` answer. # case expects. Kept outside the role's own tasks: no CI image is a Proxmox node, so the stub stands for the real `pvesh get` answer.
- name: Write the pvesh stub - name: Write the pvesh stub
check_mode: false check_mode: false
ansible.builtin.copy: ansible.builtin.copy:
@@ -14,8 +14,9 @@
{{ system_baseline_case.answer | to_json }} {{ system_baseline_case.answer | to_json }}
JSON JSON
- name: Create the apt scratch directory, which a check mode run does not - name: Create the apt scratch directory, which a check mode run of the update entry point does not
check_mode: false check_mode: false
when: system_baseline_case.tasks_from | default('vzdump_guard') == 'update'
ansible.builtin.file: ansible.builtin.file:
path: /var/cache/system-baseline-apt-tmp path: /var/cache/system-baseline-apt-tmp
state: directory state: directory
@@ -26,13 +27,13 @@
path: /var/tmp/pvesh-calls path: /var/tmp/pvesh-calls
state: absent state: absent
- name: Run the update entry point in check mode - name: Run the case's tasks in check mode
check_mode: true check_mode: true
block: block:
- name: Include system_baseline, tasks_from update - name: Include system_baseline, tasks_from {{ system_baseline_case.tasks_from | default('vzdump_guard') }}
ansible.builtin.include_role: ansible.builtin.include_role:
name: mortis.kamino.system_baseline name: mortis.kamino.system_baseline
tasks_from: update tasks_from: "{{ system_baseline_case.tasks_from | default('vzdump_guard') }}"
vars: vars:
system_baseline_system_type: "{{ system_baseline_case.type }}" system_baseline_system_type: "{{ system_baseline_case.type }}"
system_baseline_skip_upgrade_during_vzdump: "{{ system_baseline_case.input }}" system_baseline_skip_upgrade_during_vzdump: "{{ system_baseline_case.input }}"
@@ -464,6 +464,19 @@
- system_baseline_verify_update_tasks is search('(?m)^ ansible.builtin.meta:\sreset_connection$') - system_baseline_verify_update_tasks is search('(?m)^ ansible.builtin.meta:\sreset_connection$')
quiet: true quiet: true
# The guard cases below run vzdump_guard.yml alone, so this holds the wiring: the guard is imported before the upgrade, and the upgrade
# task's when reads the guard's fact.
- name: The vzdump guard is imported before the upgrade, and the upgrade waits on its fact
ansible.builtin.assert:
that:
- >-
system_baseline_verify_update_tasks is search('(?ms)^ ansible\.builtin\.import_tasks:\svzdump_guard\.yml$'
~ '.*^- name:\sUpdate & upgrade apt packages$')
- >-
system_baseline_verify_update_tasks is search('(?m)^- name:\sUpdate & upgrade apt packages\n(?: .*\n)*?'
~ ' - not \(__system_baseline_vzdump_running \| default\(false\)\)$')
quiet: true
# The reboot entry point is a supported interface: with system_baseline_reboot_if_required # The reboot entry point is a supported interface: with system_baseline_reboot_if_required
# false it only sets system_baseline_reboot_required. Here and not in converge, because it # false it only sets system_baseline_reboot_required. Here and not in converge, because it
# creates and removes the marker file, which the idempotence run would report as a change. # creates and removes the marker file, which the idempotence run would report as a change.
@@ -471,6 +484,7 @@
- name: The reboot entry point only computes the fact when told not to reboot - name: The reboot entry point only computes the fact when told not to reboot
hosts: all hosts: all
gather_facts: true gather_facts: true
gather_subset: [min]
tasks: tasks:
- name: Remove the reboot marker - name: Remove the reboot marker
ansible.builtin.file: ansible.builtin.file:
@@ -785,7 +799,8 @@
tags: always tags: always
# The vzdump guard (system_baseline_skip_upgrade_during_vzdump): a running backup is a vzdump task without an endtime. With the input off, or on # The vzdump guard (system_baseline_skip_upgrade_during_vzdump): a running backup is a vzdump task without an endtime. With the input off, or on
# a system type other than pve, pvesh is never run. Only the decision is asserted: the upgrade itself is not run in CI. # a system type other than pve, pvesh is never run. Only the decision is asserted: the upgrade itself is not run in CI. The cases run the guard
# alone; the last one runs the update entry point, so it still runs end to end in check mode.
- name: The vzdump guard skips the upgrade only for a running backup on a pve node - name: The vzdump guard skips the upgrade only for a running backup on a pve node
hosts: all hosts: all
gather_facts: false gather_facts: false
@@ -801,7 +816,7 @@
- {type: pve, input: true, running: false, asked: true, answer: [{type: qmstart, upid: b, starttime: 1}]} - {type: pve, input: true, running: false, asked: true, answer: [{type: qmstart, upid: b, starttime: 1}]}
- {type: pve, input: true, running: false, asked: true, answer: []} - {type: pve, input: true, running: false, asked: true, answer: []}
- {type: pve, input: false, running: false, asked: false, answer: [{type: vzdump, upid: a, starttime: 1}]} - {type: pve, input: false, running: false, asked: false, answer: [{type: vzdump, upid: a, starttime: 1}]}
- {type: ubuntu_lxc, input: true, running: false, asked: false, answer: [{type: vzdump, upid: a, starttime: 1}]} - {type: ubuntu_lxc, input: true, running: false, asked: false, answer: [{type: vzdump, upid: a, starttime: 1}], tasks_from: update}
# An empty system_baseline_journal_max_use leaves journald alone: with the drop-in gone, the role neither writes it again nor restarts # An empty system_baseline_journal_max_use leaves journald alone: with the drop-in gone, the role neither writes it again nor restarts
# systemd-journald. It runs last, because it applies the role with its defaults (the converge's tmux autostart and apt-daily timeout are # systemd-journald. It runs last, because it applies the role with its defaults (the converge's tmux autostart and apt-daily timeout are
@@ -810,6 +825,7 @@
- name: An empty journal size cap leaves journald alone - name: An empty journal size cap leaves journald alone
hosts: all hosts: all
gather_facts: true gather_facts: true
gather_subset: [min]
tasks: tasks:
- name: Remove the drop-in and its directory - name: Remove the drop-in and its directory
ansible.builtin.file: ansible.builtin.file:
+5 -3
View File
@@ -12,11 +12,13 @@
manager: auto manager: auto
become: true become: true
# One apt call for every unwanted package that is installed, skipped when none is.
- name: Remove unnecessary packages if installed - name: Remove unnecessary packages if installed
ansible.builtin.package: ansible.builtin.package:
name: "{{ item }}" name: "{{ __system_baseline_purge_present }}"
state: absent state: absent
purge: true purge: true
loop: "{{ __system_baseline_purge_packages }}" vars:
when: item in ansible_facts.packages __system_baseline_purge_present: "{{ __system_baseline_purge_packages | select('in', ansible_facts.packages) | list }}"
when: __system_baseline_purge_present | length > 0
become: true become: true
+3 -51
View File
@@ -21,57 +21,9 @@
mode: "0700" mode: "0700"
become: true become: true
# Opt-in guard (system_baseline_skip_upgrade_during_vzdump, pve only): an upgrade can restart Proxmox services while a backup holds a snapshot # import_tasks, not include_tasks: the update tag, the caller's when and __system_baseline_main_flow must reach the guard's tasks.
# of a guest, so the upgrade waits for the next run when this node has a vzdump task without an end time. Both tasks read state only, so - name: Decide whether a vzdump backup holds back the upgrade
# they run in check mode too; they are skipped where the upgrade is (a dry run of the main flow). `localhost` is the node's own alias, so no ansible.builtin.import_tasks: vzdump_guard.yml
# node name and no gathered facts are needed. --source active lists the running tasks: the default, archive, holds only finished ones. The
# fact is set on every run, so a guard that is off or skipped never inherits the answer of an earlier run in the same play.
- name: List the recent Proxmox tasks of this node
ansible.builtin.command:
argv:
- pvesh
- get
- /nodes/localhost/tasks
- --source
- active
- --limit
- "0"
- --output-format
- json
register: __system_baseline_pve_tasks
changed_when: false
check_mode: false
become: true
when:
- system_baseline_skip_upgrade_during_vzdump | bool
- system_baseline_system_type | default('') == 'pve'
- not (ansible_check_mode and __system_baseline_main_flow | default(false))
- name: Check that pvesh answered with a list of tasks
ansible.builtin.assert:
that:
- __system_baseline_pve_tasks.stdout | from_json is sequence
- __system_baseline_pve_tasks.stdout | from_json is not string
- __system_baseline_pve_tasks.stdout | from_json is not mapping
fail_msg: pvesh did not answer with a JSON list of tasks, so the role cannot tell whether a backup is running.
quiet: true
when: __system_baseline_pve_tasks is not skipped
- name: Note whether a vzdump backup is running on this node
ansible.builtin.set_fact:
__system_baseline_vzdump_running: >-
{{ __system_baseline_pve_tasks is not skipped
and (__system_baseline_pve_tasks.stdout | from_json
| selectattr('type', 'equalto', 'vzdump')
| rejectattr('endtime', 'defined')
| list | length) > 0 }}
- name: Skip the upgrade while a vzdump backup is running
ansible.builtin.debug:
msg: >-
Skipping the apt upgrade on {{ inventory_hostname }}: a vzdump task is running on this node. Run the update again after the backup
has finished.
when: __system_baseline_vzdump_running | default(false)
# safe is the apt module's name for the plain upgrade (apt-get upgrade --with-new-pkgs), what `true` meant here before; dist runs # safe is the apt module's name for the plain upgrade (apt-get upgrade --with-new-pkgs), what `true` meant here before; dist runs
# apt-get dist-upgrade (profile key apt_upgrade, `pve` by default). # apt-get dist-upgrade (profile key apt_upgrade, `pve` by default).
@@ -0,0 +1,52 @@
---
# Opt-in guard (system_baseline_skip_upgrade_during_vzdump, pve only): an upgrade can restart Proxmox services while a backup holds a snapshot
# of a guest, so the upgrade waits for the next run when this node has a vzdump task without an end time. Both tasks read state only, so
# they run in check mode too; they are skipped where the upgrade is (a dry run of the main flow). `localhost` is the node's own alias, so no
# node name and no gathered facts are needed. --source active lists the running tasks: the default, archive, holds only finished ones. The
# fact is set on every run, so a guard that is off or skipped never inherits the answer of an earlier run in the same play.
- name: List the recent Proxmox tasks of this node
ansible.builtin.command:
argv:
- pvesh
- get
- /nodes/localhost/tasks
- --source
- active
- --limit
- "0"
- --output-format
- json
register: __system_baseline_pve_tasks
changed_when: false
check_mode: false
become: true
when:
- system_baseline_skip_upgrade_during_vzdump | bool
- system_baseline_system_type | default('') == 'pve'
- not (ansible_check_mode and __system_baseline_main_flow | default(false))
- name: Check that pvesh answered with a list of tasks
ansible.builtin.assert:
that:
- __system_baseline_pve_tasks.stdout | from_json is sequence
- __system_baseline_pve_tasks.stdout | from_json is not string
- __system_baseline_pve_tasks.stdout | from_json is not mapping
fail_msg: pvesh did not answer with a JSON list of tasks, so the role cannot tell whether a backup is running.
quiet: true
when: __system_baseline_pve_tasks is not skipped
- name: Note whether a vzdump backup is running on this node
ansible.builtin.set_fact:
__system_baseline_vzdump_running: >-
{{ __system_baseline_pve_tasks is not skipped
and (__system_baseline_pve_tasks.stdout | from_json
| selectattr('type', 'equalto', 'vzdump')
| rejectattr('endtime', 'defined')
| list | length) > 0 }}
- name: Skip the upgrade while a vzdump backup is running
ansible.builtin.debug:
msg: >-
Skipping the apt upgrade on {{ inventory_hostname }}: a vzdump task is running on this node. Run the update again after the backup
has finished.
when: __system_baseline_vzdump_running | default(false)
+3 -2
View File
@@ -80,14 +80,14 @@ Update or remove: pass `-e traefik_update=true`, or `-e "traefik_remove=true tra
## Tests ## Tests
The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It needs outbound network: the role installs packages with apt and the converge downloads the real Traefik release from GitHub. Converge runs `mortis.kamino.ufw`, then the role. It runs `check` before the converge (on a fresh host) and after it (on the configured host). Verify covers: The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It needs outbound network: the role installs packages with apt and the converge downloads the real Traefik release from GitHub. Prepare runs `mortis.kamino.ufw`, so converge runs only the role. It runs `check` before the converge (on a fresh host) and after it (on the configured host). Verify covers:
- The input guards, first: one play expects the failure message containing `unauthenticated Traefik dashboard` (the dashboard guard: enabled without valid `user:hash` users); the next expects `collides with the middleware`, raised by the dashboard-auth collision assert, which runs whenever users are set, also with the dashboard off. - The input guards, first: one play expects the failure message containing `unauthenticated Traefik dashboard` (the dashboard guard: enabled without valid `user:hash` users); the next expects `collides with the middleware`, raised by the dashboard-auth collision assert, which runs whenever users are set, also with the dashboard off.
- The install: the pinned version runs, and only the binary is left from the archive. - The install: the pinned version runs, and only the binary is left from the archive.
- Files: `traefik.env` mode 0600 owned by root, `dynamic.yml` mode 0600 owned by `traefik`, `traefik.yml` mode 0600, the binary mode 0755; the logrotate configuration, which `logrotate --debug` parses. - Files: `traefik.env` mode 0600 owned by root, `dynamic.yml` mode 0600 owned by `traefik`, `traefik.yml` mode 0600, the binary mode 0755; the logrotate configuration, which `logrotate --debug` parses.
- Rendering: the ACME resolvers render when set and are absent when empty; the dashboard is off by default with the extra app routed, and renders behind basicAuth when enabled (a template render, not a running dashboard). - Rendering: the ACME resolvers render when set and are absent when empty; the dashboard is off by default with the extra app routed, and renders behind basicAuth when enabled (a template render, not a running dashboard).
- The service: running and enabled with `NoNewPrivileges`, `MemoryDenyWriteExecute` and `CAP_NET_BIND_SERVICE`, listening on 80 and 443 and redirecting http to https; ufw allows 80 and 443 next to SSH, with the traefik owner tag, in order. - The service: running and enabled with `NoNewPrivileges`, `MemoryDenyWriteExecute` and `CAP_NET_BIND_SERVICE`, listening on 80 and 443 and redirecting http to https; ufw allows 80 and 443 next to SSH, with the traefik owner tag, in order.
- The update path: it updates to another release and back with `traefik_update` (download from local `file://` stand-in releases, checksum check and swap) and asserts the version, an active unit and no leftovers. It leaves the stand-in stub installed, so nothing after it asserts real Traefik behaviour. - The update path: it updates to another release with `traefik_update` (download from local `file://` stand-in releases, checksum check and swap) and asserts the version, an active unit and no leftovers. It leaves the stand-in stub installed, so nothing after it asserts real Traefik behaviour.
- The remove path, last: unit and binary are deleted, the service is no longer active, and only the traefik ufw rules are removed. - The remove path, last: unit and binary are deleted, the service is no longer active, and only the traefik ufw rules are removed.
The scenario disables the namespace-based sandboxing and the `User=` switch with a drop-in because its container is unprivileged, so that sandboxing is not covered by CI. Certificate issuance is not covered: the Cloudflare credentials are dummies. The scenario disables the namespace-based sandboxing and the `User=` switch with a drop-in because its container is unprivileged, so that sandboxing is not covered by CI. Certificate issuance is not covered: the Cloudflare credentials are dummies.
@@ -96,6 +96,7 @@ The scenario disables the namespace-based sandboxing and the `User=` switch with
- Idempotent: yes. - Idempotent: yes.
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. On a host without the Traefik binary, the ACME file permissions, the service start and its running check, the `Restart Traefik` handler and the `traefik_update` tasks are skipped under `--check`, because nothing is extracted and the unit file is only simulated. - Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. On a host without the Traefik binary, the ACME file permissions, the service start and its running check, the `Restart Traefik` handler and the `traefik_update` tasks are skipped under `--check`, because nothing is extracted and the unit file is only simulated.
- The role does not refresh an APT cache younger than an hour, so a package from a source you add just before the role (`ansible.builtin.deb822_repository` does not refresh) needs your own cache refresh first.
- The role is not a state selector. `main.yml` runs prerequisites and configure unless `traefik_remove` is true; install runs only when the binary is absent; update only when `traefik_update` is true; remove only when `traefik_remove` is true, and then every other task in `main.yml` is skipped. - The role is not a state selector. `main.yml` runs prerequisites and configure unless `traefik_remove` is true; install runs only when the binary is absent; update only when `traefik_update` is true; remove only when `traefik_remove` is true, and then every other task in `main.yml` is skipped.
- Download integrity: the archive SHA-256 must appear in the release's checksum file or the play fails. - Download integrity: the archive SHA-256 must appear in the release's checksum file or the play fails.
- Secrets: `traefik.env` (mode 0600, root) and `dynamic.yml` are rendered with `no_log: true`, and no backups are kept, so `--diff` never shows them. `dynamic.yml` may hold dashboard htpasswd hashes. - Secrets: `traefik.env` (mode 0600, root) and `dynamic.yml` are rendered with `no_log: true`, and no backups are kept, so `--diff` never shows them. `dynamic.yml` may hold dashboard htpasswd hashes.
+3 -5
View File
@@ -1,12 +1,10 @@
--- ---
# Role variables come from the inventory group_vars in molecule.yml, so the idempotence step # Role variables come from the inventory group_vars in molecule.yml, so the idempotence step
# reruns converge with identical configuration; verify's plays override only what they test. # reruns converge with identical configuration; verify's plays override only what they test.
# The base ufw play comes first: traefik passes its rules through the mortis.kamino.ufw # mortis.kamino.ufw runs in prepare.yml, so only traefik counts toward idempotence. Facts are
# service_rules entry point, which needs ufw installed and active. ufw_rules comes from the # off: neither the role nor the roles it includes reads any.
# same group_vars (the SSH allow rule the lock-out guard requires).
- name: Converge - name: Converge
hosts: all hosts: all
gather_facts: true gather_facts: false
roles: roles:
- role: mortis.kamino.ufw
- role: mortis.kamino.traefik - role: mortis.kamino.traefik
+7 -6
View File
@@ -3,7 +3,7 @@
# (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in # (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# .gitea/workflows/molecule.yml. Needs outbound network, unlike most scenarios: the role installs # .gitea/workflows/molecule.yml. Needs outbound network, unlike most scenarios: the role installs
# packages with apt and the converge downloads the Traefik release from GitHub (verify's update # packages with apt and the converge downloads the Traefik release from GitHub (verify's update
# path uses file:// stand-ins built by prepare.yml). No privileged mode: systemd needs a writable # path uses a file:// stand-in built by prepare.yml). No privileged mode: systemd needs a writable
# cgroup and the firewall tools need NET_ADMIN. # cgroup and the firewall tools need NET_ADMIN.
driver: driver:
name: docker name: docker
@@ -44,9 +44,10 @@ platforms:
- apparmor=unconfined - apparmor=unconfined
provisioner: provisioner:
name: ansible name: ansible
# One source for every play in converge.yml and verify.yml. The role renders traefik.yml before # One source for the prepare plays that read them, converge.yml and verify.yml. The role renders
# its dashboard-auth collision check, so that guard play with other values would change it (and # traefik.yml before its dashboard-auth collision check, so that guard play with other values
# restart Traefik) before verify's assertions; converge's values must also stay fixed for idempotence. # would change it (and restart Traefik) before verify's assertions; converge's values must also
# stay fixed for idempotence.
inventory: inventory:
group_vars: group_vars:
all: all:
@@ -55,8 +56,8 @@ provisioner:
traefik_cloudflare_email: [email protected] traefik_cloudflare_email: [email protected]
traefik_cloudflare_api_token: molecule-not-a-token traefik_cloudflare_api_token: molecule-not-a-token
traefik_domain: example.test traefik_domain: example.test
# Any release other than the role default: verify's update path goes there and back, # Any release other than the role default: verify's update path goes there, from the
# from the stand-ins prepare.yml builds. # stand-in prepare.yml builds.
traefik_verify_other_version: v3.7.18 traefik_verify_other_version: v3.7.18
ufw_rules: ufw_rules:
- {rule: allow, port: 22, proto: tcp, comment: ssh} - {rule: allow, port: 22, proto: tcp, comment: ssh}
+18 -19
View File
@@ -41,26 +41,34 @@
ReadWritePaths= ReadWritePaths=
User= User=
# Stand-in releases for verify's update path, behind file:// URLs: the role's download, checksum # traefik passes its rules through the mortis.kamino.ufw service_rules entry point, which needs ufw
# check and swap run unchanged, without fetching two more real releases per host. The converge # installed and active. ufw_rules comes from the inventory group_vars (the SSH allow rule the
# lock-out guard requires); the ufw scenario tests that role, so it runs once here, not in converge.
- name: Install and enable ufw
hosts: all
gather_facts: false
roles:
- role: mortis.kamino.ufw
# A stand-in release for verify's update path, behind a file:// URL: the role's download, checksum
# check and swap run unchanged, without fetching another real release per host. The converge
# still downloads the real role default from GitHub. # still downloads the real role default from GitHub.
- name: Prepare the stand-in releases - name: Prepare the stand-in release
hosts: all hosts: all
gather_facts: false gather_facts: false
vars_files: vars_files:
- ../../defaults/main.yml - ../../defaults/main.yml
vars:
traefik_test_release: "{{ traefik_verify_other_version }}"
tasks: tasks:
- name: Create a directory per stand-in release - name: Create the stand-in release directory
ansible.builtin.file: ansible.builtin.file:
path: "/opt/molecule-download/{{ traefik_test_release }}" path: "/opt/molecule-download/{{ traefik_test_release }}"
state: directory state: directory
mode: "0755" mode: "0755"
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
loop_control:
loop_var: traefik_test_release
# Answers `version` like Traefik and otherwise stays up like the service. # Answers `version` like Traefik and otherwise stays up like the service.
- name: Write the stand-in binaries - name: Write the stand-in binary
ansible.builtin.copy: ansible.builtin.copy:
dest: "/opt/molecule-download/{{ traefik_test_release }}/traefik" dest: "/opt/molecule-download/{{ traefik_test_release }}/traefik"
mode: "0755" mode: "0755"
@@ -70,25 +78,16 @@
version) echo "Version: {{ traefik_test_release | regex_replace('^v', '') }}" ;; version) echo "Version: {{ traefik_test_release | regex_replace('^v', '') }}" ;;
*) exec sleep infinity ;; *) exec sleep infinity ;;
esac esac
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
loop_control:
loop_var: traefik_test_release
- name: Pack the stand-in archives - name: Pack the stand-in archive
ansible.builtin.command: ansible.builtin.command:
argv: [tar, -czf, "{{ traefik_test_archive }}", -C, "/opt/molecule-download/{{ traefik_test_release }}", traefik] argv: [tar, -czf, "{{ traefik_test_archive }}", -C, "/opt/molecule-download/{{ traefik_test_release }}", traefik]
creates: "{{ traefik_test_archive }}" creates: "{{ traefik_test_archive }}"
vars: vars:
traefik_test_archive: "/opt/molecule-download/{{ traefik_test_release }}/traefik_{{ traefik_test_release }}_{{ traefik_os }}_{{ traefik_arch }}.tar.gz" traefik_test_archive: "/opt/molecule-download/{{ traefik_test_release }}/traefik_{{ traefik_test_release }}_{{ traefik_os }}_{{ traefik_arch }}.tar.gz"
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
loop_control:
loop_var: traefik_test_release
- name: Write the checksums files in the release format - name: Write the checksums file in the release format
ansible.builtin.shell: ansible.builtin.shell:
cmd: sha256sum traefik_*.tar.gz > traefik_{{ traefik_test_release }}_checksums.txt cmd: sha256sum traefik_*.tar.gz > traefik_{{ traefik_test_release }}_checksums.txt
chdir: "/opt/molecule-download/{{ traefik_test_release }}" chdir: "/opt/molecule-download/{{ traefik_test_release }}"
creates: "traefik_{{ traefik_test_release }}_checksums.txt" creates: "traefik_{{ traefik_test_release }}_checksums.txt"
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
loop_control:
loop_var: traefik_test_release
+7 -10
View File
@@ -293,11 +293,11 @@
traefik_ufw_key_443: "{{ ('allow|443|||||in' | hash('sha1'))[:10] }}" traefik_ufw_key_443: "{{ ('allow|443|||||in' | hash('sha1'))[:10] }}"
traefik_ufw_tagged: "{{ traefik_ufw_added.stdout_lines | select('match', '^ufw ') | select('search', 'ansible-ufw') | list }}" traefik_ufw_tagged: "{{ traefik_ufw_added.stdout_lines | select('match', '^ufw ') | select('search', 'ansible-ufw') | list }}"
# A version bump through the update path and mortis.kamino._binary_update: down to another # A version bump through the update path and mortis.kamino._binary_update: to another release
# release and back to the role default, both with traefik_update, from prepare.yml's stand-ins. # with traefik_update, from prepare.yml's stand-in. One bump covers the download, checksum check
# After the idempotence step, because each run changes the binary, and before the remove path. # and swap. After the idempotence step, because it changes the binary, and before the remove path.
# It leaves the stand-in stub installed, so nothing after it may assert real Traefik behaviour. # It leaves the stand-in stub installed, so nothing after it may assert real Traefik behaviour.
- name: Verify the update path with stand-in releases - name: Verify the update path with a stand-in release
hosts: all hosts: all
gather_facts: false gather_facts: false
vars_files: vars_files:
@@ -309,13 +309,10 @@
fail_msg: Move traefik_verify_other_version off the role default ({{ traefik_version }}). fail_msg: Move traefik_verify_other_version off the role default ({{ traefik_version }}).
quiet: true quiet: true
- name: Update to the other release, then back to the role default - name: Update to the other release
ansible.builtin.include_tasks: tasks/update_and_check.yml ansible.builtin.include_tasks: tasks/update_and_check.yml
loop: vars:
- "{{ traefik_verify_other_version }}" traefik_verify_target: "{{ traefik_verify_other_version }}"
- "{{ traefik_version }}"
loop_control:
loop_var: traefik_verify_target
# The remove path. Last on purpose: it destroys what the plays above verify, and it runs # The remove path. Last on purpose: it destroys what the plays above verify, and it runs
# once, outside the idempotence step (a converge play that changed state would fail that step). # once, outside the idempotence step (a converge play that changed state would fail that step).
+1
View File
@@ -11,6 +11,7 @@
- logrotate - logrotate
state: present state: present
update_cache: true update_cache: true
cache_valid_time: 3600
tags: [traefik, prereqs, always] tags: [traefik, prereqs, always]
- name: Create Traefik group - name: Create Traefik group
+18 -73
View File
@@ -2,7 +2,8 @@
# Only runs that apply the role; the refusal cases are in verify.yml. # Only runs that apply the role; the refusal cases are in verify.yml.
- name: Converge with an SSH rule and service rules - name: Converge with an SSH rule and service rules
hosts: all hosts: all
gather_facts: true # The role reads no facts; ufw_ssh_port defaults from ansible_port.
gather_facts: false
roles: roles:
- role: mortis.kamino.ufw - role: mortis.kamino.ufw
vars: vars:
@@ -17,14 +18,15 @@
# no proto: both protocols, and the guard must cope with the key missing # no proto: both protocols, and the guard must cope with the key missing
- {rule: allow, port: 9090, comment: metrics} - {rule: allow, port: 9090, comment: metrics}
# The service_rules entry point. prepare.yml stored a stale rule for svc_c, # The service_rules entry point. prepare.yml stored a stale rule for svc_a, stale rules for
# a rule of the removed service svc_d and a stale rule for svc_e, so every pass here # svc_c and a rule of the removed service svc_d, so every pass here is a no-op after the
# is a no-op after the first one, purge included. # first one, purge included. svc_c purges after svc_a ran, so svc_a's stale rule surviving
# proves a purge touches only its own owner.
- name: Converge the rules of several services through the entry point - name: Converge the rules of several services through the entry point
hosts: all hosts: all
gather_facts: false gather_facts: false
tasks: tasks:
- name: Two rules for svc_a - name: Keep the stale rule of svc_a because purging is off
ansible.builtin.include_role: ansible.builtin.include_role:
name: mortis.kamino.ufw name: mortis.kamino.ufw
tasks_from: service_rules tasks_from: service_rules
@@ -33,18 +35,16 @@
ufw_service_rules: ufw_service_rules:
- {rule: allow, port: 8001, proto: tcp, comment: alpha web} - {rule: allow, port: 8001, proto: tcp, comment: alpha web}
- {rule: allow, port: 8002, proto: udp, from: 10.1.0.0/16, comment: alpha dns} - {rule: allow, port: 8002, proto: udp, from: 10.1.0.0/16, comment: alpha dns}
- name: Two rules for svc_b, one without a comment
ansible.builtin.include_role:
name: mortis.kamino.ufw
tasks_from: service_rules
vars:
ufw_service_name: svc_b
ufw_service_rules:
- {rule: allow, port: 8003, proto: tcp, comment: beta} - {rule: allow, port: 8003, proto: tcp, comment: beta}
# No comment and no proto: the tag alone, and both protocols.
- {rule: deny, port: 8004} - {rule: deny, port: 8004}
# A comment that mentions the SSH port on another port.
- {rule: allow, port: 8022, proto: tcp, comment: forward to 22 here}
- {rule: allow, port: 7201, proto: tcp, comment: epsilon}
- name: Keep one rule for svc_c and purge its stale rule # Of the stale rules, only 7001 and 7601 are single numeric ports; the SSH lookalike, the
# rule with no port, the source-only rule and the range are kept as possible SSH paths.
- name: Purge the stale rules of svc_c except those that may carry SSH
ansible.builtin.include_role: ansible.builtin.include_role:
name: mortis.kamino.ufw name: mortis.kamino.ufw
tasks_from: service_rules tasks_from: service_rules
@@ -53,6 +53,8 @@
ufw_purge_stale: true ufw_purge_stale: true
ufw_service_rules: ufw_service_rules:
- {rule: allow, port: 7101, proto: tcp, comment: gamma} - {rule: allow, port: 7101, proto: tcp, comment: gamma}
- {rule: allow, port: 7301, proto: tcp, comment: eta}
- {rule: allow, port: 7602, proto: tcp, comment: desired}
- name: Remove svc_d, which deletes without ufw_purge_stale - name: Remove svc_d, which deletes without ufw_purge_stale
ansible.builtin.include_role: ansible.builtin.include_role:
@@ -62,50 +64,6 @@
ufw_service_name: svc_d ufw_service_name: svc_d
ufw_service_state: absent ufw_service_state: absent
- name: Keep the stale rule of svc_e because purging is off
ansible.builtin.include_role:
name: mortis.kamino.ufw
tasks_from: service_rules
vars:
ufw_service_name: svc_e
ufw_service_rules:
- {rule: allow, port: 7201, proto: tcp, comment: epsilon}
- name: A comment that mentions the SSH port on another port
ansible.builtin.include_role:
name: mortis.kamino.ufw
tasks_from: service_rules
vars:
ufw_service_name: svc_g
ufw_service_rules:
- {rule: allow, port: 8022, proto: tcp, comment: forward to 22 here}
- name: Purge svc_h without touching its stale rule that looks like the SSH rule
ansible.builtin.include_role:
name: mortis.kamino.ufw
tasks_from: service_rules
vars:
ufw_service_name: svc_h
ufw_purge_stale: true
ufw_service_rules:
- {rule: allow, port: 7301, proto: tcp, comment: eta}
- name: Purge svc_p but keep its stale rules that may carry SSH
hosts: all
gather_facts: false
tasks:
# prepare.yml stored four stale rules for svc_p: a numeric port (deleted), and a rule
# with no port, a source-only rule and a range, which are kept as possible SSH paths.
- name: Keep one rule for svc_p and purge its stale rules
ansible.builtin.include_role:
name: mortis.kamino.ufw
tasks_from: service_rules
vars:
ufw_service_name: svc_p
ufw_purge_stale: true
ufw_service_rules:
- {rule: allow, port: 7602, proto: tcp, comment: desired}
# The orphan_rules entry point. prepare.yml stored two rules of svc_o1, a rule of # The orphan_rules entry point. prepare.yml stored two rules of svc_o1, a rule of
# svc_o2 that looks like the SSH rule, and a rule of svc_m. The managed owners below are # svc_o2 that looks like the SSH rule, and a rule of svc_m. The managed owners below are
# the ones used above plus svc_m (listed but never called), so svc_o1 and svc_o2 are # the ones used above plus svc_m (listed but never called), so svc_o1 and svc_o2 are
@@ -118,14 +76,9 @@
vars: vars:
ufw_converge_managed: ufw_converge_managed:
- svc_a - svc_a
- svc_b
- svc_c - svc_c
- svc_d - svc_d
- svc_e
- svc_g
- svc_h
- svc_m - svc_m
- svc_p
tasks: tasks:
# The marker is written after the purge, so the expected counts are absolute on both # The marker is written after the purge, so the expected counts are absolute on both
# passes: svc_o1 holds 2 rules before the purge and 0 once the marker exists. # passes: svc_o1 holds 2 rules before the purge and 0 once the marker exists.
@@ -138,9 +91,6 @@
ansible.builtin.set_fact: ansible.builtin.set_fact:
ufw_conv_o1_initial: "{{ 0 if ufw_conv_marker.stat.exists else 2 }}" ufw_conv_o1_initial: "{{ 0 if ufw_conv_marker.stat.exists else 2 }}"
- name: Assert it before the first case
ansible.builtin.include_tasks: tasks/orphan_check.yml
- name: No managed owners given, purge requested - name: No managed owners given, purge requested
ansible.builtin.include_role: ansible.builtin.include_role:
name: mortis.kamino.ufw name: mortis.kamino.ufw
@@ -148,9 +98,6 @@
vars: vars:
ufw_purge_orphans: true ufw_purge_orphans: true
- name: Nothing was deleted without a list
ansible.builtin.include_tasks: tasks/orphan_check.yml
- name: An empty list of managed owners, purge requested - name: An empty list of managed owners, purge requested
ansible.builtin.include_role: ansible.builtin.include_role:
name: mortis.kamino.ufw name: mortis.kamino.ufw
@@ -159,9 +106,6 @@
ufw_managed_owners: [] ufw_managed_owners: []
ufw_purge_orphans: true ufw_purge_orphans: true
- name: Nothing was deleted with an empty list
ansible.builtin.include_tasks: tasks/orphan_check.yml
- name: Report the orphans only - name: Report the orphans only
ansible.builtin.include_role: ansible.builtin.include_role:
name: mortis.kamino.ufw name: mortis.kamino.ufw
@@ -170,7 +114,8 @@
ufw_managed_owners: "{{ ufw_converge_managed }}" ufw_managed_owners: "{{ ufw_converge_managed }}"
ufw_purge_orphans: false ufw_purge_orphans: false
- name: Reporting deleted nothing # The counts are absolute, so one check proves none of the three cases above deleted.
- name: The cases without a purge deleted nothing
ansible.builtin.include_tasks: tasks/orphan_check.yml ansible.builtin.include_tasks: tasks/orphan_check.yml
- name: Purge the orphans - name: Purge the orphans
+13 -12
View File
@@ -39,9 +39,9 @@
proto: tcp proto: tcp
comment: replaced comment: replaced
# Owners svc_c, svc_d and svc_e keep rules in converge.yml that these entries are # Owners svc_a, svc_c and svc_d keep rules in converge.yml that these entries are
# not part of: a stale rule to purge, a rule of a removed service, a stale rule # not part of: a stale rule that is only reported, stale rules to purge, a rule of
# that is only reported. # a removed service.
- name: Store tagged rules that are no longer wanted - name: Store tagged rules that are no longer wanted
community.general.ufw: community.general.ufw:
rule: allow rule: allow
@@ -56,9 +56,10 @@
# svc_c: the old spec of a rule whose port changed (key of allow|7001|tcp||||in) # svc_c: the old spec of a rule whose port changed (key of allow|7001|tcp||||in)
- {port: 7001, comment: "ansible-ufw[svc_c:128c086248]: old"} - {port: 7001, comment: "ansible-ufw[svc_c:128c086248]: old"}
- {port: 7002, comment: "ansible-ufw[svc_d:abcdef0123]: gone"} - {port: 7002, comment: "ansible-ufw[svc_d:abcdef0123]: gone"}
- {port: 7003, comment: "ansible-ufw[svc_e:aaaaaaaaaa]: kept"} # svc_a: a stale rule kept because svc_a does not purge, while svc_c's purge runs
# svc_h: a stale rule that looks like an SSH rule, which a purge must skip - {port: 7003, comment: "ansible-ufw[svc_a:aaaaaaaaaa]: kept"}
- {port: 22, from: 10.9.0.0/16, comment: "ansible-ufw[svc_h:bbbbbbbbbb]: old"} # svc_c: a stale rule that looks like an SSH rule, which a purge must skip
- {port: 22, from: 10.9.0.0/16, comment: "ansible-ufw[svc_c:bbbbbbbbbb]: old"}
# orphan_rules: svc_o1 and svc_o2 are never listed as managed owners in converge.yml. # orphan_rules: svc_o1 and svc_o2 are never listed as managed owners in converge.yml.
# svc_o2's rule looks like the SSH rule and must survive a purge; svc_m is managed # svc_o2's rule looks like the SSH rule and must survive a purge; svc_m is managed
# but its role is never called, so its rule must survive too. # but its role is never called, so its rule must survive too.
@@ -73,11 +74,11 @@
- {from: 10.20.0.0/24, comment: "ansible-ufw[svc_o3:5555555552]: source only"} - {from: 10.20.0.0/24, comment: "ansible-ufw[svc_o3:5555555552]: source only"}
- {port: "20:30", comment: "ansible-ufw[svc_o3:5555555553]: range over 22"} - {port: "20:30", comment: "ansible-ufw[svc_o3:5555555553]: range over 22"}
- {name: OrphanOpenSSH, comment: "ansible-ufw[svc_o3:5555555554]: openssh profile"} - {name: OrphanOpenSSH, comment: "ansible-ufw[svc_o3:5555555554]: openssh profile"}
# service_rules purge of svc_p (converge.yml keeps only a rule for 7602): 7601 is stale # svc_c again: 7601 is stale and deleted by its purge, the other three are stale and
# and deleted, the other three are stale and may carry SSH, so they stay. # may carry SSH, so they stay.
- {port: 7601, comment: "ansible-ufw[svc_p:6666666664]: stale numeric"} - {port: 7601, comment: "ansible-ufw[svc_c:6666666664]: stale numeric"}
- {interface: wg0, direction: in, comment: "ansible-ufw[svc_p:6666666661]: no port"} - {interface: wg0, direction: in, comment: "ansible-ufw[svc_c:6666666661]: no port"}
- {from: 10.30.0.0/24, comment: "ansible-ufw[svc_p:6666666662]: source only"} - {from: 10.30.0.0/24, comment: "ansible-ufw[svc_c:6666666662]: source only"}
- {port: "40:50", comment: "ansible-ufw[svc_p:6666666663]: range"} - {port: "40:50", comment: "ansible-ufw[svc_c:6666666663]: range"}
loop_control: loop_control:
loop_var: ufw_prepare_rule loop_var: ufw_prepare_rule
@@ -1,9 +1,9 @@
--- ---
# Included by converge.yml and verify.yml after each orphan_rules case. The counts are # Included by converge.yml around the orphan_rules cases. The counts are absolute: svc_o1
# absolute: svc_o1 holds ufw_conv_o1_want rules (default ufw_conv_o1_initial: 2 before the # holds ufw_conv_o1_want rules (default ufw_conv_o1_initial: 2 before the purge, 0 after),
# purge, 0 after), and the tagged total is 20 plus those. The 20: svc_a 2, svc_b 2, svc_c 1, # and the tagged total is 20 plus those. The 20: svc_a 7 (six desired, one stale), svc_c 7
# svc_e 2, svc_g 1, svc_h 2, svc_m 1, svc_o2 1, svc_o3 4 (kept orphans that may carry SSH), # (three desired, four stale kept as possible SSH paths), svc_m 1, svc_o2 1, svc_o3 4 (kept
# svc_p 4 (its desired rule and three kept stale rules). # orphans that may carry SSH).
- name: Read the rules ufw would load - name: Read the rules ufw would load
ansible.builtin.command: ufw show added ansible.builtin.command: ufw show added
register: ufw_conv_added register: ufw_conv_added
@@ -18,8 +18,8 @@
- ufw_conv_added.stdout_lines | select('search', 'svc_o2:3333333333') | list | length == 1 - ufw_conv_added.stdout_lines | select('search', 'svc_o2:3333333333') | list | length == 1
- ufw_conv_added.stdout_lines | select('search', 'svc_o3:555555555[1-4]') | list | length == 4 - ufw_conv_added.stdout_lines | select('search', 'svc_o3:555555555[1-4]') | list | length == 4
- ufw_conv_added.stdout_lines | select('search', 'svc_m:4444444444') | list | length == 1 - ufw_conv_added.stdout_lines | select('search', 'svc_m:4444444444') | list | length == 1
- ufw_conv_added.stdout_lines | select('search', 'svc_p:666666666[123]') | list | length == 3 - ufw_conv_added.stdout_lines | select('search', 'svc_c:666666666[123]') | list | length == 3
- ufw_conv_added.stdout_lines | select('search', 'svc_p:6666666664') | list | length == 0 - ufw_conv_added.stdout_lines | select('search', 'svc_c:6666666664') | list | length == 0
- ufw_conv_added.stdout_lines | select('match', '^ufw ') | select('search', 'ansible-ufw') | list | length == 20 + ufw_conv_o1_count | int - ufw_conv_added.stdout_lines | select('match', '^ufw ') | select('search', 'ansible-ufw') | list | length == 20 + ufw_conv_o1_count | int
- ufw_conv_added.stdout_lines | select('match', '^ufw ') | reject('search', 'ansible-ufw') | list | length == 5 - ufw_conv_added.stdout_lines | select('match', '^ufw ') | reject('search', 'ansible-ufw') | list | length == 5
fail_msg: "Unexpected rules after the orphan_rules case: {{ ufw_conv_added.stdout_lines }}" fail_msg: "Unexpected rules after the orphan_rules case: {{ ufw_conv_added.stdout_lines }}"
+17 -24
View File
@@ -306,12 +306,6 @@
that: "'ufw_managed_owners must be a list of strings matching' in ufw_verify_failure" that: "'ufw_managed_owners must be a list of strings matching' in ufw_verify_failure"
quiet: true quiet: true
# Converge's last play purged svc_o1 (want 0); svc_o2, svc_m and the tagged total carry the proof.
- name: Nothing was deleted after the invalid owner
ansible.builtin.include_tasks: tasks/orphan_check.yml
vars:
ufw_conv_o1_want: 0
- name: Verify - name: Verify
hosts: all hosts: all
gather_facts: false gather_facts: false
@@ -385,12 +379,12 @@
that: that:
- ufw_verify_tagged | select('search', ufw_verify_svc_a_web) | list | length == 1 - ufw_verify_tagged | select('search', ufw_verify_svc_a_web) | list | length == 1
- 'ufw_verify_tagged | select("search", "8002.*ansible-ufw\[svc_a:[0-9a-f]{10}\]: alpha dns") | list | length == 1' - 'ufw_verify_tagged | select("search", "8002.*ansible-ufw\[svc_a:[0-9a-f]{10}\]: alpha dns") | list | length == 1'
- 'ufw_verify_tagged | select("search", "8003.*ansible-ufw\[svc_b:[0-9a-f]{10}\]: beta") | list | length == 1' - 'ufw_verify_tagged | select("search", "8003.*ansible-ufw\[svc_a:[0-9a-f]{10}\]: beta") | list | length == 1'
- 'ufw_verify_tagged | select("search", "8004.*ansible-ufw\[svc_b:[0-9a-f]{10}\]:.$") | list | length == 1' - 'ufw_verify_tagged | select("search", "8004.*ansible-ufw\[svc_a:[0-9a-f]{10}\]:.$") | list | length == 1'
- 'ufw_verify_tagged | select("search", "7201.*ansible-ufw\[svc_a:[0-9a-f]{10}\]: epsilon") | list | length == 1'
- 'ufw_verify_tagged | select("search", "8022/tcp comment .ansible-ufw\[svc_a:[0-9a-f]{10}\]: forward to 22 here") | list | length == 1'
- 'ufw_verify_tagged | select("search", "7101.*ansible-ufw\[svc_c:[0-9a-f]{10}\]: gamma") | list | length == 1' - 'ufw_verify_tagged | select("search", "7101.*ansible-ufw\[svc_c:[0-9a-f]{10}\]: gamma") | list | length == 1'
- 'ufw_verify_tagged | select("search", "7201.*ansible-ufw\[svc_e:[0-9a-f]{10}\]: epsilon") | list | length == 1' - 'ufw_verify_tagged | select("search", "7301.*ansible-ufw\[svc_c:[0-9a-f]{10}\]: eta") | list | length == 1'
- 'ufw_verify_tagged | select("search", "8022/tcp comment .ansible-ufw\[svc_g:[0-9a-f]{10}\]: forward to 22 here") | list | length == 1'
- 'ufw_verify_tagged | select("search", "7301.*ansible-ufw\[svc_h:[0-9a-f]{10}\]: eta") | list | length == 1'
quiet: true quiet: true
vars: vars:
ufw_verify_tagged: "{{ ufw_verify_added.stdout_lines | select('match', '^ufw ') | select('search', 'ansible-ufw') | list }}" ufw_verify_tagged: "{{ ufw_verify_added.stdout_lines | select('match', '^ufw ') | select('search', 'ansible-ufw') | list }}"
@@ -402,15 +396,14 @@
that: that:
- ufw_verify_added.stdout_lines | select('search', 'svc_c:128c086248') | list | length == 0 - ufw_verify_added.stdout_lines | select('search', 'svc_c:128c086248') | list | length == 0
- ufw_verify_added.stdout_lines | select('search', 'svc_d:') | list | length == 0 - ufw_verify_added.stdout_lines | select('search', 'svc_d:') | list | length == 0
- ufw_verify_added.stdout_lines | select('search', '7003.*svc_e:aaaaaaaaaa') | list | length == 1 - ufw_verify_added.stdout_lines | select('search', '7003.*svc_a:aaaaaaaaaa') | list | length == 1
- ufw_verify_added.stdout_lines | select('search', 'svc_h:bbbbbbbbbb') | list | length == 1 - ufw_verify_added.stdout_lines | select('search', 'svc_c:bbbbbbbbbb') | list | length == 1
- ufw_verify_added.stdout_lines | select('search', 'ansible-ufw') | list | length == 20 - ufw_verify_added.stdout_lines | select('search', 'ansible-ufw') | list | length == 20
quiet: true quiet: true
# Twenty tagged rules: svc_a 2, svc_b 2, svc_c 1, svc_e 2, svc_g 1, svc_h 2, svc_m 1, the # Twenty tagged rules: svc_a 7 (six desired, one stale), svc_c 7 (three desired, four stale),
# SSH lookalike of svc_o2, four orphans of svc_o3 and four rules of svc_p (its desired # svc_m 1, the SSH lookalike of svc_o2 and four orphans of svc_o3. Both rules of svc_o1 and
# rule and three stale ones). Both rules of svc_o1 and the numeric stale rule of svc_p were # the numeric stale rules of svc_c were deleted; the kept ones may carry SSH.
# deleted; the kept ones may carry SSH.
- name: Orphans were purged except those that may carry SSH, a managed owner kept its rule - name: Orphans were purged except those that may carry SSH, a managed owner kept its rule
ansible.builtin.assert: ansible.builtin.assert:
that: that:
@@ -426,12 +419,12 @@
- name: The stale purge of service_rules kept the lines that may carry SSH - name: The stale purge of service_rules kept the lines that may carry SSH
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- ufw_verify_added.stdout_lines | select('search', 'svc_p:6666666664') | list | length == 0 - ufw_verify_added.stdout_lines | select('search', 'svc_c:6666666664') | list | length == 0
- ufw_verify_added.stdout_lines | select('search', '7601') | list | length == 0 - ufw_verify_added.stdout_lines | select('search', '7601') | list | length == 0
- ufw_verify_added.stdout_lines | select('search', 'wg0.*svc_p:6666666661') | list | length == 1 - ufw_verify_added.stdout_lines | select('search', 'wg0.*svc_c:6666666661') | list | length == 1
- ufw_verify_added.stdout_lines | select('search', '10\.30\.0\.0/24.*svc_p:6666666662') | list | length == 1 - ufw_verify_added.stdout_lines | select('search', '10\.30\.0\.0/24.*svc_c:6666666662') | list | length == 1
- ufw_verify_added.stdout_lines | select('search', '40:50.*svc_p:6666666663') | list | length == 1 - ufw_verify_added.stdout_lines | select('search', '40:50.*svc_c:6666666663') | list | length == 1
- 'ufw_verify_added.stdout_lines | select("search", "7602.*ansible-ufw\\[svc_p:[0-9a-f]{10}\\]: desired") | list | length == 1' - 'ufw_verify_added.stdout_lines | select("search", "7602.*ansible-ufw\\[svc_c:[0-9a-f]{10}\\]: desired") | list | length == 1'
quiet: true quiet: true
- name: No rejected input left a rule behind - name: No rejected input left a rule behind
@@ -506,7 +499,7 @@
ufw_service_rules: ufw_service_rules:
- {rule: allow, port: 7701, proto: tcp, comment: check mode} - {rule: allow, port: 7701, proto: tcp, comment: check mode}
- name: An absent call for svc_a, which holds two rules - name: An absent call for svc_a, which holds seven rules
ansible.builtin.include_role: ansible.builtin.include_role:
name: mortis.kamino.ufw name: mortis.kamino.ufw
tasks_from: service_rules tasks_from: service_rules
@@ -524,7 +517,7 @@
- name: Check mode added and deleted nothing - name: Check mode added and deleted nothing
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- ufw_verify_chk_before.stdout_lines | select('search', 'svc_a:') | list | length == 2 - ufw_verify_chk_before.stdout_lines | select('search', 'svc_a:') | list | length == 7
- ufw_verify_chk_after.stdout_lines == ufw_verify_chk_before.stdout_lines - ufw_verify_chk_after.stdout_lines == ufw_verify_chk_before.stdout_lines
- ufw_verify_chk_after.stdout_lines | select('search', 'svc_chk|7701') | list | length == 0 - ufw_verify_chk_after.stdout_lines | select('search', 'svc_chk|7701') | list | length == 0
quiet: true quiet: true