diff --git a/ansible/inventory/group_vars/all/apt b/ansible/inventory/group_vars/all/apt index 5285fba6c..394532cb0 100644 --- a/ansible/inventory/group_vars/all/apt +++ b/ansible/inventory/group_vars/all/apt @@ -27,6 +27,8 @@ apt_config: [] apt_keys: [] # A list of Apt repositories. Each item is a dict with the following keys: +# * name: the .sources filename part. Optional. Default is 'kayobe' and +# the default filename is 'kayobe.sources'. # * types: whitespace-separated list of repository types, e.g. deb or deb-src # (optional, default is 'deb') # * url: URL of the repository diff --git a/ansible/roles/apt/defaults/main.yml b/ansible/roles/apt/defaults/main.yml index 5851d1908..6b53211e3 100644 --- a/ansible/roles/apt/defaults/main.yml +++ b/ansible/roles/apt/defaults/main.yml @@ -30,6 +30,8 @@ apt_keys_path: "/etc/apt/keyrings" apt_keys: [] # A list of Apt repositories. Each item is a dict with the following keys: +# * name: the .sources filename part. Optional. Default is 'kayobe' and +# the default filename is 'kayobe.sources'. # * types: whitespace-separated list of repository types, e.g. deb or deb-src # (optional, default is 'deb') # * url: URL of the repository diff --git a/ansible/roles/apt/tasks/repos.yml b/ansible/roles/apt/tasks/repos.yml index b63139e7f..9f8131ae5 100644 --- a/ansible/roles/apt/tasks/repos.yml +++ b/ansible/roles/apt/tasks/repos.yml @@ -13,11 +13,14 @@ - name: Configure apt repositories template: src: "kayobe.sources.j2" - dest: "/etc/apt/sources.list.d/kayobe.sources" + dest: "/etc/apt/sources.list.d/{{ reponame }}.sources" owner: root group: root mode: 0644 become: true + loop: "{{ apt_repositories }}" + vars: + reponame: "{{ item.name | default('kayobe') }}" notify: - Update apt cache diff --git a/ansible/roles/apt/templates/kayobe.sources.j2 b/ansible/roles/apt/templates/kayobe.sources.j2 index b63f600de..bc99a19fe 100644 --- a/ansible/roles/apt/templates/kayobe.sources.j2 +++ b/ansible/roles/apt/templates/kayobe.sources.j2 @@ -1,12 +1,13 @@ # {{ ansible_managed }} {% for repo in apt_repositories %} +{% if reponame == repo.name | default('kayobe') %} Types: {{ repo.types | default('deb') }} URIs: {{ repo.url }} Suites: {{ repo.suites | default(ansible_facts.distribution_release) }} Components: {{ repo.components | default('main') }} {% if repo.signed_by is defined %} -Signed-by: {{ apt_keys_path }}/{{ repo.signed_by }} +Signed-by: {% if not repo.signed_by.startswith('/') %}{{ apt_keys_path }}/{% endif %}{{ repo.signed_by }} {% endif %} {% if repo.architecture is defined %} Architecture: {{ repo.architecture }} @@ -15,4 +16,5 @@ Architecture: {{ repo.architecture }} Trusted: {{ repo.trusted | bool }} {% endif %} +{% endif %} {% endfor %} diff --git a/doc/source/configuration/reference/hosts.rst b/doc/source/configuration/reference/hosts.rst index 87fddbccc..9e06722e3 100644 --- a/doc/source/configuration/reference/hosts.rst +++ b/doc/source/configuration/reference/hosts.rst @@ -366,6 +366,8 @@ Kayobe supports configuration of custom Apt repositories via the The format is a list, with each item mapping to a dict/map with the following items: +* ``name``: the ``.sources`` filename part. Optional. Default is + ``kayobe`` and the default filename is ``kayobe.sources``. * ``types``: whitespace-separated list of repository types, e.g. ``deb`` or ``deb-src`` (optional, default is ``deb``) * ``url``: URL of the repository diff --git a/etc/kayobe/apt.yml b/etc/kayobe/apt.yml index 9302675c3..4027d4365 100644 --- a/etc/kayobe/apt.yml +++ b/etc/kayobe/apt.yml @@ -27,6 +27,8 @@ #apt_keys: # A list of Apt repositories. Each item is a dict with the following keys: +# * name: the .sources filename part. Optional. Default is 'kayobe' and +# the default filename is 'kayobe.sources'. # * types: whitespace-separated list of repository types, e.g. deb or deb-src # (optional, default is 'deb') # * url: URL of the repository diff --git a/releasenotes/notes/ubuntu-sources-configure-c2aff9915db76d07.yaml b/releasenotes/notes/ubuntu-sources-configure-c2aff9915db76d07.yaml new file mode 100644 index 000000000..4c4c71503 --- /dev/null +++ b/releasenotes/notes/ubuntu-sources-configure-c2aff9915db76d07.yaml @@ -0,0 +1,11 @@ +--- +fixes: + - | + Adds a ``name`` field to elements of ``apt_repositories``, which specifies + the name of the repository file (without the ``.sources`` suffix). The + default value of this field is ``kayobe`` and it may be omitted. The user + can override the default by providing a different name, such as ``ubuntu``, + and new repository data. This way, the default file, + ``/etc/apt/source.list.d/ubuntu.sources``, will be overwritten by the + provided repository configuration. + `LP#2107280 `__