From 3a244c5533e585760c034781a0394cc529e384dd Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 13 Apr 2021 00:00:43 -0400 Subject: [PATCH] config lookup can now handle collection plugins (#74250) use load_name of valid plugin to find config, will handle the renamed loaded plugin that collections do: `ansible_collection...plugins..` --- changelogs/fragments/config_lookup_fix.yml | 2 ++ lib/ansible/plugins/lookup/config.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/config_lookup_fix.yml diff --git a/changelogs/fragments/config_lookup_fix.yml b/changelogs/fragments/config_lookup_fix.yml new file mode 100644 index 00000000000..1cbeaf17049 --- /dev/null +++ b/changelogs/fragments/config_lookup_fix.yml @@ -0,0 +1,2 @@ +bugfixes: + - config lookup, can also handle collection plugins now diff --git a/lib/ansible/plugins/lookup/config.py b/lib/ansible/plugins/lookup/config.py index 67ed5f1810a..2b66881358a 100644 --- a/lib/ansible/plugins/lookup/config.py +++ b/lib/ansible/plugins/lookup/config.py @@ -89,8 +89,12 @@ def _get_plugin_config(pname, ptype, config, variables): try: # plugin creates settings on load, this is cached so not too expensive to redo loader = getattr(plugin_loader, '%s_loader' % ptype) - dump = loader.get(pname, class_only=True) - result = C.config.get_config_value(config, plugin_type=ptype, plugin_name=pname, variables=variables) + p = loader.get(pname, class_only=True) + if p is None: + raise AnsibleLookupError('Unable to load %s plugin "%s"' % (ptype, pname)) + result = C.config.get_config_value(config, plugin_type=ptype, plugin_name=p._load_name, variables=variables) + except AnsibleLookupError: + raise except AnsibleError as e: msg = to_native(e) if 'was not defined' in msg: