From d1c94fe11033dee63c000033e6c2a997b6b75421 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 9 Jul 2024 13:44:21 -0700 Subject: [PATCH] [stable-2.17] package_facts: ignore warnings by apk on stderr (#83519) * [stable-2.17] package_facts: ignore warnings by apk on stderr Ignore warnings sent by apk cli on stderr Partial backport of https://github.com/ansible/ansible/pull/83149 Fixes: #83501 Signed-off-by: Abhijeet Kasurde * CI fixes Signed-off-by: Abhijeet Kasurde --------- Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/package_facts_apk.yml | 3 +++ lib/ansible/modules/package_facts.py | 2 +- .../targets/package_facts/tasks/main.yml | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/package_facts_apk.yml diff --git a/changelogs/fragments/package_facts_apk.yml b/changelogs/fragments/package_facts_apk.yml new file mode 100644 index 00000000000..06632b2c3ef --- /dev/null +++ b/changelogs/fragments/package_facts_apk.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - package_facts - ignore warnings sent by apk on stderr (https://github.com/ansible/ansible/issues/83501). diff --git a/lib/ansible/modules/package_facts.py b/lib/ansible/modules/package_facts.py index 11a8f61fdb0..dd9badfe1e8 100644 --- a/lib/ansible/modules/package_facts.py +++ b/lib/ansible/modules/package_facts.py @@ -440,7 +440,7 @@ class APK(CLIMgr): def list_installed(self): rc, out, err = module.run_command([self._cli, 'info', '-v']) - if rc != 0 or err: + if rc != 0: raise Exception("Unable to list packages rc=%s : %s" % (rc, err)) return out.splitlines() diff --git a/test/integration/targets/package_facts/tasks/main.yml b/test/integration/targets/package_facts/tasks/main.yml index 12dfcf03164..6d4b04da500 100644 --- a/test/integration/targets/package_facts/tasks/main.yml +++ b/test/integration/targets/package_facts/tasks/main.yml @@ -65,6 +65,19 @@ that: ansible_facts.packages is defined when: (ansible_os_family == "openSUSE Leap") or (ansible_os_family == "Suse") +- name: Same as those above, but based on pkg_mgr + block: + - name: Gather package facts + package_facts: + manager: '{{ ansible_facts["pkg_mgr"] }}' + + - name: check for ansible_facts.packages exists + assert: + that: + - ansible_facts.packages is defined + - ansible_facts.packages | length > 1 + when: ansible_facts['os_family'] in ["openSUSE Leap", "Suse", "Debian"] + # Check that auto detection works also - name: Gather package facts package_facts: