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):
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(), ignores=['gather_subset'])
warn_if_reserved(facts.keys())
try:
host_cache = self._fact_cache[host]
except KeyError:
@ -584,8 +583,7 @@ class VariableManager:
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))
# NOTE: will ignore gather_subset until we can deprecate/remove this as a return from setup.py
warn_if_reserved(facts.keys(), ignores=['gather_subset'])
warn_if_reserved(facts.keys())
try:
self._nonpersistent_fact_cache[host] |= facts
except KeyError:

@ -60,10 +60,14 @@ def get_reserved_names(include_private: bool = True) -> set[str]:
else:
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
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 """
if additional is None:
@ -71,13 +75,9 @@ def warn_if_reserved(myvars: list[str], additional: list[str] | None = None, ign
else:
reserved = _RESERVED_NAMES.union(additional)
if ignores is None:
ignores = []
varnames = set(myvars)
varnames.discard('vars') # we add this one internally, so safe to ignore
for varname in varnames.intersection(reserved):
if varname not in ignores:
display.warning('Found variable using reserved name: %s' % varname)

Loading…
Cancel
Save