|
|
|
@ -130,7 +130,7 @@ class Facts(object):
|
|
|
|
|
self.facts['selinux']['policyvers'] = 'unknown'
|
|
|
|
|
try:
|
|
|
|
|
(rc, configmode) = selinux.selinux_getenforcemode()
|
|
|
|
|
if rc == 0 and Facts.SELINUX_MODE_DICT.has_key(configmode):
|
|
|
|
|
if rc == 0 and configmode in Facts.SELINUX_MODE_DICT:
|
|
|
|
|
self.facts['selinux']['config_mode'] = Facts.SELINUX_MODE_DICT[configmode]
|
|
|
|
|
else:
|
|
|
|
|
self.facts['selinux']['config_mode'] = 'unknown'
|
|
|
|
@ -138,7 +138,7 @@ class Facts(object):
|
|
|
|
|
self.facts['selinux']['config_mode'] = 'unknown'
|
|
|
|
|
try:
|
|
|
|
|
mode = selinux.security_getenforce()
|
|
|
|
|
if Facts.SELINUX_MODE_DICT.has_key(mode):
|
|
|
|
|
if mode in Facts.SELINUX_MODE_DICT:
|
|
|
|
|
self.facts['selinux']['mode'] = Facts.SELINUX_MODE_DICT[mode]
|
|
|
|
|
else:
|
|
|
|
|
self.facts['selinux']['mode'] = 'unknown'
|
|
|
|
@ -196,19 +196,21 @@ class LinuxHardware(Hardware):
|
|
|
|
|
|
|
|
|
|
In addition, it also defines number of DMI facts.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
platform = 'Linux'
|
|
|
|
|
MEMORY_FACTS = ['MemTotal', 'SwapTotal', 'MemFree', 'SwapFree']
|
|
|
|
|
# DMI bits
|
|
|
|
|
DMI_DICT = { 'form_factor': '/sys/devices/virtual/dmi/id/chassis_type',
|
|
|
|
|
'product_name': '/sys/devices/virtual/dmi/id/product_name',
|
|
|
|
|
'product_serial': '/sys/devices/virtual/dmi/id/product_serial',
|
|
|
|
|
'product_uuid': '/sys/devices/virtual/dmi/id/product_uuid',
|
|
|
|
|
'product_version': '/sys/devices/virtual/dmi/id/product_version',
|
|
|
|
|
'system_vendor': '/sys/devices/virtual/dmi/id/sys_vendor',
|
|
|
|
|
'bios_date': '/sys/devices/virtual/dmi/id/bios_date',
|
|
|
|
|
'bios_version': '/sys/devices/virtual/dmi/id/bios_version' }
|
|
|
|
|
# From smolt and DMI spec
|
|
|
|
|
# See http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.0.pdf
|
|
|
|
|
DMI_DICT = dict(
|
|
|
|
|
form_factor = '/sys/devices/virtual/dmi/id/chassis_type',
|
|
|
|
|
product_name = '/sys/devices/virtual/dmi/id/product_name',
|
|
|
|
|
product_serial = '/sys/devices/virtual/dmi/id/product_serial',
|
|
|
|
|
product_uuid = '/sys/devices/virtual/dmi/id/product_uuid',
|
|
|
|
|
product_version = '/sys/devices/virtual/dmi/id/product_version',
|
|
|
|
|
system_vendor = '/sys/devices/virtual/dmi/id/sys_vendor',
|
|
|
|
|
bios_date = '/sys/devices/virtual/dmi/id/bios_date',
|
|
|
|
|
bios_version = '/sys/devices/virtual/dmi/id/bios_version'
|
|
|
|
|
)
|
|
|
|
|
# DMI SPEC -- http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.0.pdf
|
|
|
|
|
FORM_FACTOR = [ "Unknown", "Other", "Unknown", "Desktop",
|
|
|
|
|
"Low Profile Desktop", "Pizza Box", "Mini Tower", "Tower",
|
|
|
|
|
"Portable", "Laptop", "Notebook", "Hand Held", "Docking Station",
|
|
|
|
@ -634,36 +636,36 @@ def run_setup(module):
|
|
|
|
|
# ruby-json is ALSO installed, include facter data in the JSON
|
|
|
|
|
|
|
|
|
|
if os.path.exists("/usr/bin/facter"):
|
|
|
|
|
cmd = subprocess.Popen("/usr/bin/facter --json", shell=True,
|
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
|
out, err = cmd.communicate()
|
|
|
|
|
facter = True
|
|
|
|
|
try:
|
|
|
|
|
facter_ds = json.loads(out)
|
|
|
|
|
except:
|
|
|
|
|
facter = False
|
|
|
|
|
if facter:
|
|
|
|
|
for (k,v) in facter_ds.items():
|
|
|
|
|
setup_options["facter_%s" % k] = v
|
|
|
|
|
cmd = subprocess.Popen("/usr/bin/facter --json", shell=True,
|
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
|
out, err = cmd.communicate()
|
|
|
|
|
facter = True
|
|
|
|
|
try:
|
|
|
|
|
facter_ds = json.loads(out)
|
|
|
|
|
except:
|
|
|
|
|
facter = False
|
|
|
|
|
if facter:
|
|
|
|
|
for (k,v) in facter_ds.items():
|
|
|
|
|
setup_options["facter_%s" % k] = v
|
|
|
|
|
|
|
|
|
|
# ditto for ohai, but just top level string keys
|
|
|
|
|
# because it contains a lot of nested stuff we can't use for
|
|
|
|
|
# templating w/o making a nicer key for it (TODO)
|
|
|
|
|
|
|
|
|
|
if os.path.exists("/usr/bin/ohai"):
|
|
|
|
|
cmd = subprocess.Popen("/usr/bin/ohai", shell=True,
|
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
|
out, err = cmd.communicate()
|
|
|
|
|
ohai = True
|
|
|
|
|
try:
|
|
|
|
|
ohai_ds = json.loads(out)
|
|
|
|
|
except:
|
|
|
|
|
ohai = False
|
|
|
|
|
if ohai:
|
|
|
|
|
for (k,v) in ohai_ds.items():
|
|
|
|
|
if type(v) == str or type(v) == unicode:
|
|
|
|
|
k2 = "ohai_%s" % k
|
|
|
|
|
setup_options[k2] = v
|
|
|
|
|
cmd = subprocess.Popen("/usr/bin/ohai", shell=True,
|
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
|
out, err = cmd.communicate()
|
|
|
|
|
ohai = True
|
|
|
|
|
try:
|
|
|
|
|
ohai_ds = json.loads(out)
|
|
|
|
|
except:
|
|
|
|
|
ohai = False
|
|
|
|
|
if ohai:
|
|
|
|
|
for (k,v) in ohai_ds.items():
|
|
|
|
|
if type(v) == str or type(v) == unicode:
|
|
|
|
|
k2 = "ohai_%s" % k
|
|
|
|
|
setup_options[k2] = v
|
|
|
|
|
|
|
|
|
|
setup_result = {}
|
|
|
|
|
setup_result['ansible_facts'] = setup_options
|
|
|
|
@ -683,4 +685,3 @@ def main():
|
|
|
|
|
# this is magic, see lib/ansible/module_common.py
|
|
|
|
|
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
|
|
|
|
main()
|
|
|
|
|
|
|
|
|
|