fix(tailscale): harden removal, restarts and the auth key check
Build / build (pull_request) Successful in 29s
Lint / lint (pull_request) Successful in 2m25s
Molecule / molecule (pull_request) Failing after 3m23s

- Removal passes on a host without a tailscaled unit, and the
  best-effort logout reports a change only when it succeeded.
- Under --check the service tasks run only when the unit exists, also
  with --tags configure on a host without the package.
- The auth key is required before any change only when the run includes
  the configure tasks; --tags remove, install and update need none. The
  assert in the up block stays as the hard guard.
- When the flags change or tailscaled is not active, the role clears its
  failure state and restarts it at once, so a daemon the package started
  without a TUN device does not stay in the start limit.
- The health tag is back on the configure include.
- The scenario tests removal without purge (state and defaults kept, a
  second removal passes) and a purge with a state directory the package
  does not delete itself, and waits for tailscaled to be active.

Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
Defame1297 committed 2026-11-26 20:47:49 +00:00
1 parent 80c76b16ee
commit 29165a610f
6 files changed
+190 -29

No files matched your search

+12 -3
View File
@@ -12,6 +12,15 @@
The role reads gathered facts, so run it in a play that gathers them.
quiet: true
# tailscale up runs in the configure tasks (tags tailscale and configure), so the key is needed
# only when the run selects them and skips neither.
- name: Work out whether this run brings the node up
ansible.builtin.set_fact:
__tailscale_runs_up: >-
{{ tailscale_up | bool
and (ansible_run_tags | intersect(['all', 'tagged', 'tailscale', 'configure']) | length > 0)
and (ansible_skip_tags | intersect(['tailscale', 'configure', 'health']) | length == 0) }}
# Read-only, so it also runs under --check. A missing binary or a daemon that is not up counts as
# not Running.
- name: Read the Tailscale backend state before any change
@@ -21,10 +30,10 @@
changed_when: false
failed_when: false
check_mode: false
when: tailscale_up | bool
when: __tailscale_runs_up | bool
# tailscale up runs when the node is not Running, and a removal logs it out first, so then the
# key is needed.
# key is needed. The configure tasks check it again against the state tailscale up acts on.
- name: Require an auth key when tailscale up will run
ansible.builtin.assert:
that:
@@ -37,7 +46,7 @@
vaulted variable, or set tailscale_up to false.
quiet: true
when:
- tailscale_up | bool
- __tailscale_runs_up | bool
- >-
tailscale_remove | bool
or (__tailscale_status_before.stdout | default('{}', true) | from_json).BackendState | default('NoState') != 'Running'