From ae0a9a5e9cfab4f910ca15861787cccc3c9bb600 Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Thu, 29 Mar 2018 17:48:45 -0400 Subject: [PATCH] continue fact gathering even without dmidecode (#34925) (#38001) * continue fact gathering even without dmidecode If dmidecode is not available we still wan to continue with fact gathering. On certain platforms dmidecode just won't work (cherry picked from commit cbe2915ba5236030ba560ba870b97f57e09bebe7) Fixes #37911 --- lib/ansible/module_utils/facts/virtual/linux.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/ansible/module_utils/facts/virtual/linux.py b/lib/ansible/module_utils/facts/virtual/linux.py index a0ad54584b3..fece8d8f22b 100644 --- a/lib/ansible/module_utils/facts/virtual/linux.py +++ b/lib/ansible/module_utils/facts/virtual/linux.py @@ -236,13 +236,15 @@ class LinuxVirtual(Virtual): # In older Linux Kernel versions, /sys filesystem is not available # dmidecode is the safest option to parse virtualization related values dmi_bin = self.module.get_bin_path('dmidecode') - (rc, out, err) = self.module.run_command('%s -s system-product-name' % dmi_bin) - if rc == 0: - # Strip out commented lines (specific dmidecode output) - vendor_name = ''.join([line.strip() for line in out.splitlines() if not line.startswith('#')]) - if vendor_name in ['VMware Virtual Platform', 'VMware7,1']: - virtual_facts['virtualization_type'] = 'VMware' - virtual_facts['virtualization_role'] = 'guest' + # We still want to continue even if dmidecode is not available + if dmi_bin is not None: + (rc, out, err) = self.module.run_command('%s -s system-product-name' % dmi_bin) + if rc == 0: + # Strip out commented lines (specific dmidecode output) + vendor_name = ''.join([line.strip() for line in out.splitlines() if not line.startswith('#')]) + if vendor_name.startwith('VMware'): + virtual_facts['virtualization_type'] = 'VMware' + virtual_facts['virtualization_role'] = 'guest' # If none of the above matches, return 'NA' for virtualization_type # and virtualization_role. This allows for proper grouping.