Feature/improve bhyve guest and host detection (#85767)

This commit is contained in:
biancalana
2025-11-13 14:18:00 +00:00
committed by GitHub
parent dc3cc0f9ea
commit eb0ada3d28
5 changed files with 31 additions and 2 deletions

View File

@@ -0,0 +1,2 @@
bugfixes:
- ansible_virtualization_role and ansible_virtualization_type facts - fix the detection of vms running inside FreeBSD Bhyve hypervisor and detection of jails (https://github.com/ansible/ansible/pull/85767)

View File

@@ -56,10 +56,11 @@ class FreeBSDVirtual(Virtual, VirtualSysctlDetectionMixin):
host_tech.update(sec_jail_jailed['virtualization_tech_host'])
if virtual_facts['virtualization_type'] == '':
sysctl = kern_vm_guest or hw_hv_vendor or sec_jail_jailed
# We call update here, then re-set virtualization_tech_host/guest
# later.
virtual_facts.update(sysctl)
for sysctl in [kern_vm_guest, hw_hv_vendor, sec_jail_jailed]:
if sysctl:
virtual_facts.update(sysctl)
virtual_vendor_facts = self.detect_virt_vendor('hw.model')
guest_tech.update(virtual_vendor_facts['virtualization_tech_guest'])
@@ -68,6 +69,16 @@ class FreeBSDVirtual(Virtual, VirtualSysctlDetectionMixin):
if virtual_facts['virtualization_type'] == '':
virtual_facts.update(virtual_vendor_facts)
# if vmm.ko kernel module is loaded
kldstat_bin = self.module.get_bin_path('kldstat')
if kldstat_bin is not None:
(rc, out, err) = self.module.run_command('%s -q -m vmm' % kldstat_bin)
if rc == 0:
host_tech.add('bhyve')
virtual_facts['virtualization_type'] = 'bhyve'
virtual_facts['virtualization_role'] = 'host'
virtual_facts['virtualization_tech_guest'] = guest_tech
virtual_facts['virtualization_tech_host'] = host_tech
return virtual_facts

View File

@@ -187,6 +187,12 @@ class LinuxVirtual(Virtual):
virtual_facts['virtualization_type'] = 'openstack'
found_virt = True
if product_name == 'BHYVE':
guest_tech.add('bhyve')
if not found_virt:
virtual_facts['virtualization_type'] = 'bhyve'
found_virt = True
bios_vendor = get_file_content('/sys/devices/virtual/dmi/id/bios_vendor')
if bios_vendor == 'Xen':

View File

@@ -115,6 +115,10 @@ class SunOSVirtual(Virtual):
guest_tech.add('kvm')
virtual_facts['virtualization_type'] = 'kvm'
virtual_facts['virtualization_role'] = 'guest'
elif 'BHYVE' in line:
guest_tech.add('bhyve')
virtual_facts['virtualization_type'] = 'bhyve'
virtual_facts['virtualization_role'] = 'guest'
virtual_facts['virtualization_tech_guest'] = guest_tech
virtual_facts['virtualization_tech_host'] = host_tech

View File

@@ -65,6 +65,12 @@ class VirtualSysctlDetectionMixin:
virtual_product_facts['virtualization_type'] = 'RHEV'
virtual_product_facts['virtualization_role'] = 'guest'
found_virt = True
if out.rstrip() == 'bhyve':
guest_tech.add('bhyve')
if not found_virt:
virtual_product_facts['virtualization_type'] = 'bhyve'
virtual_product_facts['virtualization_role'] = 'guest'
found_virt = True
if (key == 'security.jail.jailed') and (out.rstrip() == '1'):
guest_tech.add('jails')
if not found_virt: