10000 feat(repositories): stop removing sources files and support unmanaged · saltstack-formulas/apt-formula@8404617 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8404617

Browse files
committed
feat(repositories): stop removing sources files and support unmanaged
1 parent 70d13b3 commit 8404617

File tree

9 files changed

+49
-21
lines changed

9 files changed

+49
-21
lines changed

apt/apt_conf.sls

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 3 deletions
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'],
@@ -24,19 +25,22 @@
2425
'distro': distribution,
2526
'url': 'http://deb.debian.org/debian/',
2627
'arch': arch,
27-
'comps': ['main'],
28+
'comps': debian_comp,
29+
'opts': 'signed-by=/usr/share/keyrings/debian-archive-keyring.gpg'
2830
},
2931
'security-stable': {
3032
'distro': distribution ~ '/updates',
3133
'url': 'http://security.debian.org/',
3234
'arch': arch,
33-
'comps': ['main'],
35+
'comps': debian_comp,
36+
'opts': 'signed-by=/usr/share/keyrings/debian-archive-keyring.gpg'
3437
},
3538
'default-updates': {
3639
'distro': distribution ~ '-updates',
3740
'url': 'http://deb.debian.org/debian/',
3841
'arch': arch,
39-
'comps': ['main'],
42+
'comps': debian_comp,
43+
'opts': 'signed-by=/usr/share/keyrings/debian-archive-keyring.gpg'
4044
},
4145
},
4246
},

apt/repositories.sls

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,28 @@
2323
- replace: False
2424
{% endif %}
2525
26+
{% set excluded_sources = [] %}
27+
{% set unmanaged_repos = [] %}
28+
{% for repo, args in repositories.items() %}
29+
{% if args.unmanaged is defined and args.unmanaged %}
30+
{# repo.list is considered the filename unless filename is explicitly defined.
31+
# managed repo lists files are constructed repo-type.list #}
32+
{% do excluded_sources.append(args.filename if args.filename is defined else repo ~ '.list') %}
33+
{% do unmanaged_repos.append(repo) %}
34+
{% endif %}
35+
{% endfor %}
36+
{% for repo in unmanaged_repos %}
37+
{# remove these repo's to avoid pgrepo.managed loop #}
38+
{% do repositories.pop(repo) %}
39+
{% endfor %}
40+
2641
{{ sources_list_dir }}:
2742
file.directory:
2843
- mode: '0755'
2944
- user: root
3045
- group: root
3146
- clean: {{ clean_sources_list_d }}
47+
- exclude_pat: {{ excluded_sources | json }}
3248
3349
{% for repo, args in repositories.items() %}
3450
@@ -80,7 +96,13 @@
8096
- refresh_db: False
8197
- onchanges_in:
8298
- module: apt.refresh_db
83-
99+
file.managed:
100+
- name: {{ sources_list_dir }}/{{ r_file }}
101+
- replace: false
102+
- require_in:
103+
- file: {{ sources_list_dir }}
104+
# require_in the directory clean state
105+
# This way, we don't remove all the files, just to add them again.
84106
{%- endfor %}
85107
{% endfor %}
86108

kitchen.yml

Lines changed: 4 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ apt:
126126
opts:
127127
trusted: 'yes'
128128
another: whatever
129+
rabbitmq:
130+
unmanaged: true # useful when rabbitmq.list is managed by another formula
129131

130132
preferences:
131133
00-rspamd:

test/integration/repositories/controls/repositories_spec.rb

Lines changed: 2 additions & 7 deletions
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

Lines changed: 3 additions & 7 deletions
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

Lines changed: 5 additions & 0 deletions
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)
0