Skip to content

Commit f47e94d

Browse files
authored
F #127: Make pre-enabled DNF repos customizable (#128)
1 parent ff12bdf commit f47e94d

3 files changed

Lines changed: 44 additions & 16 deletions

File tree

roles/repository/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Role Variables
4040
| `opennebula_repo_key_url` | `dict` | | | OpenNebula GPG key urls for Debian/RedHat distros. |
4141
| `opennebula_repo_path` | `dict` | | | OpenNebula repo definition paths for Debian/RedHat distros. |
4242
| `opennebula_repo_url` | `dict` | | (check below) | OpenNebula repo url for Debian/RedHat distros. |
43+
| `opennebula_repo_pre_enable` | `dict` | | (check below) | Definition of DNF repos to pre-enable in RedHat-like distros. |
4344

4445
Dependencies
4546
------------
@@ -56,6 +57,12 @@ Example Playbook
5657
# Enable OpenNebula EE repo.
5758
one_token: 'asd123as:123asd12'
5859

60+
# Enable only 'epel' and 'crb' DNF repos in Alma Linux 9
61+
opennebula_repo_pre_enable:
62+
AlmaLinux:
63+
config_manager:
64+
'9': [epel, crb]
65+
5966
# Use custom / local / insecure OpenNebula repo.
6067
opennebula_repo_force_trusted: true
6168
opennebula_repo_url:

roles/repository/defaults/main.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,19 @@ opennebula_repo_url_defaults:
142142
{%- else -%}
143143
https://downloads.opennebula.io/repo/{{ one_version }}/{{ ansible_distribution }}/{{ ansible_distribution_version }}
144144
{%- endif -%}
145+
146+
opennebula_repo_pre_enable_defaults:
147+
AlmaLinux:
148+
config_manager:
149+
'8': [epel, powertools, ha]
150+
'9': [epel, crb, highavailability]
151+
subscription_manager:
152+
'8': []
153+
'9': []
154+
RedHat:
155+
config_manager:
156+
'8': [epel]
157+
'9': [epel]
158+
subscription_manager:
159+
'8': [codeready-builder-for-rhel-8-x86_64-rpms, rhel-8-for-x86_64-highavailability-rpms]
160+
'9': [codeready-builder-for-rhel-9-x86_64-rpms, rhel-9-for-x86_64-highavailability-rpms]

roles/repository/tasks/opennebula.yml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
---
22
- when: ansible_pkg_mgr == 'dnf'
33
block:
4+
- name: Compute facts (DNF)
5+
ansible.builtin.set_fact:
6+
opennebula_repo_pre_enable: >-
7+
{{ opennebula_repo_pre_enable_defaults | combine(opennebula_repo_pre_enable | d({}), recursive=true) }}
8+
49
- name: Enable required DNF extra repos
510
ansible.builtin.shell:
611
cmd: |
712
set -o errexit
8-
{{ _script[ansible_distribution][ansible_distribution_major_version] }}
13+
14+
{% if _config_manager | count > 0 %}
15+
dnf config-manager -y --enable {{ _config_manager | map('regex_replace', '^(.*)$', "'\g<1>'") | join(' ') }}
16+
{% endif %}
17+
18+
{% if _subscription_manager | count > 0 %}
19+
subscription-manager repos {{ _subscription_manager | map('regex_replace', '^(.*)$', "--enable '\g<1>'") | join(' ') }}
20+
{% endif %}
921
executable: /bin/bash
1022
changed_when: false
1123
vars:
12-
_script:
13-
AlmaLinux:
14-
'8': |
15-
dnf config-manager -y --enable epel powertools ha
16-
'9': |
17-
dnf config-manager -y --enable epel crb highavailability
18-
RedHat:
19-
'8': |
20-
dnf config-manager -y --enable epel
21-
subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpms \
22-
--enable rhel-8-for-x86_64-highavailability-rpms
23-
'9': |
24-
dnf config-manager -y --enable epel
25-
subscription-manager repos --enable codeready-builder-for-rhel-9-x86_64-rpms \
26-
--enable rhel-9-for-x86_64-highavailability-rpms
24+
_config_manager: >-
25+
{{ opennebula_repo_pre_enable[ansible_distribution].config_manager[ansible_distribution_major_version]
26+
| d([])
27+
| map('replace', "'", '') }}
28+
_subscription_manager: >-
29+
{{ opennebula_repo_pre_enable[ansible_distribution].subscription_manager[ansible_distribution_major_version]
30+
| d([])
31+
| map('replace', "'", '') }}
2732
2833
- vars:
2934
# Merge repository config with defaults.

0 commit comments

Comments
 (0)