diff --git a/lib/ansible/executor/task_queue_manager.py b/lib/ansible/executor/task_queue_manager.py index 3e62cb3c99d..0f0dba04442 100644 --- a/lib/ansible/executor/task_queue_manager.py +++ b/lib/ansible/executor/task_queue_manager.py @@ -198,11 +198,13 @@ class TaskQueueManager: 'hostvars', callable=lambda: hostvars, # FIXME: this is the list of exposed methods to the DictProxy object, plus our - # one special one (set_variable_manager). There's probably a better way + # special ones (set_variable_manager/set_inventory). There's probably a better way # to do this with a proper BaseProxy/DictProxy derivative - exposed=('set_variable_manager', '__contains__', '__delitem__', '__getitem__', - '__len__', '__setitem__', 'clear', 'copy', 'get', 'has_key', 'items', - 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values'), + exposed=( + 'set_variable_manager', 'set_inventory', '__contains__', '__delitem__', + '__getitem__', '__len__', '__setitem__', 'clear', 'copy', 'get', 'has_key', + 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values' + ), ) self._hostvars_manager = HostVarsManager() self._hostvars_manager.start() diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index 38c65552d3a..405a8c7b3a7 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -246,11 +246,13 @@ class StrategyBase: new_host_info = result_item.get('add_host', dict()) self._add_host(new_host_info, iterator) + self._tqm._hostvars_manager.hostvars().set_inventory(self._inventory) elif result[0] == 'add_group': host = result[1] result_item = result[2] self._add_group(host, result_item) + self._tqm._hostvars_manager.hostvars().set_inventory(self._inventory) elif result[0] == 'notify_handler': task_result = result[1] diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index c895b59f5fb..ea9c38e0b9f 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -119,7 +119,7 @@ class VariableManager: self._host_vars_files = data.get('host_vars_files', defaultdict(dict)) self._group_vars_files = data.get('group_vars_files', defaultdict(dict)) self._omit_token = data.get('omit_token', '__omit_place_holder__%s' % sha1(os.urandom(64)).hexdigest()) - self._inventory = None + self._inventory = data.get('inventory', None) def _get_cache_entry(self, play=None, host=None, task=None): play_id = "NONE" diff --git a/lib/ansible/vars/hostvars.py b/lib/ansible/vars/hostvars.py index 246b2c78123..742d3266e75 100644 --- a/lib/ansible/vars/hostvars.py +++ b/lib/ansible/vars/hostvars.py @@ -57,13 +57,16 @@ class HostVars(collections.Mapping): def set_variable_manager(self, variable_manager): self._variable_manager = variable_manager + def set_inventory(self, inventory): + self._inventory = inventory + def _find_host(self, host_name): return self._inventory.get_host(host_name) def __getitem__(self, host_name): host = self._find_host(host_name) if host is None: - return j2undefined + raise j2undefined data = self._variable_manager.get_vars(loader=self._loader, host=host, play=self._play, include_hostvars=False)