Files
Kamino/roles/tailscale
Defame1297 731bc022cd
Build / build (pull_request) Successful in 26s
Lint / lint (pull_request) Canceled after 2m8s
Molecule / molecule (pull_request) Canceled after 1m37s
fix(tailscale): tolerate an unloaded tailscaled unit in reset-failed
After a removal without purge the role has disabled tailscaled, so the
reinstall's postinst does not start it. systemd then unloads the inactive,
unreferenced unit, and `systemctl reset-failed tailscaled` exits 1 with
"Unit tailscaled.service not loaded.", failing the configure step on both
noble and resolute. An unloaded unit has no failure state to clear, and the
restart that follows loads it, so that one error is not a failure.

Assisted-by: Claude Code:claude-opus-5-5
2026-11-26 21:24:10 +00:00
..

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 of tailscale_apt_release read them.
  • Role dependencies: none.
  • tailscale_auth_key has no default. With tailscale_up: true it must be a non-empty string whenever the node is not Running (a new node, a logged-out one, or any run with tailscale_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/tun passed through from its host, or tailscale_userspace_networking: true.
  • The role owns no firewall rule: Tailscale makes outbound connections (UDP 41641 by default) and needs no inbound one.
  • become is 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). With tailscale_up: true, tailscale up runs only while the node is not Running.
  • Check mode: --check is the supported preview; a play-level check_mode: true is not supported. On a host without the package, the package install, the FLAGS edit, the service start and the update are skipped under --check, because the new source line is only simulated. tailscale up is 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 and tailscale up tasks use no_log.
  • tailscale up runs only when tailscale status --json reports a state other than Running (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_networking edits only the --tun=userspace-networking token of the FLAGS line; other flags and the rest of /etc/default/tailscaled (a conffile of the package, which also holds PORT) are kept. A change, or a tailscaled that 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 to tailscaled, not to tailscale up.
  • The Restart tailscaled handler runs after a package install or update.
  • Removal tolerates a host with no tailscaled unit, so a repeated --tags remove passes.
  • tailscale logout during removal is best effort. A removal without tailscale_remove_data keeps the state directory and the defaults file.