fix(tailscale): harden removal, restarts and the auth key check
- 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:
1 parent
80c76b16ee
commit
29165a610f
6 files changed
+190
-29
No files matched your search
@@ -31,29 +31,67 @@
|
||||
| regex_replace('^"(.*)"$', '\1') | regex_replace("^'(.*)'$", '\1') | split }}
|
||||
tags: [tailscale, configure]
|
||||
|
||||
# Under --check the unit exists only when the package is installed and this run did not just
|
||||
# (simulate) installing it; the defaults file ships with the package.
|
||||
- name: Work out whether the tailscaled unit can be managed
|
||||
ansible.builtin.set_fact:
|
||||
__tailscale_unit_present: >-
|
||||
{{ not ansible_check_mode
|
||||
or (__tailscale_defaults_stat.stat.exists
|
||||
and __tailscale_apt_source | default({}) is not changed
|
||||
and __tailscale_package_install | default({}) is not changed) }}
|
||||
tags: [tailscale, configure]
|
||||
|
||||
- name: Set the tailscaled flags
|
||||
become: true
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/default/tailscaled
|
||||
regexp: "^FLAGS="
|
||||
line: FLAGS="{{ __tailscale_flags | join(' ') }}"
|
||||
notify: Restart tailscaled
|
||||
register: __tailscale_flags_file
|
||||
# The package ships the file; under --check on a host without the package it does not exist yet.
|
||||
when: not ansible_check_mode or __tailscale_defaults_stat.stat.exists
|
||||
tags: [tailscale, configure]
|
||||
|
||||
# Reads the flags just written when it starts tailscaled, so a daemon that failed to start without
|
||||
# a TUN device comes up here.
|
||||
- name: Read the state of tailscaled
|
||||
become: true
|
||||
ansible.builtin.systemd:
|
||||
name: tailscaled
|
||||
register: __tailscale_unit
|
||||
check_mode: true
|
||||
when: __tailscale_unit_present | bool
|
||||
tags: [tailscale, configure]
|
||||
|
||||
# The package starts tailscaled with the flags it ships. Without a TUN device that start fails and
|
||||
# Restart=on-failure can run into the start limit, which refuses a later plain start. So when the
|
||||
# flags changed or the unit is not active, clear the failure state and restart now, not at the end
|
||||
# of the play.
|
||||
- name: Restart tailscaled with the current flags
|
||||
when:
|
||||
- __tailscale_unit_present | bool
|
||||
- __tailscale_flags_file is changed or __tailscale_unit.status.ActiveState | default('') != 'active'
|
||||
tags: [tailscale, configure]
|
||||
block:
|
||||
- name: Clear the failure state of tailscaled
|
||||
become: true
|
||||
ansible.builtin.command: systemctl reset-failed tailscaled # noqa: command-instead-of-module
|
||||
changed_when: false
|
||||
# Not run under --check: the restart below only reports what it would do there.
|
||||
when: not ansible_check_mode
|
||||
|
||||
- name: Restart tailscaled
|
||||
become: true
|
||||
ansible.builtin.systemd:
|
||||
name: tailscaled
|
||||
state: restarted
|
||||
|
||||
- name: Enable and start tailscaled service
|
||||
become: true
|
||||
ansible.builtin.systemd:
|
||||
name: tailscaled
|
||||
enabled: true
|
||||
state: started
|
||||
# Under --check on a host without the package there is no unit to start yet.
|
||||
when: >-
|
||||
not ansible_check_mode
|
||||
or (__tailscale_apt_source | default({}) is not changed and __tailscale_package_install | default({}) is not changed)
|
||||
when: __tailscale_unit_present | bool
|
||||
tags: [tailscale, configure]
|
||||
|
||||
- name: Check current Tailscale backend status
|
||||
|
||||
Reference in new issue
Block a user