From 1244054dfb1b5bc4735f293a98322480dfbb64f7 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Mon, 11 Jun 2012 15:06:23 +0200 Subject: [PATCH 1/2] Evaluate only_if early to do as little work as possible --- lib/ansible/runner/__init__.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index b46ba05db71..6519adb3ee8 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -288,11 +288,6 @@ class Runner(object): inject.update(host_variables) inject.update(self.module_vars) - conditional = utils.double_template(self.conditional, inject, self.setup_cache) - if not eval(conditional): - result = utils.smjson(dict(skipped=True)) - return ReturnData(host=conn.host, result=result) - if self.module_name == 'setup': if not args: args = {} @@ -635,6 +630,16 @@ class Runner(object): host_variables = self.inventory.get_variables(host) port = host_variables.get('ansible_ssh_port', self.remote_port) + inject = self.setup_cache.get(host,{}).copy() + inject.update(host_variables) + inject.update(self.module_vars) + + conditional = utils.double_template(self.conditional, inject, self.setup_cache) + if not eval(conditional): + result = utils.smjson(dict(skipped=True)) + self.callbacks.on_skipped(host) + return ReturnData(host=host, result=result) + conn = None try: conn = self.connector.connect(host, port) @@ -642,8 +647,7 @@ class Runner(object): result = dict(failed=True, msg="FAILED: %s" % str(e)) return ReturnData(host=host, comm_ok=False, result=result) - cache = self.setup_cache.get(host, {}) - module_name = utils.template(self.module_name, cache, self.setup_cache) + module_name = utils.template(self.module_name, inject, self.setup_cache) tmp = self._get_tmp_path(conn) result = None From 2371bf9aaf7f02d6541f4dd84be2e5c6c3d1cf8f Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Mon, 11 Jun 2012 15:07:37 +0200 Subject: [PATCH 2/2] Fix on_unreachable invocation with non-existing variable --- lib/ansible/runner/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 6519adb3ee8..25a83d64a92 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -671,7 +671,7 @@ class Runner(object): if not result.comm_ok: # connection or parsing errors... - self.callbacks.on_unreachable(host, data) + self.callbacks.on_unreachable(host, result.result) else: data = result.result if 'skipped' in data: