summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Doran <sdoran@redhat.com>2019-10-14 12:30:46 -0400
committerToshio Kuratomi <a.badger@gmail.com>2019-11-01 08:40:49 -0700
commita0fb10c2ab309524430d9e11e6513df9e948134b (patch)
treed4d96b2e1ab1affec3c67d2b2337451eb63274b3
parent353c9cb99d374365f07c847e039f8f95d564a044 (diff)
downloadansible-a0fb10c2ab309524430d9e11e6513df9e948134b.tar.gz
[stable-2.9] package_facts - use AnsibleModule.warn() for warnings
(cherry picked from commit 2b1e24fc49) Co-authored-by: Sam Doran <sdoran@redhat.com>
-rw-r--r--changelogs/fragments/package-facts-use-module-warnings.yaml2
-rw-r--r--lib/ansible/module_utils/facts/packages.py2
-rw-r--r--lib/ansible/modules/packaging/os/package_facts.py7
3 files changed, 4 insertions, 7 deletions
diff --git a/changelogs/fragments/package-facts-use-module-warnings.yaml b/changelogs/fragments/package-facts-use-module-warnings.yaml
new file mode 100644
index 0000000000..b837bc972d
--- /dev/null
+++ b/changelogs/fragments/package-facts-use-module-warnings.yaml
@@ -0,0 +1,2 @@
+bugfixes:
+ - package_facts - use module warnings rather than a custom implementation for reporting warnings
diff --git a/lib/ansible/module_utils/facts/packages.py b/lib/ansible/module_utils/facts/packages.py
index 8a3cb198f0..39b65f7812 100644
--- a/lib/ansible/module_utils/facts/packages.py
+++ b/lib/ansible/module_utils/facts/packages.py
@@ -18,8 +18,6 @@ def get_all_pkg_managers():
class PkgMgr(with_metaclass(ABCMeta, object)):
- warnings = []
-
@abstractmethod
def is_available(self):
# This method is supposed to return True/False if the package manager is currently installed/usable
diff --git a/lib/ansible/modules/packaging/os/package_facts.py b/lib/ansible/modules/packaging/os/package_facts.py
index 9ec4ce39ca..2ff76fefda 100644
--- a/lib/ansible/modules/packaging/os/package_facts.py
+++ b/lib/ansible/modules/packaging/os/package_facts.py
@@ -230,7 +230,7 @@ class RPM(LibMgr):
''' we expect the python bindings installed, but this gives warning if they are missing and we have rpm cli'''
we_have_lib = super(RPM, self).is_available()
if not we_have_lib and get_bin_path('rpm'):
- self.warnings.append('Found "rpm" but %s' % (missing_required_lib('rpm')))
+ module.warn('Found "rpm" but %s' % (missing_required_lib('rpm')))
return we_have_lib
@@ -256,7 +256,7 @@ class APT(LibMgr):
if not we_have_lib:
for exe in ('apt', 'apt-get', 'aptitude'):
if get_bin_path(exe):
- self.warnings.append('Found "%s" but %s' % (exe, missing_required_lib('apt')))
+ module.warn('Found "%s" but %s' % (exe, missing_required_lib('apt')))
break
return we_have_lib
@@ -382,9 +382,6 @@ def main():
module.warn('Requested package manager %s was not usable by this module: %s' % (pkgmgr, to_text(e)))
continue
- for warning in getattr(manager, 'warnings', []):
- module.warn(warning)
-
except Exception as e:
if pkgmgr in module.params['manager']:
module.warn('Failed to retrieve packages with %s: %s' % (pkgmgr, to_text(e)))