1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

facts: detect FreeBSD KVM guests (#50030)

Fixes: #49158
This commit is contained in:
Martin Krizek 2018-12-18 21:57:53 +01:00 committed by Jordan Borean
parent 29c3bb48e9
commit 545edc9114
3 changed files with 13 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- Detect FreeBSD KVM guests in facts (https://github.com/ansible/ansible/issues/49158)

View file

@ -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

View file

@ -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):