From 94eb11a6d79485ac8edab193c4ac9500b335aa5c Mon Sep 17 00:00:00 2001 From: Stephen Fromm Date: Fri, 14 Sep 2012 11:25:23 -0700 Subject: [PATCH 1/2] Add pkg_mgr fact to setup This should help facilitate playbook decision making that are not strictly distribution specific, but more package manager. --- library/setup | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/library/setup b/library/setup index 5499c2f857..39613b7e8c 100755 --- a/library/setup +++ b/library/setup @@ -54,6 +54,10 @@ class Facts(object): '/etc/vmware-release': 'VMwareESX' } SELINUX_MODE_DICT = { 1: 'enforcing', 0: 'permissive', -1: 'disabled' } + PKG_MGR_DICT = { '/usr/bin/yum' : 'yum', + '/usr/bin/apt-get' : 'apt', + '/usr/bin/zypper' : 'zypper' } + def __init__(self): self.facts = {} self.get_platform_facts() @@ -61,6 +65,7 @@ class Facts(object): self.get_cmdline() self.get_public_ssh_host_keys() self.get_selinux_facts() + self.get_pkg_mgr_facts() def populate(self): return self.facts @@ -133,6 +138,12 @@ class Facts(object): else: self.facts['ssh_host_key_rsa_public'] = rsa.split()[1] + def get_pkg_mgr_facts(self): + self.facts['pkg_mgr'] = 'unknown' + for (path, name) in Facts.PKG_MGR_DICT.items(): + if os.path.exists(path): + self.facts['pkg_mgr'] = name + def get_selinux_facts(self): if not HAVE_SELINUX: self.facts['selinux'] = False From 65fe7b7003f6de2df9b1201619d465b054a480c0 Mon Sep 17 00:00:00 2001 From: Stephen Fromm Date: Sun, 16 Sep 2012 20:51:46 -0700 Subject: [PATCH 2/2] Update package manager fact innards to a list of dicts --- library/setup | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/library/setup b/library/setup index 39613b7e8c..4820ec257e 100755 --- a/library/setup +++ b/library/setup @@ -54,9 +54,12 @@ class Facts(object): '/etc/vmware-release': 'VMwareESX' } SELINUX_MODE_DICT = { 1: 'enforcing', 0: 'permissive', -1: 'disabled' } - PKG_MGR_DICT = { '/usr/bin/yum' : 'yum', - '/usr/bin/apt-get' : 'apt', - '/usr/bin/zypper' : 'zypper' } + # A list of dicts. If there is a platform with more than one + # package manager, put the preferred one last. If there is an + # ansible module, use that as the value for the 'name' key. + PKG_MGRS = [ { 'path' : '/usr/bin/yum', 'name' : 'yum' }, + { 'path' : '/usr/bin/apt-get', 'name' : 'apt' }, + { 'path' : '/usr/bin/zypper', 'name' : 'zypper' } ] def __init__(self): self.facts = {} @@ -140,9 +143,9 @@ class Facts(object): def get_pkg_mgr_facts(self): self.facts['pkg_mgr'] = 'unknown' - for (path, name) in Facts.PKG_MGR_DICT.items(): - if os.path.exists(path): - self.facts['pkg_mgr'] = name + for pkg in Facts.PKG_MGRS: + if os.path.exists(pkg['path']): + self.facts['pkg_mgr'] = pkg['name'] def get_selinux_facts(self): if not HAVE_SELINUX: