- 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
53 lines
2.3 KiB
YAML
53 lines
2.3 KiB
YAML
---
|
|
# Input checks. Imported first in main.yml with tags: always, so a bad input fails before any
|
|
# change. The argument spec (types) runs before this file.
|
|
|
|
# The repository suite and the source list follow the host's release, read from gathered facts.
|
|
- name: Require Ubuntu
|
|
ansible.builtin.assert:
|
|
that:
|
|
- ansible_facts['distribution'] | default('') == 'Ubuntu'
|
|
fail_msg: >-
|
|
tailscale supports Ubuntu only (found: {{ ansible_facts['distribution'] | default('no gathered facts') }}).
|
|
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
|
|
become: true
|
|
ansible.builtin.command: tailscale status --json
|
|
register: __tailscale_status_before
|
|
changed_when: false
|
|
failed_when: false
|
|
check_mode: false
|
|
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. 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:
|
|
- tailscale_auth_key is defined
|
|
- tailscale_auth_key is string
|
|
- tailscale_auth_key | trim | length > 0
|
|
fail_msg: >-
|
|
tailscale_auth_key must be a non-empty string: tailscale_up is true and the node is not Running
|
|
(or tailscale_remove is true), so the role runs tailscale up. Set the key, normally from a
|
|
vaulted variable, or set tailscale_up to false.
|
|
quiet: true
|
|
when:
|
|
- __tailscale_runs_up | bool
|
|
- >-
|
|
tailscale_remove | bool
|
|
or (__tailscale_status_before.stdout | default('{}', true) | from_json).BackendState | default('NoState') != 'Running'
|