Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions provision/ansible/roles/devbox/tasks/tailscale.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
---
# Tailscale from its own repository, for the release the host runs. Joining
# is tailnet.yml's.
# is tailnet.yml's. The key and the list have the names Tailscale's own
# installer and berth's server recipe give them, as apt refuses two lists of
# the same repository with different keys.
- name: Remove the Tailscale repository of earlier berths, kept under other names
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop:
- /etc/apt/sources.list.d/devbox-tailscale.list
- /usr/share/keyrings/devbox-tailscale.gpg
register: tailscale_old_repo
- name: Add Tailscale package signing key
ansible.builtin.get_url:
url: https://pkgs.tailscale.com/stable/ubuntu/{{ ansible_facts.distribution_release }}.noarmor.gpg
dest: /usr/share/keyrings/devbox-tailscale.gpg
dest: /usr/share/keyrings/tailscale-archive-keyring.gpg
mode: '0644'
- name: Configure Tailscale repository
ansible.builtin.copy:
dest: /etc/apt/sources.list.d/devbox-tailscale.list
content: "deb [signed-by=/usr/share/keyrings/devbox-tailscale.gpg] https://pkgs.tailscale.com/stable/ubuntu {{ ansible_facts.distribution_release }} main\n"
dest: /etc/apt/sources.list.d/tailscale.list
content: "deb [signed-by=/usr/share/keyrings/tailscale-archive-keyring.gpg] https://pkgs.tailscale.com/stable/ubuntu {{ ansible_facts.distribution_release }} main\n"
mode: '0644'
register: tailscale_repo
- name: Install Tailscale
ansible.builtin.apt:
name: tailscale
state: present
update_cache: "{{ tailscale_repo.changed }}"
update_cache: "{{ tailscale_repo.changed or tailscale_old_repo.changed }}"
26 changes: 26 additions & 0 deletions tests/test_tailnet_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,29 @@ def test_a_host_on_the_tailnet_is_left_alone_even_without_a_key(self):

if __name__ == '__main__':
unittest.main()


@unittest.skipUnless(yaml, 'needs PyYAML: install provision/requirements.txt')
class OneRepository(unittest.TestCase):
"""apt refuses two lists of Tailscale's repository with different keys,
so the role writes the list the server recipe and Tailscale's installer do."""

def written(self, tasks):
found = {}
for task in yaml.safe_load(tasks.read_text()):
for module in ('ansible.builtin.copy', 'ansible.builtin.get_url'):
if module in task:
found[task[module]['dest']] = task[module].get('content', '')
return found

def test_the_role_and_the_recipe_write_the_same_list_and_key(self):
role = self.written(ROLE / 'tasks/tailscale.yml')
recipe = self.written(ROOT / 'recipes/shared/tailscale.yml')
self.assertEqual(set(role), set(recipe))
for dest, content in role.items():
self.assertEqual(content.replace('ansible_facts.distribution_release', "ansible_facts['distribution_release']"), recipe[dest])

def test_the_list_of_earlier_berths_goes(self):
tasks = yaml.safe_load((ROLE / 'tasks/tailscale.yml').read_text())
removed = [task for task in tasks if task.get('ansible.builtin.file', {}).get('state') == 'absent']
self.assertIn('/etc/apt/sources.list.d/devbox-tailscale.list', removed[0]['loop'])
Loading