mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fix delegate_facts (#17736)
code was misplaced when we changed result processing also cleaned up import and clarified item/label fixes #17582
This commit is contained in:
parent
a4fed650e2
commit
f63b8878fd
1 changed files with 19 additions and 16 deletions
|
@ -19,7 +19,6 @@
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
import os
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -35,7 +34,6 @@ from ansible.executor.process.worker import WorkerProcess
|
||||||
from ansible.executor.task_result import TaskResult
|
from ansible.executor.task_result import TaskResult
|
||||||
from ansible.inventory.host import Host
|
from ansible.inventory.host import Host
|
||||||
from ansible.inventory.group import Group
|
from ansible.inventory.group import Group
|
||||||
from ansible.module_utils.facts import Facts
|
|
||||||
from ansible.playbook.helpers import load_list_of_blocks
|
from ansible.playbook.helpers import load_list_of_blocks
|
||||||
from ansible.playbook.included_file import IncludedFile
|
from ansible.playbook.included_file import IncludedFile
|
||||||
from ansible.playbook.task_include import TaskInclude
|
from ansible.playbook.task_include import TaskInclude
|
||||||
|
@ -438,18 +436,18 @@ class StrategyBase:
|
||||||
self._add_group(original_host, result_item)
|
self._add_group(original_host, result_item)
|
||||||
|
|
||||||
elif 'ansible_facts' in result_item:
|
elif 'ansible_facts' in result_item:
|
||||||
loop_var = 'item'
|
|
||||||
|
# set correct loop var
|
||||||
if original_task.loop_control:
|
if original_task.loop_control:
|
||||||
loop_var = original_task.loop_control.loop_var or 'item'
|
loop_var = original_task.loop_control.loop_var or 'item'
|
||||||
|
else:
|
||||||
|
loop_var = 'item'
|
||||||
|
|
||||||
item = result_item.get(loop_var, None)
|
item = result_item.get(loop_var, None)
|
||||||
|
|
||||||
if original_task.action == 'include_vars':
|
# if delegated fact and we are delegating facts, we need to change target host for them
|
||||||
for (var_name, var_value) in iteritems(result_item['ansible_facts']):
|
|
||||||
# find the host we're actually refering too here, which may
|
|
||||||
# be a host that is not really in inventory at all
|
|
||||||
if original_task.delegate_to is not None and original_task.delegate_facts:
|
if original_task.delegate_to is not None and original_task.delegate_facts:
|
||||||
task_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, host=host, task=original_task)
|
task_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, host=original_host, task=original_task)
|
||||||
self.add_tqm_variables(task_vars, play=iterator._play)
|
self.add_tqm_variables(task_vars, play=iterator._play)
|
||||||
if item is not None:
|
if item is not None:
|
||||||
task_vars[loop_var] = item
|
task_vars[loop_var] = item
|
||||||
|
@ -461,6 +459,11 @@ class StrategyBase:
|
||||||
else:
|
else:
|
||||||
actual_host = original_host
|
actual_host = original_host
|
||||||
|
|
||||||
|
if original_task.action == 'include_vars':
|
||||||
|
for (var_name, var_value) in iteritems(result_item['ansible_facts']):
|
||||||
|
# find the host we're actually refering too here, which may
|
||||||
|
# be a host that is not really in inventory at all
|
||||||
|
|
||||||
if original_task.run_once:
|
if original_task.run_once:
|
||||||
host_list = [host for host in self._inventory.get_hosts(iterator._play.hosts) if host.name not in self._tqm._unreachable_hosts]
|
host_list = [host for host in self._inventory.get_hosts(iterator._play.hosts) if host.name not in self._tqm._unreachable_hosts]
|
||||||
else:
|
else:
|
||||||
|
@ -472,7 +475,7 @@ class StrategyBase:
|
||||||
if original_task.run_once:
|
if original_task.run_once:
|
||||||
host_list = [host for host in self._inventory.get_hosts(iterator._play.hosts) if host.name not in self._tqm._unreachable_hosts]
|
host_list = [host for host in self._inventory.get_hosts(iterator._play.hosts) if host.name not in self._tqm._unreachable_hosts]
|
||||||
else:
|
else:
|
||||||
host_list = [original_host]
|
host_list = [actual_host]
|
||||||
|
|
||||||
for target_host in host_list:
|
for target_host in host_list:
|
||||||
if original_task.action == 'set_fact':
|
if original_task.action == 'set_fact':
|
||||||
|
|
Loading…
Add table
Reference in a new issue