From 72fd971822cad6043c762a8b599763625c3000b4 Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Fri, 27 Apr 2012 16:43:55 -0400 Subject: [PATCH 1/3] fall through file source list: first_available_file support add first_available_file look up to _execute_template and _execute_copy to runner. add this data to playbook handler so it can be included into module_vars --- lib/ansible/playbook.py | 6 ++++-- lib/ansible/runner.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/ansible/playbook.py b/lib/ansible/playbook.py index a8e6f0d834c..bd5a3c33bde 100644 --- a/lib/ansible/playbook.py +++ b/lib/ansible/playbook.py @@ -390,8 +390,10 @@ class PlayBook(object): module_args = tokens[1] # include task specific vars - module_vars = task.get('vars') - + module_vars = task.get('vars', {}) + if 'first_available_file' in task: + module_vars['first_available_file'] = task.get('first_available_file') + # tasks can be direct (run on all nodes matching # the pattern) or conditional, where they ran # as the result of a change handler on a subset diff --git a/lib/ansible/runner.py b/lib/ansible/runner.py index 1cba37ce4fa..1bf098b631b 100644 --- a/lib/ansible/runner.py +++ b/lib/ansible/runner.py @@ -390,6 +390,20 @@ class Runner(object): # apply templating to source argument inject = self.setup_cache.get(conn.host,{}) + + # if we have first_available_file in our vars + # look up the files and use the first one we find as src + if 'first_available_file' in self.module_vars: + found = False + for fn in self.module_vars.get('first_available_file'): + fn = utils.template(fn, inject, self.setup_cache) + if os.path.exists(fn): + source = fn + found = True + break + if not found: + return (host, True, dict(failed=True, msg="could not find src"), '') + source = utils.template(source, inject, self.setup_cache) # transfer the file to a remote tmp location @@ -480,6 +494,20 @@ class Runner(object): # apply templating to source argument so vars can be used in the path inject = self.setup_cache.get(conn.host,{}) + + # if we have first_available_file in our vars + # look up the files and use the first one we find as src + if 'first_available_file' in self.module_vars: + found = False + for fn in self.module_vars.get('first_available_file'): + fn = utils.template(fn, inject, self.setup_cache) + if os.path.exists(fn): + source = fn + found = True + break + if not found: + return (host, True, dict(failed=True, msg="could not find src"), '') + source = utils.template(source, inject, self.setup_cache) (host, ok, data, err) = (None, None, None, None) From c701e5959248aec5ebc450fd88bde77ad3d84df8 Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Fri, 27 Apr 2012 16:45:28 -0400 Subject: [PATCH 2/3] very minor indentation issue in librar/copy --- library/copy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/copy b/library/copy index b5a52647a95..f6cf6028610 100755 --- a/library/copy +++ b/library/copy @@ -43,9 +43,9 @@ for x in items: src = params['src'] dest = params['dest'] if src: - src = os.path.expanduser(src) + src = os.path.expanduser(src) if dest: - dest = os.path.expanduser(dest) + dest = os.path.expanduser(dest) # raise an error if there is no src file if not os.path.exists(src): From a3ab793ba862676efdfa27de7262f1c99aebc009 Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Fri, 27 Apr 2012 17:38:46 -0400 Subject: [PATCH 3/3] fixes for yum module for rhel5 and issue 269 --- library/yum | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/library/yum b/library/yum index bb4f690281d..ee773ee15f2 100755 --- a/library/yum +++ b/library/yum @@ -57,13 +57,24 @@ def pkg_to_dict(po): 'epoch':po.epoch, 'release':po.release, 'version':po.version, - 'repo':po.ui_from_repo, - '_nevra':po.ui_nevra, } + if type(po) == yum.rpmsack.RPMInstalledPackage: d['yumstate'] = 'installed' + d['repo'] = 'installed' else: d['yumstate'] = 'available' + d['repo'] = po.repoid + + if hasattr(po, 'ui_from_repo'): + d['repo'] = po.ui_from_repo + + if hasattr(po, 'ui_nevra'): + d['_nevra'] = po.ui_nevra + else: + d['_nevra'] = '%s-%s-%s.%s' % (po.name, po.version, po.release, po.arch) + + return d @@ -215,6 +226,9 @@ def ensure(my, state, pkgspec): if state == 'latest': updates = my.doPackageLists(pkgnarrow='updates', patterns=[pkgspec]).updates + # sucks but this is for rhel5 - won't matter for rhel6 or fedora or whatnot + e,m,u = yum.parsePackages(updates, [pkgspec], casematch=True) + updates = e + m avail = my.doPackageLists(pkgnarrow='available', patterns=[pkgspec]).available if not updates and not avail: if not my.doPackageLists(pkgnarrow='installed', patterns=[pkgspec]).installed: