diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2025-01-16 22:33:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-16 22:33:43 +0100 |
commit | 675d7201d827a68912f4c7b432486c6b28a4bad4 (patch) | |
tree | bc36236db820b54813e538721d4c8a1456141471 | |
parent | filters/flatten: fix input documentation (#84477) (diff) | |
download | ansible-devel.tar.xz ansible-devel.zip |
also fix gather_subset warning and add some comments/notes
---------
Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
-rw-r--r-- | lib/ansible/module_utils/facts/ansible_collector.py | 6 | ||||
-rw-r--r-- | lib/ansible/vars/manager.py | 6 | ||||
-rw-r--r-- | lib/ansible/vars/reserved.py | 8 | ||||
-rw-r--r-- | test/integration/targets/var_reserved/tasks/task_vars_used.yml | 2 |
4 files changed, 17 insertions, 5 deletions
diff --git a/lib/ansible/module_utils/facts/ansible_collector.py b/lib/ansible/module_utils/facts/ansible_collector.py index 9fe1c8a84e..5b66f0a0eb 100644 --- a/lib/ansible/module_utils/facts/ansible_collector.py +++ b/lib/ansible/module_utils/facts/ansible_collector.py @@ -113,7 +113,13 @@ class CollectorMetaDataCollector(collector.BaseFactCollector): self.module_setup = module_setup def collect(self, module=None, collected_facts=None): + # NOTE: deprecate/remove once DT lands + # we can return this data, but should not be top level key meta_facts = {'gather_subset': self.gather_subset} + + # NOTE: this is just a boolean indicator that 'facts were gathered' + # and should be moved to the 'gather_facts' action plugin + # probably revised to handle modules/subsets combos if self.module_setup: meta_facts['module_setup'] = self.module_setup return meta_facts diff --git a/lib/ansible/vars/manager.py b/lib/ansible/vars/manager.py index d25d63730b..aa84681a4d 100644 --- a/lib/ansible/vars/manager.py +++ b/lib/ansible/vars/manager.py @@ -559,7 +559,8 @@ 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)) - warn_if_reserved(facts.keys()) + # 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']) try: host_cache = self._fact_cache[host] except KeyError: @@ -583,7 +584,8 @@ 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)) - warn_if_reserved(facts.keys()) + # 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']) try: self._nonpersistent_fact_cache[host] |= facts except KeyError: diff --git a/lib/ansible/vars/reserved.py b/lib/ansible/vars/reserved.py index 51e8dc4114..4799b307a3 100644 --- a/lib/ansible/vars/reserved.py +++ b/lib/ansible/vars/reserved.py @@ -63,7 +63,7 @@ def get_reserved_names(include_private: bool = True) -> set[str]: return result -def warn_if_reserved(myvars: list[str], additional: list[str] | None = None) -> None: +def warn_if_reserved(myvars: list[str], additional: list[str] | None = None, ignores: list[str] | None = None) -> None: """ this function warns if any variable passed conflicts with internally reserved names """ if additional is None: @@ -71,10 +71,14 @@ def warn_if_reserved(myvars: list[str], additional: list[str] | None = None) -> 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): - display.warning('Found variable using reserved name: %s' % varname) + if varname not in ignores: + display.warning('Found variable using reserved name: %s' % varname) def is_reserved_name(name: str) -> bool: diff --git a/test/integration/targets/var_reserved/tasks/task_vars_used.yml b/test/integration/targets/var_reserved/tasks/task_vars_used.yml index 5d42bf58ab..bc439f64c4 100644 --- a/test/integration/targets/var_reserved/tasks/task_vars_used.yml +++ b/test/integration/targets/var_reserved/tasks/task_vars_used.yml @@ -3,6 +3,6 @@ tasks: - name: task fails due to overriding q, but we should also see warning debug: - msg: "{{q('pipe', 'pwd'}}" + msg: "{{q('pipe', 'pwd')}}" vars: q: jinja2 uses me internally |