|
|
|
@ -524,27 +524,35 @@ class VariableManager:
|
|
|
|
|
delegated_host_name = None
|
|
|
|
|
if task.delegate_to:
|
|
|
|
|
delegated_host_name = templar.template(task.delegate_to, fail_on_undefined=False)
|
|
|
|
|
delegated_host = self._inventory.get_host(delegated_host_name)
|
|
|
|
|
if delegated_host is None:
|
|
|
|
|
for h in self._inventory.get_hosts(ignore_limits=True, ignore_restrictions=True):
|
|
|
|
|
# check if the address matches, or if both the delegated_to host
|
|
|
|
|
# and the current host are in the list of localhost aliases
|
|
|
|
|
if h.address == delegated_host_name:
|
|
|
|
|
delegated_host = h
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
delegated_host = Host(name=delegated_host_name)
|
|
|
|
|
|
|
|
|
|
delegated_vars['ansible_delegated_vars'] = {
|
|
|
|
|
delegated_host_name: self.get_vars(
|
|
|
|
|
play=task.get_play(),
|
|
|
|
|
host=delegated_host,
|
|
|
|
|
task=task,
|
|
|
|
|
include_delegate_to=False,
|
|
|
|
|
include_hostvars=True,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
delegated_vars['ansible_delegated_vars'][delegated_host_name]['inventory_hostname'] = variables.get('inventory_hostname')
|
|
|
|
|
|
|
|
|
|
# no need to do work if omitted
|
|
|
|
|
if delegated_host_name != self._omit_token:
|
|
|
|
|
|
|
|
|
|
if not delegated_host_name:
|
|
|
|
|
raise AnsibleError('Empty hostname produced from delegate_to: "%s"' % task.delegate_to)
|
|
|
|
|
|
|
|
|
|
delegated_host = self._inventory.get_host(delegated_host_name)
|
|
|
|
|
if delegated_host is None:
|
|
|
|
|
for h in self._inventory.get_hosts(ignore_limits=True, ignore_restrictions=True):
|
|
|
|
|
# check if the address matches, or if both the delegated_to host
|
|
|
|
|
# and the current host are in the list of localhost aliases
|
|
|
|
|
if h.address == delegated_host_name:
|
|
|
|
|
delegated_host = h
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
delegated_host = Host(name=delegated_host_name)
|
|
|
|
|
|
|
|
|
|
delegated_vars['ansible_delegated_vars'] = {
|
|
|
|
|
delegated_host_name: self.get_vars(
|
|
|
|
|
play=task.get_play(),
|
|
|
|
|
host=delegated_host,
|
|
|
|
|
task=task,
|
|
|
|
|
include_delegate_to=False,
|
|
|
|
|
include_hostvars=True,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
delegated_vars['ansible_delegated_vars'][delegated_host_name]['inventory_hostname'] = variables.get('inventory_hostname')
|
|
|
|
|
|
|
|
|
|
return delegated_vars, delegated_host_name
|
|
|
|
|
|
|
|
|
|
def _get_delegated_vars(self, play, task, existing_variables):
|
|
|
|
|