parent
9178e176b5
commit
4f29662a9e
4 changed files with 24 additions and 25 deletions
|
@ -71,7 +71,7 @@ def preprocess_vars(a):
|
|||
if a is None:
|
||||
return None
|
||||
elif not isinstance(a, list):
|
||||
data = [ a ]
|
||||
data = [a]
|
||||
else:
|
||||
data = a
|
||||
|
||||
|
@ -81,6 +81,7 @@ def preprocess_vars(a):
|
|||
|
||||
return data
|
||||
|
||||
|
||||
def strip_internal_keys(dirty):
|
||||
'''
|
||||
All keys stating with _ansible_ are internal, so create a copy of the 'dirty' dict
|
||||
|
@ -119,15 +120,15 @@ class VariableManager:
|
|||
|
||||
def __getstate__(self):
|
||||
data = dict(
|
||||
fact_cache = self._fact_cache,
|
||||
np_fact_cache = self._nonpersistent_fact_cache,
|
||||
vars_cache = self._vars_cache,
|
||||
extra_vars = self._extra_vars,
|
||||
host_vars_files = self._host_vars_files,
|
||||
group_vars_files = self._group_vars_files,
|
||||
omit_token = self._omit_token,
|
||||
options_vars = self._options_vars,
|
||||
#inventory = self._inventory,
|
||||
fact_cache=self._fact_cache,
|
||||
np_fact_cache=self._nonpersistent_fact_cache,
|
||||
vars_cache=self._vars_cache,
|
||||
extra_vars=self._extra_vars,
|
||||
host_vars_files=self._host_vars_files,
|
||||
group_vars_files=self._group_vars_files,
|
||||
omit_token=self._omit_token,
|
||||
options_vars=self._options_vars,
|
||||
# inventory=self._inventory,
|
||||
)
|
||||
return data
|
||||
|
||||
|
@ -192,7 +193,7 @@ class VariableManager:
|
|||
if a is None:
|
||||
return None
|
||||
elif not isinstance(a, list):
|
||||
data = [ a ]
|
||||
data = [a]
|
||||
else:
|
||||
data = a
|
||||
|
||||
|
@ -307,7 +308,7 @@ class VariableManager:
|
|||
# the with_first_found mechanism.
|
||||
vars_file_list = vars_file_item
|
||||
if not isinstance(vars_file_list, list):
|
||||
vars_file_list = [ vars_file_list ]
|
||||
vars_file_list = [vars_file_list]
|
||||
|
||||
# now we iterate through the (potential) files, and break out
|
||||
# as soon as we read one from the list. If none are found, we
|
||||
|
@ -389,7 +390,7 @@ class VariableManager:
|
|||
if task and task.delegate_to is not None and include_delegate_to:
|
||||
all_vars['ansible_delegated_vars'] = self._get_delegated_vars(loader, play, task, all_vars)
|
||||
|
||||
#VARIABLE_CACHE[cache_entry] = all_vars
|
||||
# VARIABLE_CACHE[cache_entry] = all_vars
|
||||
if task or play:
|
||||
all_vars['vars'] = all_vars.copy()
|
||||
|
||||
|
@ -414,7 +415,7 @@ class VariableManager:
|
|||
if host:
|
||||
# host already provides some magic vars via host.get_vars()
|
||||
if self._inventory:
|
||||
variables['groups'] = self._inventory.get_group_dict()
|
||||
variables['groups'] = self._inventory.get_group_dict()
|
||||
|
||||
if play:
|
||||
variables['role_names'] = [r._role_name for r in play.roles]
|
||||
|
@ -439,8 +440,8 @@ class VariableManager:
|
|||
variables['ansible_play_hosts'] = [x for x in variables['ansible_play_hosts_all'] if x not in play._removed_hosts]
|
||||
variables['ansible_play_batch'] = [x.name for x in self._inventory.get_hosts() if x.name not in play._removed_hosts]
|
||||
|
||||
#DEPRECATED: play_hosts should be deprecated in favor of ansible_play_batch,
|
||||
# however this would take work in the templating engine, so for now we'll add both
|
||||
# DEPRECATED: play_hosts should be deprecated in favor of ansible_play_batch,
|
||||
# however this would take work in the templating engine, so for now we'll add both
|
||||
variables['play_hosts'] = variables['ansible_play_batch']
|
||||
|
||||
# the 'omit' value alows params to be left out if the variable they are based on is undefined
|
||||
|
@ -628,7 +629,6 @@ class VariableManager:
|
|||
|
||||
return data
|
||||
|
||||
|
||||
def add_group_vars_file(self, path, loader):
|
||||
'''
|
||||
Loads and caches a host_vars file in the _host_vars_files dict,
|
||||
|
|
|
@ -40,6 +40,7 @@ except ImportError:
|
|||
|
||||
__all__ = ['HostVars']
|
||||
|
||||
|
||||
# Note -- this is a Mapping, not a MutableMapping
|
||||
class HostVars(collections.Mapping):
|
||||
''' A special view of vars_cache that adds values from the inventory when needed. '''
|
||||
|
|
|
@ -30,6 +30,7 @@ except ImportError:
|
|||
from ansible.utils.display import Display
|
||||
display = Display()
|
||||
|
||||
|
||||
def get_reserved_names(include_private=True):
|
||||
''' this function returns the list of reserved names associated with play objects'''
|
||||
|
||||
|
@ -37,8 +38,8 @@ def get_reserved_names(include_private=True):
|
|||
private = set()
|
||||
result = set()
|
||||
|
||||
#FIXME: find a way to 'not hardcode', possibly need role deps/includes
|
||||
class_list = [ Play, Role, Block, Task ]
|
||||
# FIXME: find a way to 'not hardcode', possibly need role deps/includes
|
||||
class_list = [Play, Role, Block, Task]
|
||||
|
||||
for aclass in class_list:
|
||||
aobj = aclass()
|
||||
|
@ -55,7 +56,7 @@ def get_reserved_names(include_private=True):
|
|||
public.add('local_action')
|
||||
|
||||
# loop implies with_
|
||||
#FIXME: remove after with_ is not only deprecated but removed
|
||||
# FIXME: remove after with_ is not only deprecated but removed
|
||||
if 'loop' in private or 'loop' in public:
|
||||
public.add('with_')
|
||||
|
||||
|
@ -66,12 +67,12 @@ def get_reserved_names(include_private=True):
|
|||
|
||||
return result
|
||||
|
||||
|
||||
def warn_if_reserved(myvars):
|
||||
''' this function warns if any variable passed conflicts with internally reserved names '''
|
||||
reserved = get_reserved_names()
|
||||
for varname in myvars:
|
||||
if varname == 'vars':
|
||||
continue # we add this one internally
|
||||
continue # we add this one internally
|
||||
if varname in reserved:
|
||||
display.warning('Found variable using reserved name: %s' % varname)
|
||||
|
||||
|
|
|
@ -873,9 +873,6 @@ lib/ansible/utils/listify.py
|
|||
lib/ansible/utils/path.py
|
||||
lib/ansible/utils/ssh_functions.py
|
||||
lib/ansible/utils/vars.py
|
||||
lib/ansible/vars/__init__.py
|
||||
lib/ansible/vars/hostvars.py
|
||||
lib/ansible/vars/reserved.py
|
||||
setup.py
|
||||
test/integration/cleanup_azure.py
|
||||
test/integration/cleanup_ec2.py
|
||||
|
|
Loading…
Reference in a new issue