Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LSB facts, as derived from lsb_release -a #1151

Merged
merged 1 commit into from
Sep 30, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions library/setup
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Facts(object):
self.get_public_ssh_host_keys()
self.get_selinux_facts()
self.get_pkg_mgr_facts()
self.get_lsb_facts()

def populate(self):
return self.facts
Expand Down Expand Up @@ -170,6 +171,32 @@ class Facts(object):
if os.path.exists(pkg['path']):
self.facts['pkg_mgr'] = pkg['name']

def get_lsb_facts(self):
lsb_path = module.get_bin_path('lsb_release')
if lsb_path is None:
return self.facts
cmd = subprocess.Popen([lsb_path, "-a"], shell=False,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = cmd.communicate()
if cmd.returncode == 0:
self.facts['lsb'] = {}
for line in out.split('\n'):
if len(line) < 1:
continue
value = line.split(':', 1)[1].strip()
if 'LSB Version:' in line:
self.facts['lsb']['release'] = value
elif 'Distributor ID:' in line:
self.facts['lsb']['id'] = value
elif 'Description:' in line:
self.facts['lsb']['description'] = value
elif 'Release:' in line:
self.facts['lsb']['release'] = value
elif 'Codename:' in line:
self.facts['lsb']['codename'] = value
if 'lsb' in self.facts and 'release' in self.facts['lsb']:
self.facts['lsb']['major_release'] = self.facts['lsb']['release'].split('.')[0]

def get_selinux_facts(self):
if not HAVE_SELINUX:
self.facts['selinux'] = False
Expand Down