Don't hardcode the dnf module, dynamically select one (#83183)

pull/83188/head
Matt Martz 2 weeks ago committed by GitHub
parent 2b65166a29
commit dc6b77beca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,40 @@
# Copyright: Contributors to the Ansible project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
from collections import Counter
def parse_module_list(stdout):
lines = stdout.splitlines()
name_offset = 0
empty_offset = -1
modules = []
for i, line in enumerate(lines):
if line.startswith('Name '):
name_offset = i + 1
if not line.strip():
empty_offset = i
for line in lines[name_offset:empty_offset]:
cols = line.split()[:3]
modules.append({
'name': cols[0],
'version': cols[1],
'profile': cols[2].rstrip(','), # Just the first profile
})
return modules
def get_first_single_version_module(stdout):
modules = parse_module_list(stdout)
name = Counter([m['name'] for m in modules]).most_common()[-1][0]
module, = [m for m in modules if m['name'] == name]
return module
class FilterModule:
def filters(self):
return {
'get_first_single_version_module': get_first_single_version_module,
}

@ -62,13 +62,30 @@
- ansible_distribution == 'Fedora'
- ansible_distribution_major_version is version('23', '>=')
- include_tasks: modularity.yml
when:
- when:
- (ansible_distribution == 'Fedora' and ansible_distribution_major_version is version('39', '<')) or
(ansible_distribution in ['RedHat', 'CentOS'] and ansible_distribution_major_version is version('8', '>='))
- not dnf5|default(false)
tags:
- dnf_modularity
block:
# FUTURE - look at including AppStream support in our local repo
- name: list modules
command: dnf module list -q
register: module_list
# A module that only has a single version
- name: Find a module that meets our testing needs
set_fact:
astream_name: '@{{ module.name }}:{{ module.version }}/{{ module.profile }}'
astream_name_no_stream: '@{{ module.name }}/{{ module.profile }}'
vars:
module: '{{ module_list.stdout|get_first_single_version_module }}'
- include_tasks: modularity.yml
tags:
- dnf_modularity
rescue:
# Just in case something crazy happens when listing or parsing modules
- meta: noop
- include_tasks: logging.yml
when: (ansible_distribution == 'Fedora' and ansible_distribution_major_version is version('31', '>=')) or

@ -1,12 +1,3 @@
# FUTURE - look at including AppStream support in our local repo
- name: Include distribution specific variables
include_vars: "{{ item }}"
with_first_found:
- files:
- "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml"
- "{{ ansible_facts.distribution }}.yml"
paths: ../vars
- name: install "{{ astream_name }}" module
dnf:
name: "{{ astream_name }}"

@ -1,2 +0,0 @@
astream_name: '@php:7.2/minimal'
astream_name_no_stream: '@php/minimal'

@ -1,6 +0,0 @@
astream_name: '@varnish:6.0/default'
# For this to work, it needs to be that only shows once in `dnf module list`.
# Such packages, that exist on all the versions we test on, are hard to come by.
# TODO: This would be solved by using our own repo with modularity/streams.
astream_name_no_stream: '@varnish/default'

@ -1,2 +0,0 @@
astream_name: '@php:8.1/minimal'
astream_name_no_stream: '@php/minimal'

@ -1,2 +0,0 @@
astream_name: '@php:7.2/minimal'
astream_name_no_stream: '@php/minimal'
Loading…
Cancel
Save