mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
parent
cca084c89d
commit
0f2b1244d2
4 changed files with 15 additions and 15 deletions
|
@ -143,7 +143,7 @@ class ResultProcess(multiprocessing.Process):
|
||||||
if result._task.loop:
|
if result._task.loop:
|
||||||
# this task had a loop, and has more than one result, so
|
# this task had a loop, and has more than one result, so
|
||||||
# loop over all of them instead of a single result
|
# loop over all of them instead of a single result
|
||||||
result_items = result._result['results']
|
result_items = result._result.get('results', [])
|
||||||
else:
|
else:
|
||||||
result_items = [ result._result ]
|
result_items = [ result._result ]
|
||||||
|
|
||||||
|
|
|
@ -141,7 +141,6 @@ class StrategyBase:
|
||||||
|
|
||||||
display.debug("entering _queue_task() for %s/%s" % (host, task))
|
display.debug("entering _queue_task() for %s/%s" % (host, task))
|
||||||
|
|
||||||
task_vars['hostvars'] = self._tqm.hostvars
|
|
||||||
# and then queue the new task
|
# and then queue the new task
|
||||||
display.debug("%s - putting task (%s) in queue" % (host, task))
|
display.debug("%s - putting task (%s) in queue" % (host, task))
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -40,7 +40,6 @@ from ansible.inventory.host import Host
|
||||||
from ansible.plugins import lookup_loader
|
from ansible.plugins import lookup_loader
|
||||||
from ansible.plugins.cache import FactCache
|
from ansible.plugins.cache import FactCache
|
||||||
from ansible.template import Templar
|
from ansible.template import Templar
|
||||||
from ansible.utils.debug import debug
|
|
||||||
from ansible.utils.listify import listify_lookup_plugin_terms
|
from ansible.utils.listify import listify_lookup_plugin_terms
|
||||||
from ansible.utils.vars import combine_vars
|
from ansible.utils.vars import combine_vars
|
||||||
from ansible.vars.unsafe_proxy import wrap_var
|
from ansible.vars.unsafe_proxy import wrap_var
|
||||||
|
@ -98,6 +97,7 @@ class VariableManager:
|
||||||
self._host_vars_files = defaultdict(dict)
|
self._host_vars_files = defaultdict(dict)
|
||||||
self._group_vars_files = defaultdict(dict)
|
self._group_vars_files = defaultdict(dict)
|
||||||
self._inventory = None
|
self._inventory = None
|
||||||
|
self._hostvars = None
|
||||||
self._omit_token = '__omit_place_holder__%s' % sha1(os.urandom(64)).hexdigest()
|
self._omit_token = '__omit_place_holder__%s' % sha1(os.urandom(64)).hexdigest()
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
|
@ -172,8 +172,6 @@ class VariableManager:
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
# FIXME: include_hostvars is no longer used, and should be removed, but
|
|
||||||
# all other areas of code calling get_vars need to be fixed too
|
|
||||||
def get_vars(self, loader, play=None, host=None, task=None, include_hostvars=True, include_delegate_to=True, use_cache=True):
|
def get_vars(self, loader, play=None, host=None, task=None, include_hostvars=True, include_delegate_to=True, use_cache=True):
|
||||||
'''
|
'''
|
||||||
Returns the variables, with optional "context" given via the parameters
|
Returns the variables, with optional "context" given via the parameters
|
||||||
|
@ -194,10 +192,10 @@ class VariableManager:
|
||||||
- extra vars
|
- extra vars
|
||||||
'''
|
'''
|
||||||
|
|
||||||
debug("in VariableManager get_vars()")
|
display.debug("in VariableManager get_vars()")
|
||||||
cache_entry = self._get_cache_entry(play=play, host=host, task=task)
|
cache_entry = self._get_cache_entry(play=play, host=host, task=task)
|
||||||
if cache_entry in VARIABLE_CACHE and use_cache:
|
if cache_entry in VARIABLE_CACHE and use_cache:
|
||||||
debug("vars are cached, returning them now")
|
display.debug("vars are cached, returning them now")
|
||||||
return VARIABLE_CACHE[cache_entry]
|
return VARIABLE_CACHE[cache_entry]
|
||||||
|
|
||||||
all_vars = dict()
|
all_vars = dict()
|
||||||
|
@ -346,7 +344,7 @@ class VariableManager:
|
||||||
if task or play:
|
if task or play:
|
||||||
all_vars['vars'] = all_vars.copy()
|
all_vars['vars'] = all_vars.copy()
|
||||||
|
|
||||||
debug("done with get_vars()")
|
display.debug("done with get_vars()")
|
||||||
return all_vars
|
return all_vars
|
||||||
|
|
||||||
def invalidate_hostvars_cache(self, play):
|
def invalidate_hostvars_cache(self, play):
|
||||||
|
@ -395,6 +393,9 @@ class VariableManager:
|
||||||
variables['omit'] = self._omit_token
|
variables['omit'] = self._omit_token
|
||||||
variables['ansible_version'] = CLI.version_info(gitinfo=False)
|
variables['ansible_version'] = CLI.version_info(gitinfo=False)
|
||||||
|
|
||||||
|
if self._hostvars is not None and include_hostvars:
|
||||||
|
variables['hostvars'] = self._hostvars
|
||||||
|
|
||||||
return variables
|
return variables
|
||||||
|
|
||||||
def _get_delegated_vars(self, loader, play, task, existing_variables):
|
def _get_delegated_vars(self, loader, play, task, existing_variables):
|
||||||
|
@ -407,16 +408,14 @@ class VariableManager:
|
||||||
items = []
|
items = []
|
||||||
if task.loop is not None:
|
if task.loop is not None:
|
||||||
if task.loop in lookup_loader:
|
if task.loop in lookup_loader:
|
||||||
#TODO: remove convert_bare true and deprecate this in with_
|
|
||||||
try:
|
try:
|
||||||
|
#TODO: remove convert_bare true and deprecate this in with_
|
||||||
loop_terms = listify_lookup_plugin_terms(terms=task.loop_args, templar=templar, loader=loader, fail_on_undefined=True, convert_bare=True)
|
loop_terms = listify_lookup_plugin_terms(terms=task.loop_args, templar=templar, loader=loader, fail_on_undefined=True, convert_bare=True)
|
||||||
|
items = lookup_loader.get(task.loop, loader=loader, templar=templar).run(terms=loop_terms, variables=vars_copy)
|
||||||
except AnsibleUndefinedVariable as e:
|
except AnsibleUndefinedVariable as e:
|
||||||
if 'has no attribute' in str(e):
|
# This task will be skipped later due to this, so we just setup
|
||||||
loop_terms = []
|
# a dummy array for the later code so it doesn't fail
|
||||||
display.deprecated("Skipping task due to undefined attribute, in the future this will be a fatal error.")
|
items = [None]
|
||||||
else:
|
|
||||||
raise
|
|
||||||
items = lookup_loader.get(task.loop, loader=loader, templar=templar).run(terms=loop_terms, variables=vars_copy)
|
|
||||||
else:
|
else:
|
||||||
raise AnsibleError("Unexpected failure in finding the lookup named '%s' in the available lookup plugins" % task.loop)
|
raise AnsibleError("Unexpected failure in finding the lookup named '%s' in the available lookup plugins" % task.loop)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -51,10 +51,12 @@ class HostVars(collections.Mapping):
|
||||||
self._inventory = inventory
|
self._inventory = inventory
|
||||||
self._loader = loader
|
self._loader = loader
|
||||||
self._variable_manager = variable_manager
|
self._variable_manager = variable_manager
|
||||||
|
variable_manager._hostvars = self
|
||||||
self._cached_result = dict()
|
self._cached_result = dict()
|
||||||
|
|
||||||
def set_variable_manager(self, variable_manager):
|
def set_variable_manager(self, variable_manager):
|
||||||
self._variable_manager = variable_manager
|
self._variable_manager = variable_manager
|
||||||
|
variable_manager._hostvars = self
|
||||||
|
|
||||||
def set_inventory(self, inventory):
|
def set_inventory(self, inventory):
|
||||||
self._inventory = inventory
|
self._inventory = inventory
|
||||||
|
|
Loading…
Add table
Reference in a new issue