reserved vars, avoid gather_subset (#84575)

pull/83715/head
Brian Coca 11 months ago committed by GitHub
parent 675d7201d8
commit 3398c102b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -559,8 +559,7 @@ class VariableManager:
if not isinstance(facts, Mapping): if not isinstance(facts, Mapping):
raise AnsibleAssertionError("the type of 'facts' to set for host_facts should be a Mapping but is a %s" % type(facts)) raise AnsibleAssertionError("the type of 'facts' to set for host_facts should be a Mapping but is a %s" % type(facts))
# NOTE: will ignore gather_subset until we can deprecate/remove this as a return from setup.py warn_if_reserved(facts.keys())
warn_if_reserved(facts.keys(), ignores=['gather_subset'])
try: try:
host_cache = self._fact_cache[host] host_cache = self._fact_cache[host]
except KeyError: except KeyError:
@ -584,8 +583,7 @@ class VariableManager:
if not isinstance(facts, Mapping): if not isinstance(facts, Mapping):
raise AnsibleAssertionError("the type of 'facts' to set for nonpersistent_facts should be a Mapping but is a %s" % type(facts)) raise AnsibleAssertionError("the type of 'facts' to set for nonpersistent_facts should be a Mapping but is a %s" % type(facts))
# NOTE: will ignore gather_subset until we can deprecate/remove this as a return from setup.py warn_if_reserved(facts.keys())
warn_if_reserved(facts.keys(), ignores=['gather_subset'])
try: try:
self._nonpersistent_fact_cache[host] |= facts self._nonpersistent_fact_cache[host] |= facts
except KeyError: except KeyError:

@ -60,10 +60,14 @@ def get_reserved_names(include_private: bool = True) -> set[str]:
else: else:
result = public result = public
# due to Collectors always adding, need to ignore this
# eventually should remove after we deprecate it in setup.py
result.remove('gather_subset')
return result return result
def warn_if_reserved(myvars: list[str], additional: list[str] | None = None, ignores: list[str] | None = None) -> None: def warn_if_reserved(myvars: list[str], additional: list[str] | None = None) -> None:
""" this function warns if any variable passed conflicts with internally reserved names """ """ this function warns if any variable passed conflicts with internally reserved names """
if additional is None: if additional is None:
@ -71,13 +75,9 @@ def warn_if_reserved(myvars: list[str], additional: list[str] | None = None, ign
else: else:
reserved = _RESERVED_NAMES.union(additional) reserved = _RESERVED_NAMES.union(additional)
if ignores is None:
ignores = []
varnames = set(myvars) varnames = set(myvars)
varnames.discard('vars') # we add this one internally, so safe to ignore varnames.discard('vars') # we add this one internally, so safe to ignore
for varname in varnames.intersection(reserved): for varname in varnames.intersection(reserved):
if varname not in ignores:
display.warning('Found variable using reserved name: %s' % varname) display.warning('Found variable using reserved name: %s' % varname)

Loading…
Cancel
Save