Hi,
on Debian systems, one can configure repositories in an
/etc/apt/sources.list.d directory with multiple files. I usually name
the files after the distribution, so that, in a simplyfied example, I
might have a file /etc/apt/sources.list.d/stable.list on systems running
Debian stable, and /etc/apt/sources.list.d/testing.list on systems
running Debian testing. In the real case, there are additional
distribution-depending files (security, backports, local packages in
different stages).
A similiar setup can usually be found in /etc/yum.repos.d/ on Red Hat
based systems.
A local admin might choose to place additional files into those
directories manually, for example adding special repositories for
third-party software that doesn't come with the distribution.
But back to the Debian case.
When I change a system from testing to stable, I want the all
testing*.list to vanish, and the stable*.list files to appear, unless
they're already there, in which case I want them untouched. Locally
placed files should also be untouched.
My first approach was to concentrate all the ansible-managed *.list
files under a common prefix, zda, giving, for example,
zda-unstable.list.
I then wrote code to first remove all zda*.list files (and their laegacy-named
instances), and code to deploy the correct zda-foo.list file:
- name: search for sources.list files
find:
paths: "/etc/apt/sources.list.d"
patterns: "zda-*.list,exp-mc.list,sid-mc.list,sid-zg-stable-mc.list,sid-zg-unstable-mc.list,stretch-mc.list,stretch-security.list,stretch-zg-stable-mc.list,stretch-zg-unstable-mc.list,buster-mc.list,stretch-zg-stable-mc.list,stretch-security.list"
register: sourceslistfiles
- name: delete sources.list files
file:
path: "{{ item.path }}"
state: absent
with_items: "{{ sourceslistfiles.files }}"
and finally code to roll out new list files:
- name: include repositories
tags:
repos
include_tasks:
"{{distribution}}/{{distribution_version}}/repos.yml"
$ cat roles/common/tasks/debian/stretch/repos.yml