From 3950f5b9ce07cdcf398f7043034908648945753a Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Mon, 15 Jan 2018 22:16:43 +0530 Subject: [PATCH] facts: Get virtual facts about VMware (#34132) This fixes fact gathering of VMware guest machines with older Linux Kernel versions. These older Kernels do not support /sys filesystem which is used to gather virtualization related facts. 'dmidecode' is the safest option to find out virtualization related facts. Fixes: #21573 Signed-off-by: Abhijeet Kasurde --- lib/ansible/module_utils/facts/virtual/linux.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/ansible/module_utils/facts/virtual/linux.py b/lib/ansible/module_utils/facts/virtual/linux.py index 68f3cfe0a20..fcb1568f3e9 100644 --- a/lib/ansible/module_utils/facts/virtual/linux.py +++ b/lib/ansible/module_utils/facts/virtual/linux.py @@ -220,6 +220,17 @@ class LinuxVirtual(Virtual): virtual_facts['virtualization_role'] = 'guest' return virtual_facts + # 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' + # If none of the above matches, return 'NA' for virtualization_type # and virtualization_role. This allows for proper grouping. virtual_facts['virtualization_type'] = 'NA'