diff --git a/changelogs/fragments/hostvars-to-varsmanager.yml b/changelogs/fragments/hostvars-to-varsmanager.yml new file mode 100644 index 00000000000..9d5d2493b01 --- /dev/null +++ b/changelogs/fragments/hostvars-to-varsmanager.yml @@ -0,0 +1,3 @@ +minor_changes: + - hostvars - ``HostVars`` is now instantiated in ``VariableManager`` instead of in ``TaskQueueManager`` + - hostvars - removed unused ``HostVars#set_variable_manager`` diff --git a/lib/ansible/executor/task_queue_manager.py b/lib/ansible/executor/task_queue_manager.py index 02a75cd07f5..42b506964b5 100644 --- a/lib/ansible/executor/task_queue_manager.py +++ b/lib/ansible/executor/task_queue_manager.py @@ -38,7 +38,6 @@ from ansible.playbook.task import Task from ansible.plugins.loader import callback_loader, strategy_loader, module_loader from ansible.plugins.callback import CallbackBase from ansible.template import Templar -from ansible.vars.hostvars import HostVars from ansible.vars.reserved import warn_if_reserved from ansible.utils.display import Display from ansible.utils.lock import lock_decorator @@ -237,12 +236,6 @@ class TaskQueueManager: new_play.post_validate(templar) new_play.handlers = new_play.compile_roles_handlers() + new_play.handlers - self.hostvars = HostVars( - inventory=self._inventory, - variable_manager=self._variable_manager, - loader=self._loader, - ) - play_context = PlayContext(new_play, self.passwords, self._connection_lockfile.fileno()) if (self._stdout_callback and hasattr(self._stdout_callback, 'set_play_context')): diff --git a/lib/ansible/vars/hostvars.py b/lib/ansible/vars/hostvars.py index b47ec1975ce..c9ed76956ba 100644 --- a/lib/ansible/vars/hostvars.py +++ b/lib/ansible/vars/hostvars.py @@ -50,13 +50,8 @@ class HostVars(Mapping): def __init__(self, inventory, variable_manager, loader): self._inventory = inventory - self._loader = loader - self._variable_manager = variable_manager - variable_manager._hostvars = self - - def set_variable_manager(self, variable_manager): self._variable_manager = variable_manager - variable_manager._hostvars = self + self._loader = loader def set_inventory(self, inventory): self._inventory = inventory diff --git a/lib/ansible/vars/manager.py b/lib/ansible/vars/manager.py index a4942bac5d3..2f8878a9a68 100644 --- a/lib/ansible/vars/manager.py +++ b/lib/ansible/vars/manager.py @@ -46,6 +46,7 @@ from ansible.utils.listify import listify_lookup_plugin_terms from ansible.utils.vars import combine_vars, load_extra_vars, load_options_vars from ansible.utils.unsafe_proxy import wrap_var from ansible.vars.clean import namespace_facts, clean_facts +from ansible.vars.hostvars import HostVars from ansible.vars.plugins import get_vars_from_inventory_sources, get_vars_from_path display = Display() @@ -85,8 +86,11 @@ class VariableManager: self._group_vars_files = defaultdict(dict) self._inventory = inventory self._loader = loader - self._hostvars = None self._omit_token = '__omit_place_holder__%s' % sha1(os.urandom(64)).hexdigest() + self._hostvars = HostVars( + inventory=self._inventory, + variable_manager=self, + loader=self._loader) self._options_vars = load_options_vars(version_info)