Files
Kamino/roles/tailscale/README.md
T
Defame1297 80c76b16ee feat(tailscale): add the tailscale role
Installs Tailscale from the upstream APT repository with the keyring
pinned by sha256, enables tailscaled and, with tailscale_up (default
true), runs tailscale up with tailscale_auth_key while the node is not
Running. It can also update to the APT candidate version and remove or
purge.

The role asserts Ubuntu and follows the host's release, and requires a
non-empty auth key before any change whenever tailscale up will run.
tailscale_userspace_networking now sets --tun=userspace-networking in
the FLAGS of /etc/default/tailscaled, where tailscaled reads it, instead
of passing it to tailscale up.

The molecule scenario installs the real package on noble and resolute
without joining a tailnet, and covers the update and purge paths and
the refusal cases.

Closes #396

Assisted-by: Claude Code:claude-opus-5-5
2026-11-26 19:08:25 +00:00

6.9 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 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); this is asserted before any change. 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.

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), and runs it with tailscale_remove and tailscale_remove_data (a marker in the state directory and a line added to the defaults file are gone, and the role installed and configured Tailscale again). 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 restarts tailscaled. The flag belongs to tailscaled, not to tailscale up.
  • The Restart tailscaled handler runs after a package install or update and after a change of the flags.
  • tailscale logout during removal is best effort. A removal without tailscale_remove_data keeps the state directory and the defaults file.