From b3ca17a0f5ac8a9e1a91c5048877b4c8a28b35cd Mon Sep 17 00:00:00 2001 From: Helight Date: Sun, 15 Nov 2026 18:38:23 +0100 Subject: [PATCH] fix(role): Tailscale's repository has one list, as its installer names it A machine the server recipe set up has tailscale.list with Tailscale's own key name; the role's second list of the same repository with another key made apt refuse every source. The role now writes the same list and removes the one of earlier berths. --- .../ansible/roles/devbox/tasks/tailscale.yml | 20 ++++++++++---- tests/test_tailnet_role.py | 26 +++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/provision/ansible/roles/devbox/tasks/tailscale.yml b/provision/ansible/roles/devbox/tasks/tailscale.yml index 00a624b..4d93166 100644 --- a/provision/ansible/roles/devbox/tasks/tailscale.yml +++ b/provision/ansible/roles/devbox/tasks/tailscale.yml @@ -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 }}" diff --git a/tests/test_tailnet_role.py b/tests/test_tailnet_role.py index 7933edb..527bbb7 100644 --- a/tests/test_tailnet_role.py +++ b/tests/test_tailnet_role.py @@ -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'])