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
---
- name: zda-stretch-mc.list
tags:
- repos
- stretch
copy:
dest: /etc/apt/sources.list.d/zda-stretch-mc.list
owner: root
group: root
mode: 0644
content: |
deb
http://debian.debian.zugschlus.de/debian/ stretch main contrib
notify: apt update
- name: zda-stretch-security.list
tags:
- repos
- stretch
copy:
dest: /etc/apt/sources.list.d/zda-stretch-security.list
owner: root
group: root
mode: 0644
content: |
deb
http://debian-security.debian.zugschlus.de/debian-security/ stretch/updates main contrib
deb
http://security.debian.org/ stretch/updates main contrib
notify: apt update
But of course this does not quiet what I want, as it first zaps all
files, and then proceeds to roll out the "new" files again, resulting in
ctime and inode values being changed etc.
How about the following:
- build the list of files found on the remote system
- roll out the new contents, remove the name of the file from the list
- delete the remainder of files
or
- roll out the new contents, build a list of files being rolled out
- build the list of files found on the remote system
- delete files that are in list 2 but not in list 1.
Will that work? How would I write that? Is it a common idiom? Or am I
better off with living with ever-changing inode numbers?
I don't want to keep a list of files in the ansible code as this will
never be current, and I don't want to use the same file names regardless
of which distribution is used (I like to be able to look in the
directory to see what I'll find inside the files).
Greetings
Marc
--
-----------------------------------------------------------------------------
Marc Haber | "I don't trust Computers. They | Mailadresse im Header
Leimen, Germany | lose things." Winona Ryder | Fon: *49 6224 1600402
Nordisch by Nature | How to make an American Quilt | Fax: *49 6224 1600421