diff --git a/changelogs/fragments/49158-detect-kvm-on-freebsd.yaml b/changelogs/fragments/49158-detect-kvm-on-freebsd.yaml new file mode 100644 index 0000000000..282c7c393f --- /dev/null +++ b/changelogs/fragments/49158-detect-kvm-on-freebsd.yaml @@ -0,0 +1,2 @@ +bugfixes: + - Detect FreeBSD KVM guests in facts (https://github.com/ansible/ansible/issues/49158) diff --git a/lib/ansible/module_utils/facts/virtual/freebsd.py b/lib/ansible/module_utils/facts/virtual/freebsd.py index 132fe8d93d..47360aa6cc 100644 --- a/lib/ansible/module_utils/facts/virtual/freebsd.py +++ b/lib/ansible/module_utils/facts/virtual/freebsd.py @@ -19,9 +19,10 @@ __metaclass__ = type import os from ansible.module_utils.facts.virtual.base import Virtual, VirtualCollector +from ansible.module_utils.facts.virtual.sysctl import VirtualSysctlDetectionMixin -class FreeBSDVirtual(Virtual): +class FreeBSDVirtual(Virtual, VirtualSysctlDetectionMixin): """ This is a FreeBSD-specific subclass of Virtual. It defines - virtualization_type @@ -39,6 +40,14 @@ class FreeBSDVirtual(Virtual): virtual_facts['virtualization_type'] = 'xen' virtual_facts['virtualization_role'] = 'guest' + if virtual_facts['virtualization_type'] == '': + virtual_product_facts = self.detect_virt_product('kern.vm_guest') or self.detect_virt_product('hw.hv_vendor') + virtual_facts.update(virtual_product_facts) + + if virtual_facts['virtualization_type'] == '': + virtual_vendor_facts = self.detect_virt_vendor('hw.model') + virtual_facts.update(virtual_vendor_facts) + return virtual_facts diff --git a/lib/ansible/module_utils/facts/virtual/sysctl.py b/lib/ansible/module_utils/facts/virtual/sysctl.py index eb7dbffbff..b1583949fe 100644 --- a/lib/ansible/module_utils/facts/virtual/sysctl.py +++ b/lib/ansible/module_utils/facts/virtual/sysctl.py @@ -30,7 +30,7 @@ class VirtualSysctlDetectionMixin(object): if self.sysctl_path: rc, out, err = self.module.run_command("%s -n %s" % (self.sysctl_path, key)) if rc == 0: - if re.match('(KVM|Bochs|SmartDC).*', out): + if re.match('(KVM|kvm|Bochs|SmartDC).*', out): virtual_product_facts['virtualization_type'] = 'kvm' virtual_product_facts['virtualization_role'] = 'guest' elif re.match('.*VMware.*', out):