From f3d7294690893160184d48fbe2f71d9ea8890605 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 11 Oct 2012 07:56:01 -0400 Subject: [PATCH] Test for directory existance, fix exception catching granularity --- lib/ansible/playbook/task.py | 14 +++++++++----- lib/ansible/runner/__init__.py | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index 3178b23aec..aab3bb3fed 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -41,9 +41,13 @@ class Task(object): def __init__(self, play, ds, module_vars=None): ''' constructor loads from a task or handler datastructure ''' + + # code to allow for saying "modulename: args" versus "action: modulename args" + modules_list = set() for path in C.DEFAULT_MODULE_PATH.split(pathsep): - modules_list.update(os.listdir(path)) + if os.path.exists(path): + modules_list.update(os.listdir(path)) modules_list = list(modules_list) for x in ds.keys(): if x in modules_list: @@ -77,10 +81,10 @@ class Task(object): # delegate_to can use variables if not (self.delegate_to is None): - self.delegate_to = utils.template(None, self.delegate_to, self.module_vars) - # delegate_to: localhost should use local transport - if self.delegate_to in ['127.0.0.1', 'localhost']: - self.transport = 'local' + self.delegate_to = utils.template(None, self.delegate_to, self.module_vars) + # delegate_to: localhost should use local transport + if self.delegate_to in ['127.0.0.1', 'localhost']: + self.transport = 'local' # notified by is used by Playbook code to flag which hosts # need to run a notifier diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 5a0f1f32cd..2b56e9df53 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -467,7 +467,7 @@ class Runner(object): data2 = utils.last_non_blank_line(data) try: return data2.split()[0] - except: + except IndexError: sys.stderr.write("warning: md5sum command failed unusually, please report this to the list so it can be fixed\n") sys.stderr.write("command: %s\n" % md5s) sys.stderr.write("----\n")