From 21ac550828ce0faaa8b9e5b2bb9258908cce705c Mon Sep 17 00:00:00 2001 From: Rick Elrod Date: Thu, 23 Jul 2020 19:50:04 -0500 Subject: [PATCH] virtualization facts: check /dev/kvm as a fallback (#70829) Change: - On Linux, there are situations where a host might be a KVM host but not have the kernel module enabled (it might be compiled in instead). In these cases, /dev/kvm will still exist, and rather than reporting NA, we should report that the host is a KVM host. Test Plan: - Local Signed-off-by: Rick Elrod --- changelogs/fragments/dev-kvm.yml | 2 ++ lib/ansible/module_utils/facts/virtual/linux.py | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 changelogs/fragments/dev-kvm.yml diff --git a/changelogs/fragments/dev-kvm.yml b/changelogs/fragments/dev-kvm.yml new file mode 100644 index 00000000000..d18b1e4101a --- /dev/null +++ b/changelogs/fragments/dev-kvm.yml @@ -0,0 +1,2 @@ +minor_changes: + - facts - ``/dev/kvm`` is now consulted in Linux virtualization facts, and the host is considered a KVM host if this file exists and none of the pre-existing checks matched. diff --git a/lib/ansible/module_utils/facts/virtual/linux.py b/lib/ansible/module_utils/facts/virtual/linux.py index e133df42958..db591402871 100644 --- a/lib/ansible/module_utils/facts/virtual/linux.py +++ b/lib/ansible/module_utils/facts/virtual/linux.py @@ -238,6 +238,11 @@ class LinuxVirtual(Virtual): virtual_facts['virtualization_role'] = 'guest' return virtual_facts + if os.path.exists('/dev/kvm'): + virtual_facts['virtualization_type'] = 'kvm' + virtual_facts['virtualization_role'] = 'host' + return virtual_facts + # If none of the above matches, return 'NA' for virtualization_type # and virtualization_role. This allows for proper grouping. virtual_facts['virtualization_type'] = 'NA'