mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Evaluate only_if early to do as little work as possible
This commit is contained in:
parent
e8e6c98016
commit
eba81ee36f
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