From ed07940386bf0d6c207f0991102ddbb6bcda41b3 Mon Sep 17 00:00:00 2001 From: Stephen Fromm Date: Sat, 29 Sep 2012 23:58:04 -0700 Subject: [PATCH] Add LSB facts, as derived from lsb_release -a This gathers LSB facts via lsb_release. This complements the platform facts collected via the platform module. This reoprts release, id, description, release, and codename. It also adds 'major_release', which is the major version number of a distribution. --- library/setup | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/library/setup b/library/setup index 8749448397..46e73face2 100755 --- a/library/setup +++ b/library/setup @@ -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 @@ -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