Skip to content

Commit 69a2c47

Browse files
authored
repository: make role usable for Ubuntu 24.04 @ ARM (#727)
Signed-off-by: Christian Berendt <[email protected]>
1 parent a172e32 commit 69a2c47

File tree

18 files changed

+133
-32
lines changed

18 files changed

+133
-32
lines changed

molecule/delegated/tests/repository/centos.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from ..util.util import (
44
get_ansible,
55
get_variable,
6-
get_dist_role_variable,
6+
get_dist_arch_role_variable,
77
jinja_replacement,
88
)
99

@@ -29,7 +29,7 @@ def test_repository_centos_files(host):
2929
repositories = get_variable(host, "repositories")
3030

3131
if len(repositories) <= 0:
32-
repositories = get_dist_role_variable(host, "__repository_default")
32+
repositories = get_dist_arch_role_variable(host, "__repository_default")
3333

3434
if len(repositories) > 0:
3535
ansible_distribution = get_variable(host, "ansible_distribution", True)

molecule/delegated/tests/repository/debian.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
get_ansible,
55
get_variable,
66
get_from_url,
7-
get_dist_role_variable,
7+
get_dist_arch_role_variable,
88
jinja_replacement,
99
)
1010

@@ -68,10 +68,17 @@ def test_repository_debian_key_files_dir(host):
6868
assert f.mode == 0o644
6969

7070

71-
def test_repository_debian_sources_list_file(host):
71+
def test_repository_debian_sources_file(host):
7272
check_ansible_os_family(host)
7373

74-
f = host.file("/etc/apt/sources.list")
74+
ansible_distribution_release = get_variable(
75+
host, "ansible_distribution_release", True
76+
)
77+
78+
if ansible_distribution_release in ["noble"]:
79+
f = host.file("/etc/apt/sources.list.d/ubuntu.sources")
80+
else:
81+
f = host.file("/etc/apt/sources.list")
7582
assert f.exists
7683
assert f.user == "root"
7784
assert f.group == "root"
@@ -81,22 +88,14 @@ def test_repository_debian_sources_list_file(host):
8188
repositories = get_variable(host, "repositories")
8289

8390
if len(repositories) <= 0:
84-
repositories = get_dist_role_variable(host, "__repository_default")
91+
repositories = get_dist_arch_role_variable(host, "__repository_default")
8592

8693
assert len(repositories) > 0
8794

8895
for repository in repositories:
89-
ansible_distribution_release = get_variable(
90-
host, "ansible_distribution_release", True
91-
)
9296
repository["name"] = jinja_replacement(
9397
repository["name"],
9498
{"ansible_distribution_release": ansible_distribution_release},
9599
)
96-
repository["repository"] = jinja_replacement(
97-
repository["repository"],
98-
{"ansible_distribution_release": ansible_distribution_release},
99-
)
100100

101101
assert repository["name"] in f.content_string
102-
assert repository["repository"] in f.content_string

molecule/delegated/tests/util/util.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ def get_dist_role_variable(host, name):
8484
)
8585

8686

87+
def get_dist_arch_role_variable(host, name):
88+
return get_role_variable(
89+
host,
90+
name,
91+
get_variable(host, "ansible_distribution", True)
92+
+ "-"
93+
+ get_variable(host, "ansible_architecture", True)
94+
+ ".yml",
95+
)
96+
97+
8798
def get_from_url(url, binary=False):
8899
# Create a request object with a faked User-Agent header.
89100
# Some websites like https://pkg.osquery.io/rpm/GPG need this, otherwise they will return http 403 forbidden.

roles/repository/tasks/AlmaLinux.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RedHat.yml

roles/repository/tasks/CentOS.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RedHat.yml

roles/repository/tasks/repository-Debian-family.yml renamed to roles/repository/tasks/Debian.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
when:
2929
- repository_key_ids
3030

31-
# NOTE: We ignore errors that can occur during the seeding of the
32-
# environment in constellations where the repository keys are
33-
# still missing.
31+
# We ignore errors that can occur during the seeding of the
32+
# environment in constellations where the repository keys are
33+
# still missing.
3434
- name: Check if the keys directory exists
3535
ansible.builtin.stat:
3636
path: "{{ repository_key_files_directory }}"
@@ -54,8 +54,7 @@
5454
when:
5555
- result is defined and result.stat.isdir is defined and result.stat.isdir
5656

57-
# NOTE: Not using apt_repository here because it requires python-apt.
58-
57+
# Not using apt_repository here because it requires python-apt.
5958
- name: Copy source.list file
6059
become: true
6160
ansible.builtin.template:

roles/repository/tasks/Rocky.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RedHat.yml

roles/repository/tasks/Ubuntu.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
- name: Create /etc/apt/sources.list.d directory
3+
become: true
4+
ansible.builtin.file:
5+
path: /etc/apt/sources.list.d
6+
state: directory
7+
owner: root
8+
group: root
9+
mode: 0755
10+
11+
- name: Include tasks for Ubuntu < 24.04
12+
ansible.builtin.include_tasks: Debian.yml
13+
when: "ansible_distribution_version is version('24.04', '<')"
14+
15+
- name: Copy 99osism apt configuration
16+
become: true
17+
ansible.builtin.template:
18+
src: 99osism.j2
19+
dest: /etc/apt/apt.conf.d/99osism
20+
mode: 0644
21+
when: "ansible_distribution_version is version('24.04', '>=')"
22+
23+
- name: Remove sources.list file
24+
become: true
25+
ansible.builtin.file:
26+
path: /etc/apt/source.list
27+
state: absent
28+
when: "ansible_distribution_version is version('24.04', '>=')"
29+
30+
- name: Copy ubuntu.sources file
31+
become: true
32+
ansible.builtin.template:
33+
src: ubuntu.sources.j2
34+
dest: /etc/apt/sources.list.d/ubuntu.sources
35+
owner: root
36+
group: root
37+
mode: 0644
38+
backup: true
39+
notify: Force update of package cache
40+
when: "ansible_distribution_version is version('24.04', '>=')"
41+
42+
- name: Update package cache
43+
become: true
44+
ansible.builtin.apt:
45+
cache_valid_time: "{{ repository_cache_valid_time }}"
46+
lock_timeout: "{{ apt_lock_timeout | default(300) }}"
47+
when: "ansible_distribution_version is version('24.04', '>=')"

roles/repository/tasks/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
- name: Gather variables for each operating system
3-
ansible.builtin.include_vars: "{{ ansible_distribution }}-dist.yml"
3+
ansible.builtin.include_vars: "{{ ansible_distribution }}-{{ ansible_architecture }}.yml"
44

5-
- name: Set repository_default variable to default value
5+
- name: Set repository_default fact to default value
66
ansible.builtin.set_fact:
77
repository_default: "{{ __repository_default }}"
88
when: repository_default | default(None) == None
@@ -13,4 +13,4 @@
1313
when: repositories | length == 0
1414

1515
- name: Include distribution specific repository tasks
16-
ansible.builtin.include_tasks: "repository-{{ ansible_os_family }}-family.yml"
16+
ansible.builtin.include_tasks: "{{ ansible_distribution }}.yml"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
2+
3+
{% for item in repositories %}
4+
Types: deb
5+
URIs: {{ item.deb822_uris }}
6+
Suites: {{ item.name }}
7+
Components: {{ item.deb822_components }}
8+
Signed-By: {{ item.deb822_signed_by }}
9+
{{ '' if loop.last else '\n' }}
10+
{% endfor %}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# We only support ARM as of Ubuntu 24.04. Therefore, only the new
2+
# DEB822 format is used here.
3+
---
4+
__repository_default:
5+
- name: "{{ ansible_distribution_release }}"
6+
deb822_uris: http://ports.ubuntu.com/ubuntu-ports/
7+
deb822_components: main restricted universe multiverse
8+
deb822_signed_by: /usr/share/keyrings/ubuntu-archive-keyring.gpg
9+
- name: "{{ ansible_distribution_release }}-backports"
10+
deb822_uris: http://ports.ubuntu.com/ubuntu-ports/
11+
deb822_components: main restricted universe multiverse
12+
deb822_signed_by: /usr/share/keyrings/ubuntu-archive-keyring.gpg
13+
- name: "{{ ansible_distribution_release }}-security"
14+
deb822_uris: http://ports.ubuntu.com/ubuntu-ports/
15+
deb822_components: main restricted universe multiverse
16+
deb822_signed_by: /usr/share/keyrings/ubuntu-archive-keyring.gpg
17+
- name: "{{ ansible_distribution_release }}-updates"
18+
deb822_uris: http://ports.ubuntu.com/ubuntu-ports/
19+
deb822_components: main restricted universe multiverse
20+
deb822_signed_by: /usr/share/keyrings/ubuntu-archive-keyring.gpg

roles/repository/vars/Ubuntu-dist.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
__repository_default:
3+
- name: "{{ ansible_distribution_release }}"
4+
repository: "deb http://de.archive.ubuntu.com/ubuntu/ {{ ansible_distribution_release }} main restricted universe multiverse"
5+
deb822_uris: http://de.archive.ubuntu.com/ubuntu/
6+
deb822_components: main restricted universe multiverse
7+
deb822_signed_by: /usr/share/keyrings/ubuntu-archive-keyring.gpg
8+
- name: "{{ ansible_distribution_release }}-backports"
9+
repository: "deb http://de.archive.ubuntu.com/ubuntu/ {{ ansible_distribution_release }}-backports main restricted universe multiverse"
10+
deb822_uris: http://de.archive.ubuntu.com/ubuntu/
11+
deb822_components: main restricted universe multiverse
12+
deb822_signed_by: /usr/share/keyrings/ubuntu-archive-keyring.gpg
13+
- name: "{{ ansible_distribution_release }}-security"
14+
repository: "deb http://de.archive.ubuntu.com/ubuntu/ {{ ansible_distribution_release }}-security main restricted universe multiverse"
15+
deb822_uris: http://de.archive.ubuntu.com/ubuntu/
16+
deb822_components: main restricted universe multiverse
17+
deb822_signed_by: /usr/share/keyrings/ubuntu-archive-keyring.gpg
18+
- name: "{{ ansible_distribution_release }}-updates"
19+
repository: "deb http://de.archive.ubuntu.com/ubuntu/ {{ ansible_distribution_release }}-updates main restricted universe multiverse"
20+
deb822_uris: http://de.archive.ubuntu.com/ubuntu/
21+
deb822_components: main restricted universe multiverse
22+
deb822_signed_by: /usr/share/keyrings/ubuntu-archive-keyring.gpg

0 commit comments

Comments
 (0)