Evaluate only_if early to do as little work as possible

This commit is contained in:
Daniel Hokka Zakrisson 2012-06-11 15:06:23 +02:00
parent c1b02d7805
commit 1244054dfb

View file

@ -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