From 7099a5f4483a3bccd67bee63e9deac242f560486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ne=C4=8Das?= Date: Mon, 15 Mar 2021 10:50:44 +0100 Subject: [PATCH] setup - virtualization facts add Red Hat vendor (#72876) Co-authored-by: Abhijeet Kasurde --- .../72876-setup-facts-add-redhat-vendor.yml | 2 ++ .../module_utils/facts/virtual/linux.py | 24 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/72876-setup-facts-add-redhat-vendor.yml diff --git a/changelogs/fragments/72876-setup-facts-add-redhat-vendor.yml b/changelogs/fragments/72876-setup-facts-add-redhat-vendor.yml new file mode 100644 index 00000000000..d28315a6a59 --- /dev/null +++ b/changelogs/fragments/72876-setup-facts-add-redhat-vendor.yml @@ -0,0 +1,2 @@ +bugfixes: +- "Setup virtualization_facts - add RHV and oVirt type. This change will fully work for VMs in clusters at cluster level 4.4 or newer (https://github.com/ansible/ansible/pull/72876)." diff --git a/lib/ansible/module_utils/facts/virtual/linux.py b/lib/ansible/module_utils/facts/virtual/linux.py index 7e5b5d71a88..fca07e1b1cd 100644 --- a/lib/ansible/module_utils/facts/virtual/linux.py +++ b/lib/ansible/module_utils/facts/virtual/linux.py @@ -139,6 +139,8 @@ class LinuxVirtual(Virtual): virtual_facts['virtualization_role'] = 'guest' product_name = get_file_content('/sys/devices/virtual/dmi/id/product_name') + sys_vendor = get_file_content('/sys/devices/virtual/dmi/id/sys_vendor') + product_family = get_file_content('/sys/devices/virtual/dmi/id/product_family') if product_name in ('KVM', 'KVM Server', 'Bochs', 'AHV'): guest_tech.add('kvm') @@ -146,12 +148,24 @@ class LinuxVirtual(Virtual): virtual_facts['virtualization_type'] = 'kvm' found_virt = True - if product_name == 'RHEV Hypervisor': - guest_tech.add('RHEV') + if sys_vendor == 'oVirt': + guest_tech.add('oVirt') if not found_virt: - virtual_facts['virtualization_type'] = 'RHEV' + virtual_facts['virtualization_type'] = 'oVirt' found_virt = True + if sys_vendor == 'Red Hat': + if product_family == 'RHV': + guest_tech.add('RHV') + if not found_virt: + virtual_facts['virtualization_type'] = 'RHV' + found_virt = True + elif product_family == 'RHEV Hypervisor': + guest_tech.add('RHEV') + if not found_virt: + virtual_facts['virtualization_type'] = 'RHEV' + found_virt = True + if product_name in ('VMware Virtual Platform', 'VMware7,1'): guest_tech.add('VMware') if not found_virt: @@ -184,9 +198,7 @@ class LinuxVirtual(Virtual): virtual_facts['virtualization_type'] = 'kvm' found_virt = True - sys_vendor = get_file_content('/sys/devices/virtual/dmi/id/sys_vendor') - - KVM_SYS_VENDORS = ('QEMU', 'oVirt', 'Amazon EC2', 'DigitalOcean', 'Google', 'Scaleway', 'Nutanix') + KVM_SYS_VENDORS = ('QEMU', 'Amazon EC2', 'DigitalOcean', 'Google', 'Scaleway', 'Nutanix') if sys_vendor in KVM_SYS_VENDORS: guest_tech.add('kvm') if not found_virt: