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
@@ -95,11 +95,15 @@
|
||||
- "'https://pkgs.tailscale.com/stable/ubuntu ' ~ ansible_facts['distribution_release'] in tailscale_test_policy.stdout"
|
||||
quiet: true
|
||||
|
||||
- name: Ask systemd about tailscaled
|
||||
# tailscaled may still be starting after a restart.
|
||||
- name: Wait for tailscaled
|
||||
ansible.builtin.systemd:
|
||||
name: tailscaled
|
||||
register: tailscale_test_unit
|
||||
check_mode: true
|
||||
until: tailscale_test_unit.status.ActiveState == 'active'
|
||||
retries: 10
|
||||
delay: 3
|
||||
|
||||
- name: Tailscaled is enabled and running
|
||||
ansible.builtin.assert:
|
||||
@@ -206,11 +210,15 @@
|
||||
register: tailscale_test_updated
|
||||
changed_when: false
|
||||
|
||||
- name: Ask systemd about tailscaled after the update
|
||||
# tailscaled may still be starting after a restart.
|
||||
- name: Wait for tailscaled after the update
|
||||
ansible.builtin.systemd:
|
||||
name: tailscaled
|
||||
register: tailscale_test_unit
|
||||
check_mode: true
|
||||
until: tailscale_test_unit.status.ActiveState == 'active'
|
||||
retries: 10
|
||||
delay: 3
|
||||
|
||||
- name: The candidate is installed and tailscaled runs
|
||||
ansible.builtin.assert:
|
||||
@@ -219,10 +227,10 @@
|
||||
- tailscale_test_unit.status.ActiveState == 'active'
|
||||
quiet: true
|
||||
|
||||
# tailscale_remove with tailscale_remove_data purges the package and the state directory, then the
|
||||
# role installs it again. A marker in the state directory and a line added to the defaults file (a
|
||||
# conffile, so only a purge replaces it) show that both went.
|
||||
- name: Verify removal and purge
|
||||
# A removal without tailscale_remove_data, through the role's remove tasks alone (as --tags remove
|
||||
# runs them): the package goes, while the state directory and the defaults file (a conffile) stay.
|
||||
# A second removal finds no tailscaled unit and must still pass. The role then installs it again.
|
||||
- name: Verify removal without purge
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
tasks:
|
||||
@@ -237,17 +245,112 @@
|
||||
path: /etc/default/tailscaled
|
||||
line: "# molecule-marker"
|
||||
|
||||
- name: Run the remove tasks
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.tailscale
|
||||
tasks_from: remove
|
||||
vars:
|
||||
tailscale_remove: true
|
||||
|
||||
- name: Ask dpkg for the package state
|
||||
ansible.builtin.command:
|
||||
argv: [dpkg-query, --show, --showformat, "${db:Status-Status}", tailscale]
|
||||
register: tailscale_test_dpkg
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Stat the state marker and the source list
|
||||
ansible.builtin.stat:
|
||||
path: "{{ item }}"
|
||||
loop:
|
||||
- /var/lib/tailscale/molecule-marker
|
||||
- /etc/apt/sources.list.d/tailscale.list
|
||||
register: tailscale_test_kept
|
||||
|
||||
- name: Read the defaults file
|
||||
ansible.builtin.slurp:
|
||||
src: /etc/default/tailscaled
|
||||
register: tailscale_test_defaults
|
||||
|
||||
- name: The package and the source list are gone, the state and the defaults file are kept
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- tailscale_test_dpkg.stdout != 'installed'
|
||||
- tailscale_test_kept.results | map(attribute='stat.exists') | list == [true, false]
|
||||
- "'# molecule-marker' in (tailscale_test_defaults.content | b64decode).splitlines()"
|
||||
quiet: true
|
||||
|
||||
- name: Run the remove tasks again, with no tailscaled unit left
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.tailscale
|
||||
tasks_from: remove
|
||||
vars:
|
||||
tailscale_remove: true
|
||||
|
||||
- name: Install again
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.tailscale
|
||||
|
||||
- name: Wait for tailscaled
|
||||
ansible.builtin.systemd:
|
||||
name: tailscaled
|
||||
register: tailscale_test_unit
|
||||
check_mode: true
|
||||
until: tailscale_test_unit.status.ActiveState == 'active'
|
||||
retries: 10
|
||||
delay: 3
|
||||
|
||||
- name: Stat the state marker again
|
||||
ansible.builtin.stat:
|
||||
path: /var/lib/tailscale/molecule-marker
|
||||
register: tailscale_test_marker
|
||||
|
||||
- name: The reinstall kept the state
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- tailscale_test_marker.stat.exists
|
||||
- tailscale_test_unit.status.UnitFileState == 'enabled'
|
||||
quiet: true
|
||||
|
||||
# tailscale_remove with tailscale_remove_data purges the package and deletes tailscale_state_dir,
|
||||
# then the role installs it again. The package's own purge deletes /var/lib/tailscale, so the state
|
||||
# directory here is another one: only the role removes it. The marker line in the defaults file (a
|
||||
# conffile, so only a purge replaces it) shows the purge.
|
||||
- name: Verify removal with purge
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
vars:
|
||||
tailscale_test_state_dir: /srv/tailscale-molecule-state
|
||||
tasks:
|
||||
- name: Create the state directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ tailscale_test_state_dir }}"
|
||||
state: directory
|
||||
mode: "0700"
|
||||
|
||||
- name: Put a marker in the state directory
|
||||
ansible.builtin.copy:
|
||||
content: marker
|
||||
dest: "{{ tailscale_test_state_dir }}/molecule-marker"
|
||||
mode: "0600"
|
||||
|
||||
- name: Add a marker line to the defaults file
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/default/tailscaled
|
||||
line: "# molecule-marker"
|
||||
|
||||
- name: Run the role with removal and data removal
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.tailscale
|
||||
vars:
|
||||
tailscale_remove: true
|
||||
tailscale_remove_data: true
|
||||
tailscale_state_dir: "{{ tailscale_test_state_dir }}"
|
||||
|
||||
- name: Stat the state marker
|
||||
- name: Stat the state directory
|
||||
ansible.builtin.stat:
|
||||
path: /var/lib/tailscale/molecule-marker
|
||||
register: tailscale_test_marker
|
||||
path: "{{ tailscale_test_state_dir }}"
|
||||
register: tailscale_test_state
|
||||
|
||||
- name: Read the defaults file
|
||||
ansible.builtin.slurp:
|
||||
@@ -260,21 +363,23 @@
|
||||
register: tailscale_test_dpkg
|
||||
changed_when: false
|
||||
|
||||
- name: Ask systemd about tailscaled
|
||||
- name: Wait for tailscaled
|
||||
ansible.builtin.systemd:
|
||||
name: tailscaled
|
||||
register: tailscale_test_unit
|
||||
check_mode: true
|
||||
until: tailscale_test_unit.status.ActiveState == 'active'
|
||||
retries: 10
|
||||
delay: 3
|
||||
|
||||
- name: The data went, and the role installed and configured tailscale again
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- not tailscale_test_marker.stat.exists
|
||||
- not tailscale_test_state.stat.exists
|
||||
- "'# molecule-marker' not in tailscale_test_defaults_lines"
|
||||
- "'FLAGS=\"--tun=userspace-networking\"' in tailscale_test_defaults_lines"
|
||||
- tailscale_test_dpkg.stdout == 'installed'
|
||||
- tailscale_test_unit.status.UnitFileState == 'enabled'
|
||||
- tailscale_test_unit.status.ActiveState == 'active'
|
||||
quiet: true
|
||||
vars:
|
||||
tailscale_test_defaults_lines: "{{ (tailscale_test_defaults.content | b64decode).splitlines() }}"
|
||||
Reference in new issue
Block a user