diff --git a/changelogs/fragments/63683-dnf-handle-empty-appstream-stream.yml b/changelogs/fragments/63683-dnf-handle-empty-appstream-stream.yml new file mode 100644 index 00000000000..e3154957fe4 --- /dev/null +++ b/changelogs/fragments/63683-dnf-handle-empty-appstream-stream.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - dnf - Properly handle module AppStreams that don't define stream (https://github.com/ansible/ansible/issues/63683) diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py index 2a4e2c9080a..cf796bf6886 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -886,9 +886,16 @@ class DnfModule(YumDnf): if self.with_modules: module_spec = module_spec.strip() module_list, nsv = self.module_base._get_modules(module_spec) + enabled_streams = self.base._moduleContainer.getEnabledStream(nsv.name) - if nsv.stream in self.base._moduleContainer.getEnabledStream(nsv.name): - return True + if enabled_streams: + if nsv.stream: + if nsv.stream in enabled_streams: + return True # The provided stream was found + else: + return False # The provided stream was not found + else: + return True # No stream provided, but module found return False # seems like a sane default diff --git a/test/integration/targets/dnf/tasks/modularity.yml b/test/integration/targets/dnf/tasks/modularity.yml index 7c848c2dc36..48a0111a266 100644 --- a/test/integration/targets/dnf/tasks/modularity.yml +++ b/test/integration/targets/dnf/tasks/modularity.yml @@ -49,3 +49,51 @@ that: - "not dnf_result.failed" - "not dnf_result.changed" + +- name: install "{{ astream_name_no_stream }}" module without providing stream + dnf: + name: "{{ astream_name_no_stream }}" + state: present + register: dnf_result + +- name: verify installation of "{{ astream_name_no_stream }}" module without providing stream + assert: + that: + - "not dnf_result.failed" + - "dnf_result.changed" + +- name: install "{{ astream_name_no_stream }}" module again without providing stream + dnf: + name: "{{ astream_name_no_stream }}" + state: present + register: dnf_result + +- name: verify installation of "{{ astream_name_no_stream }}" module again without providing stream + assert: + that: + - "not dnf_result.failed" + - "not dnf_result.changed" + +- name: uninstall "{{ astream_name_no_stream }}" module without providing stream + dnf: + name: "{{ astream_name_no_stream }}" + state: absent + register: dnf_result + +- name: verify uninstallation of "{{ astream_name_no_stream }}" module without providing stream + assert: + that: + - "not dnf_result.failed" + - "dnf_result.changed" + +- name: uninstall "{{ astream_name_no_stream }}" module again without providing stream + dnf: + name: "{{ astream_name_no_stream }}" + state: absent + register: dnf_result + +- name: verify uninstallation of "{{ astream_name_no_stream }}" module again without providing stream + assert: + that: + - "not dnf_result.failed" + - "not dnf_result.changed" diff --git a/test/integration/targets/dnf/vars/Fedora.yml b/test/integration/targets/dnf/vars/Fedora.yml index 25a04e74563..af3de4c1ccb 100644 --- a/test/integration/targets/dnf/vars/Fedora.yml +++ b/test/integration/targets/dnf/vars/Fedora.yml @@ -1 +1,2 @@ -astream_name: '@ripgrep:master/default' +astream_name: '@stratis:1/default' +astream_name_no_stream: '@stratis/default' diff --git a/test/integration/targets/dnf/vars/RedHat.yml b/test/integration/targets/dnf/vars/RedHat.yml index 0fd8ee4b01d..c70d8538d81 100644 --- a/test/integration/targets/dnf/vars/RedHat.yml +++ b/test/integration/targets/dnf/vars/RedHat.yml @@ -1 +1,2 @@ astream_name: '@php:7.2/minimal' +astream_name_no_stream: '@php/minimal'