Evaluate only_if early to do as little work as possible
This commit is contained in:
parent
c1b02d7805
commit
1244054dfb
1 changed files with 11 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue