mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Inject vars need to pushed further up to make with_items work as desired.
This commit is contained in:
parent
4e74ab4856
commit
8bb8314d10
2 changed files with 19 additions and 15 deletions
|
@ -95,10 +95,6 @@ class Task(object):
|
||||||
# process with_items so it can be used by Runner code
|
# process with_items so it can be used by Runner code
|
||||||
if self.with_items is None:
|
if self.with_items is None:
|
||||||
self.with_items = [ ]
|
self.with_items = [ ]
|
||||||
elif isinstance(self.with_items, basestring):
|
|
||||||
self.with_items = utils.varLookup(self.with_items, self.module_vars)
|
|
||||||
if type(self.with_items) != list:
|
|
||||||
raise errors.AnsibleError("with_items must be a list, got: %s" % self.with_items)
|
|
||||||
self.module_vars['items'] = self.with_items
|
self.module_vars['items'] = self.with_items
|
||||||
|
|
||||||
# tags allow certain parts of a playbook to be run without running the whole playbook
|
# tags allow certain parts of a playbook to be run without running the whole playbook
|
||||||
|
|
|
@ -548,9 +548,24 @@ class Runner(object):
|
||||||
def _executor_internal(self, host):
|
def _executor_internal(self, host):
|
||||||
''' executes any module one or more times '''
|
''' executes any module one or more times '''
|
||||||
|
|
||||||
|
host_variables = self.inventory.get_variables(host)
|
||||||
|
port = host_variables.get('ansible_ssh_port', self.remote_port)
|
||||||
|
inject = self.setup_cache[host].copy()
|
||||||
|
inject.update(host_variables)
|
||||||
|
inject.update(self.module_vars)
|
||||||
|
|
||||||
items = self.module_vars.get('items', [])
|
items = self.module_vars.get('items', [])
|
||||||
|
if isinstance(items, basestring) and items.startswith("$"):
|
||||||
|
items = items.replace("$","")
|
||||||
|
if items in inject:
|
||||||
|
items = inject[items]
|
||||||
|
else:
|
||||||
|
raise errors.AnsibleError("unbound variable in with_items: %s" % items)
|
||||||
|
if type(items) != list:
|
||||||
|
raise errors.AnsibleError("with_items only takes a list: %s" % items)
|
||||||
|
|
||||||
if len(items) == 0:
|
if len(items) == 0:
|
||||||
return self._executor_internal_inner(host)
|
return self._executor_internal_inner(host, inject, port)
|
||||||
else:
|
else:
|
||||||
# executing using with_items, so make multiple calls
|
# executing using with_items, so make multiple calls
|
||||||
# TODO: refactor
|
# TODO: refactor
|
||||||
|
@ -560,8 +575,8 @@ class Runner(object):
|
||||||
all_failed = False
|
all_failed = False
|
||||||
results = []
|
results = []
|
||||||
for x in items:
|
for x in items:
|
||||||
self.module_vars['item'] = x
|
inject['item'] = x
|
||||||
result = self._executor_internal_inner(host)
|
result = self._executor_internal_inner(host, inject, port)
|
||||||
results.append(result.result)
|
results.append(result.result)
|
||||||
if result.comm_ok == False:
|
if result.comm_ok == False:
|
||||||
all_comm_ok = False
|
all_comm_ok = False
|
||||||
|
@ -582,16 +597,9 @@ class Runner(object):
|
||||||
|
|
||||||
# *****************************************************
|
# *****************************************************
|
||||||
|
|
||||||
def _executor_internal_inner(self, host):
|
def _executor_internal_inner(self, host, inject, port):
|
||||||
''' decides how to invoke a module '''
|
''' decides how to invoke a module '''
|
||||||
|
|
||||||
host_variables = self.inventory.get_variables(host)
|
|
||||||
port = host_variables.get('ansible_ssh_port', self.remote_port)
|
|
||||||
|
|
||||||
inject = self.setup_cache[host].copy()
|
|
||||||
inject.update(host_variables)
|
|
||||||
inject.update(self.module_vars)
|
|
||||||
|
|
||||||
# special non-user/non-fact variables:
|
# special non-user/non-fact variables:
|
||||||
# 'groups' variable is a list of host name in each group
|
# 'groups' variable is a list of host name in each group
|
||||||
# 'hostvars' variable contains variables for each host name
|
# 'hostvars' variable contains variables for each host name
|
||||||
|
|
Loading…
Add table
Reference in a new issue