-1

The Ansible user manual gives the following example to add repository:

- name: Add specified repository into sources list
  ansible.builtin.apt_repository:
    repo: deb http://archive.canonical.com/ubuntu focal partner
    state: present

However, this adds the repo entry in /etc/apt/sources.list.d/archive_canonical_com_ubuntu.list rather than updating the default /etc/apt/sources.list file. As a result, Ubuntu does not show this repository in Software & Updates(see "Canonical Partners" checkbox below).

enter image description here

The user manual also indicates that filename: "Sets the name of the source list file in sources.list.d." However, this appears to only add entries in /etc/apt/sources.list.d/ rather than the /etc/apt/sources.list file.

Is it possible to use ansible.builtin.apt_repository to add repo entries to /etc/apt/sources.list (i.e., rather than using template or lineinfile)?

user2514157
  • 545
  • 6
  • 24
  • 1
    Not sure why this question was down voted and closed for being a "general computing hardware and software" question. It is a well researched question clearly directed to a problem related to the proper use of a common software module that is not well documented elsewhere. – user2514157 Mar 17 '22 at 22:20

1 Answers1

1

Regarding your question

Is it possible to use ansible.builtin.apt_repository to add repo entries to /etc/apt/sources.list

it seems to be not according

It is the intended behavior as it has less complexity and this approach is simpler than changing or editing existing files.

Your mentioned approach with

... using template or lineinfile

would add probably unnecessary complexity.

Further Q&A

U880D
  • 8,601
  • 6
  • 24
  • 40
  • Agreed, template/lineinfile may not be as elegant but it has the advantage of displaying the correct information for repos picked up by the ubuntu gui. – user2514157 Mar 17 '22 at 22:27