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
This commit is contained in:
Defame1297 committed 2026-11-26 19:08:25 +00:00
1 parent 31634c4eef
commit 80c76b16ee
18 files changed
+943 -3

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
---
# Run with tailscale_update=true (tag: update).
- name: Refresh APT cache before checking for Tailscale updates
become: true
ansible.builtin.apt:
update_cache: true
tags: [tailscale, update]
- name: Determine latest available Tailscale candidate version
ansible.builtin.command: apt-cache policy {{ tailscale_package | quote }}
register: __tailscale_apt_policy
changed_when: false
# Read-only, so it also runs in the --check preview, which needs its stdout.
check_mode: false
tags: [tailscale, update]
- name: Extract latest Tailscale candidate version
ansible.builtin.set_fact:
__tailscale_candidate_version: >-
{{ __tailscale_apt_policy.stdout | regex_search('Candidate:\s+(\S+)', '\1') | default([''], true) | first }}
tags: [tailscale, update]
- name: Fail if Tailscale has no installable candidate
ansible.builtin.fail:
msg: >-
No installable candidate version found for {{ tailscale_package }} (apt-cache policy reported
'{{ __tailscale_candidate_version }}'). Check that the Tailscale APT repository is reachable.
when: __tailscale_candidate_version in ['', '(none)']
tags: [tailscale, update]
# Pinned to the resolved candidate version (never state=latest), so the task stays idempotent and
# passes ansible-lint's package-latest rule.
- name: Update Tailscale package to latest candidate version
become: true
ansible.builtin.apt:
name: "{{ tailscale_package }}={{ __tailscale_candidate_version }}"
state: present
notify: Restart tailscaled
tags: [tailscale, update]