Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate only_if early #461

Merged
merged 2 commits into from
Jun 14, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions lib/ansible/runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,6 @@ def _execute_module(self, conn, tmp, remote_module_path, args,
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 = {}
Expand Down Expand Up @@ -635,15 +630,24 @@ def _executor_internal(self, host):
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)
except errors.AnsibleConnectionFailed, e:
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
Expand All @@ -667,7 +671,7 @@ def _executor_internal(self, host):

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:
Expand Down