- 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
8.2 KiB
tailscale
Installs Tailscale from the upstream APT repository with the keyring pinned by sha256, sets the tailscaled flags, enables tailscaled and brings the node onto the tailnet with an auth key. It can also update to the APT candidate version, and remove or purge. Variables and their types are defined in meta/argument_specs.yml, which is the source of truth.
Supported platforms
Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on. The role asserts that the host is Ubuntu before any change, and the repository suite follows the host's release (tailscale_apt_release). The host needs outbound access to pkgs.tailscale.com.
The role targets Ubuntu hosts, not Proxmox nodes, so it does not cover Debian trixie: it asserts Ubuntu and is tested only there.
Requirements and run order
- Use it by its fully qualified name,
mortis.kamino.tailscale, in a play that gathers facts: the Ubuntu assert and the default oftailscale_apt_releaseread them. - Role dependencies: none.
tailscale_auth_keyhas no default. Withtailscale_up: trueit must be a non-empty string whenever the node is not Running (a new node, a logged-out one, or any run withtailscale_remove) and the run includes the configure tasks; this is asserted before any change. See Tags for which runs need it. Source it from a vaulted variable.- A container needs
/dev/net/tunpassed through from its host, ortailscale_userspace_networking: true. - The role owns no firewall rule: Tailscale makes outbound connections (UDP 41641 by default) and needs no inbound one.
becomeis used for every task that changes the host.
Role variables
| Variable | Default | Description |
|---|---|---|
tailscale_up |
true |
Run tailscale up when the backend state is not Running. False installs and runs tailscaled without joining a tailnet. |
tailscale_auth_key |
none | Auth key for tailscale up. No default; see Requirements. no_log. |
tailscale_update |
false |
Install the package's APT candidate version. |
tailscale_remove |
false |
Log out, stop and disable tailscaled, remove the package, the source list and the keyring, then install and configure again. |
tailscale_remove_data |
false |
With tailscale_remove: purge the package and delete tailscale_state_dir. |
tailscale_userspace_networking |
false |
Add --tun=userspace-networking to FLAGS in /etc/default/tailscaled; false removes it again. |
tailscale_package |
tailscale |
APT package name. |
tailscale_apt_distribution |
ubuntu |
Repository distribution directory. |
tailscale_apt_release |
the host's release (ansible_facts['distribution_release']) |
Repository suite and keyring release. |
tailscale_repo_url |
https://pkgs.tailscale.com/stable/<tailscale_apt_distribution> |
APT repository URL in the source list. |
tailscale_keyring_url |
<tailscale_repo_url>/<tailscale_apt_release>.noarmor.gpg |
Keyring download URL. |
tailscale_keyring_checksum |
sha256 of the current Tailscale keyring | Expected sha256 of the keyring; a mismatch fails the download. |
tailscale_keyring_path |
/usr/share/keyrings/tailscale-archive-keyring.gpg |
Keyring destination. |
tailscale_apt_list_path |
/etc/apt/sources.list.d/tailscale.list |
APT source list destination. |
tailscale_state_dir |
/var/lib/tailscale |
Deleted when tailscale_remove_data is true. |
Tags
The input validation (tasks/validate.yml) carries always, so it runs whatever tags are selected. tailscale selects every other task; install, configure, update and remove select their task files. health is only on the include of the configure tasks, whose own tasks carry tailscale and configure, so --tags health runs none of them.
The auth key is needed only by runs that include the configure tasks: no tag selection, --tags tailscale or --tags configure (and tagged), unless --skip-tags names tailscale, configure or health. --tags remove, --tags install and --tags update run without it.
Example play
- name: Join the tailnet
hosts: tailnet_nodes
roles:
- role: mortis.kamino.tailscale
vars:
tailscale_auth_key: "{{ vault_tailscale_auth_key }}"
Removal and update are explicit: -e tailscale_remove=true (add tailscale_remove_data=true to purge) removes and then reinstalls, while --tags remove runs only the removal; -e tailscale_update=true --tags update updates.
Tests
The default molecule scenario runs in CI only, on two platforms: ${MOLECULE_IMAGE} (Ubuntu 24.04) and ${MOLECULE_IMAGE_2604} (Ubuntu 26.04). It installs the real package from pkgs.tailscale.com with tailscale_up: false and tailscale_userspace_networking: true. tailscale up (joining a tailnet) is not exercised: the scenario has no auth key and no tailnet. Verify checks the keyring checksum against the published hash, the APT source line, the package installed from that repository, tailscaled enabled and active, the FLAGS line in /etc/default/tailscaled with the package's PORT line kept, the running daemon's command line carrying --tun=userspace-networking, and a backend state that is not Running. It then downgrades the package to an older version from the repository and runs the role with tailscale_update (the candidate is installed again), Removal is run twice. First the remove tasks alone, as --tags remove runs them, without tailscale_remove_data: the package and the source list go, while a marker in the state directory and a line added to the defaults file stay. A second removal, with no tailscaled unit left, passes, and the role then installs Tailscale again with the state kept. Second, the role with tailscale_remove and tailscale_remove_data and a tailscale_state_dir other than /var/lib/tailscale, which the package's own purge deletes: that directory is gone, the defaults file is the package's fresh copy, and the role installed and configured Tailscale again. Verify waits for tailscaled to be active after each restart. It runs check before the converge (a fresh host) and after it (a configured host). Negative tests cover a host without Ubuntu facts, a tailscale_up that is not a boolean, and tailscale_up: true without an auth key or with an empty one. Switching tailscale_userspace_networking back to false is not run: tailscaled cannot start without /dev/net/tun in the container.
Notes
- Idempotent: yes, with
tailscale_up: false(the scenario checks it). Withtailscale_up: true,tailscale upruns only while the node is not Running. - Check mode:
--checkis the supported preview; a play-levelcheck_mode: trueis not supported. On a host without the package, the package install, theFLAGSedit, the service start and the update are skipped under--check, because the new source line is only simulated.tailscale upis always skipped under--check. The auth key is still asserted. - The auth key is passed as
--auth-key=file:<path>from a root-owned 0600 temporary file, so it never appears in argv. The file is always removed, and the write andtailscale uptasks useno_log. tailscale upruns only whentailscale status --jsonreports a state other thanRunning(an unreadable status counts as not running).- No Tailscale SSH flag and no ACL tag are set: the node gets a plain tailnet IP.
tailscale_userspace_networkingedits only the--tun=userspace-networkingtoken of theFLAGSline; other flags and the rest of/etc/default/tailscaled(a conffile of the package, which also holdsPORT) are kept. A change, or atailscaledthat is not active, restarts it at once after clearing its failure state (systemctl reset-failed): the package starts it with the flags it ships, which fails without a TUN device and can run into systemd's start limit. The flag belongs totailscaled, not totailscale up.- The
Restart tailscaledhandler runs after a package install or update. - Removal tolerates a host with no
tailscaledunit, so a repeated--tags removepasses. tailscale logoutduring removal is best effort. A removal withouttailscale_remove_datakeeps the state directory and the defaults file.