Skip to content

Commit acbbd44

Browse files
committed
feat(repositories): stop removing sources files and support unmanaged
1 parent e6230fb commit acbbd44

File tree

9 files changed

+49
-21
lines changed

9 files changed

+49
-21
lines changed

apt/apt_conf.sls

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
{{ confd_dir }}:
2020
file.directory:
21-
- mode: 755
21+
- mode: '0755'
2222
- user: root
2323
- group: root
2424
- clean: {{ clean_apt_conf_d }}
@@ -30,7 +30,7 @@
3030
- template: jinja
3131
- user: root
3232
- group: root
33-
- mode: 644
33+
- mode: '0644'
3434
- context:
3535
data: {{ contents }}
3636
- require_in:

apt/listchanges.sls

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ apt_listchanges_pkgs:
1313
- template: jinja
1414
- user: root
1515
- group: root
16-
- mode: 644
16+
- mode: '0644'
1717
- source: {{ listchanges_config_template }}

apt/map.jinja

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{% set distribution = salt['grains.get']('lsb_distrib_codename') %}
22
{% set arch = salt['grains.get']('osarch').split(' ') %}
3+
{% set debian_comp = ['main', 'contrib', 'non-free', 'non-free-firmware'] if salt['grains.get']('osmajorrelease') >= 12 else ['main', 'contrib', 'non-free'] %}
34
{% set apt = salt['grains.filter_by']({
45
'Debian': {
56
'pkgs': ['unattended-upgrades'],
@@ -26,19 +27,22 @@
2627
'distro': distribution,
2728
'url': 'http://deb.debian.org/debian/',
2829
'arch': arch,
29-
'comps': ['main'],
30+
'comps': debian_comp,
31+
'opts': 'signed-by=/usr/share/keyrings/debian-archive-keyring.gpg'
3032
},
3133
'security-stable': {
3234
'distro': distribution ~ '/updates',
3335
'url': 'http://security.debian.org/',
3436
'arch': arch,
35-
'comps': ['main'],
37+
'comps': debian_comp,
38+
'opts': 'signed-by=/usr/share/keyrings/debian-archive-keyring.gpg'
3639
},
3740
'default-updates': {
3841
'distro': distribution ~ '-updates',
3942
'url': 'http://deb.debian.org/debian/',
4043
'arch': arch,
41-
'comps': ['main'],
44+
'comps': debian_comp,
45+
'opts': 'signed-by=/usr/share/keyrings/debian-archive-keyring.gpg'
4246
},
4347
},
4448
},

apt/repositories.sls

+23-1
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,28 @@
2525
- replace: False
2626
{% endif %}
2727
28+
{% set excluded_sources = [] %}
29+
{% set unmanaged_repos = [] %}
30+
{% for repo, args in repositories.items() %}
31+
{% if args.unmanaged is defined and args.unmanaged %}
32+
{# repo.list is considered the filename unless filename is explicitly defined.
33+
# managed repo lists files are constructed repo-type.list #}
34+
{% do excluded_sources.append(args.filename if args.filename is defined else repo ~ '.list') %}
35+
{% do unmanaged_repos.append(repo) %}
36+
{% endif %}
37+
{% endfor %}
38+
{% for repo in unmanaged_repos %}
39+
{# remove these repo's to avoid pgrepo.managed loop #}
40+
{% do repositories.pop(repo) %}
41+
{% endfor %}
42+
2843
{{ sources_list_dir }}:
2944
file.directory:
3045
- mode: '0755'
3146
- user: root
3247
- group: root
3348
- clean: {{ clean_sources_list_d }}
49+
- exclude_pat: {{ excluded_sources | json }}
3450
3551
{{ keyrings_dir }}:
3652
file.directory:
@@ -95,7 +111,13 @@
95111
{% endif %}
96112
- onchanges_in:
97113
- module: apt.refresh_db
98-
114+
file.managed:
115+
- name: {{ sources_list_dir }}/{{ r_file }}
116+
- replace: false
117+
- require_in:
118+
- file: {{ sources_list_dir }}
119+
# require_in the directory clean state
120+
# This way, we don't remove all the files, just to add them again.
99121
{%- endfor %}
100122
{% endfor %}
101123

kitchen.yml

+4
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ suites:
259259
state_top:
260260
base:
261261
'*':
262+
- states/unmanaged
262263
- apt._mapdata
263264
- apt.repositories
264265
- apt.update
@@ -269,6 +270,9 @@ suites:
269270
- apt
270271
pillars_from_files:
271272
apt.sls: test/salt/pillar/repositories.sls
273+
dependencies:
274+
- name: states
275+
path: ./test/salt
272276
verifier:
273277
inspec_tests:
274278
- path: test/integration/repositories

pillar.example

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ apt:
136136
type: [binary]
137137
key_url: https://packages.broadcom.com/artifactory/api/security/keypair/SaltProjectKey/public # yamllint disable-line rule:line-length
138138
opts: "signed-by=/etc/apt/keyrings/salt-archive-keyring.pgp"
139+
rabbitmq:
140+
unmanaged: true # useful when rabbitmq.list is managed by another formula
139141

140142
preferences:
141143
00-rspamd:

test/integration/repositories/controls/repositories_spec.rb

+2-7
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,10 @@
2525
its('mode') { should cmp '0755' }
2626
end
2727

28-
describe file('/etc/apt/sources.list.d/multimedia-stable-binary.list') do
28+
describe file('/etc/apt/sources.list.d/unmanaged.list') do
2929
it { should exist }
30-
it { should be_owned_by 'root' }
31-
it { should be_grouped_into 'root' }
32-
its('mode') { should cmp '0644' }
3330
its(:content) do
34-
should match(
35-
%r{deb \[arch=amd64\] http://www.deb-multimedia.org stable main}
36-
)
31+
should match("## unmanged list file that shouldn't be removed")
3732
end
3833
end
3934

test/salt/pillar/repositories.sls

+3-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@ apt:
66
clean_sources_list_d: true
77

88
repositories:
9-
multimedia-stable:
10-
distro: stable
11-
url: http://www.deb-multimedia.org
12-
arch: [amd64]
13-
comps: [main]
14-
keyid: 5C808C2B65558117
15-
keyserver: keyserver.ubuntu.com
9+
unmanaged:
10+
unmanaged: true # do not remove this file when clean_sources_list_d=true
11+
filename: unmanaged.list # optional
1612
heroku:
1713
distro: ./
1814
url: https://cli-assets.heroku.com/apt

test/salt/states/unmanaged.sls

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
repos_maintained_by_another_formula:
2+
file.managed:
3+
- name: /etc/apt/sources.list.d/unmanaged.list
4+
- mode: '0644'
5+
- contents: "## unmanged list file that shouldn't be removed"

0 commit comments

Comments
 (0)