- 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
56 lines
1.7 KiB
YAML
56 lines
1.7 KiB
YAML
---
|
|
# Run with tailscale_remove=true (and tailscale_remove_data=true to purge), tag: remove. main.yml
|
|
# installs and configures Tailscale again afterwards.
|
|
- name: Log Tailscale out of the tailnet
|
|
become: true
|
|
ansible.builtin.command: tailscale logout
|
|
register: __tailscale_logout
|
|
changed_when: __tailscale_logout.rc == 0
|
|
# Best effort: already logged out, tailscaled down or binary missing must not block the removal. A
|
|
# failed logout leaves a stale device in the tailnet admin console.
|
|
failed_when: false
|
|
tags: [tailscale, remove]
|
|
|
|
- name: Stop and disable tailscaled service
|
|
become: true
|
|
ansible.builtin.systemd:
|
|
name: tailscaled
|
|
state: stopped
|
|
enabled: false
|
|
register: __tailscale_stop
|
|
# A host without the package has no unit; there is nothing to stop then.
|
|
failed_when:
|
|
- __tailscale_stop is failed
|
|
- "'Could not find the requested service' not in __tailscale_stop.msg | default('')"
|
|
tags: [tailscale, remove]
|
|
|
|
- name: Remove Tailscale package
|
|
become: true
|
|
ansible.builtin.apt:
|
|
name: "{{ tailscale_package }}"
|
|
state: absent
|
|
purge: "{{ tailscale_remove_data | bool }}"
|
|
tags: [tailscale, remove]
|
|
|
|
- name: Remove Tailscale APT source list
|
|
become: true
|
|
ansible.builtin.file:
|
|
path: "{{ tailscale_apt_list_path }}"
|
|
state: absent
|
|
tags: [tailscale, remove]
|
|
|
|
- name: Remove Tailscale APT keyring
|
|
become: true
|
|
ansible.builtin.file:
|
|
path: "{{ tailscale_keyring_path }}"
|
|
state: absent
|
|
tags: [tailscale, remove]
|
|
|
|
- name: Remove Tailscale state directory
|
|
become: true
|
|
ansible.builtin.file:
|
|
path: "{{ tailscale_state_dir }}"
|
|
state: absent
|
|
when: tailscale_remove_data | bool
|
|
tags: [tailscale, remove]
|