From 2f8f7fba4c6b17c25bf20913bfd332ea06b8e8ae Mon Sep 17 00:00:00 2001 From: devon-mar Date: Mon, 20 Feb 2023 11:45:03 -0800 Subject: [PATCH] Update lookup to use positional only arg for name to avoid conflicts (#79839) --- changelogs/fragments/79839-lookup-option-name.yml | 3 +++ lib/ansible/template/__init__.py | 4 ++-- test/integration/targets/lookup-option-name/aliases | 2 ++ test/integration/targets/lookup-option-name/tasks/main.yml | 6 ++++++ 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/79839-lookup-option-name.yml create mode 100644 test/integration/targets/lookup-option-name/aliases create mode 100644 test/integration/targets/lookup-option-name/tasks/main.yml diff --git a/changelogs/fragments/79839-lookup-option-name.yml b/changelogs/fragments/79839-lookup-option-name.yml new file mode 100644 index 00000000000..9804c654887 --- /dev/null +++ b/changelogs/fragments/79839-lookup-option-name.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - templates - Fixed `TypeError` when a lookup plugin has an option called `name`. diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py index f6513042022..f8246a274d6 100644 --- a/lib/ansible/template/__init__.py +++ b/lib/ansible/template/__init__.py @@ -810,12 +810,12 @@ class Templar: return now - def _query_lookup(self, name, *args, **kwargs): + def _query_lookup(self, name, /, *args, **kwargs): ''' wrapper for lookup, force wantlist true''' kwargs['wantlist'] = True return self._lookup(name, *args, **kwargs) - def _lookup(self, name, *args, **kwargs): + def _lookup(self, name, /, *args, **kwargs): instance = lookup_loader.get(name, loader=self._loader, templar=self) if instance is None: diff --git a/test/integration/targets/lookup-option-name/aliases b/test/integration/targets/lookup-option-name/aliases new file mode 100644 index 00000000000..498fedd558e --- /dev/null +++ b/test/integration/targets/lookup-option-name/aliases @@ -0,0 +1,2 @@ +shippable/posix/group4 +context/controller diff --git a/test/integration/targets/lookup-option-name/tasks/main.yml b/test/integration/targets/lookup-option-name/tasks/main.yml new file mode 100644 index 00000000000..4f248c84b34 --- /dev/null +++ b/test/integration/targets/lookup-option-name/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- debug: + msg: "{{ lookup('vars', name='test') }}" + +- debug: + msg: "{{ query('vars', name='test') }}"