summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2022-05-10 17:40:33 -0400
committerGitHub <noreply@github.com>2022-05-10 16:40:33 -0500
commita9f17d05320a56623e6736945fe18eb7c9c9f0c4 (patch)
tree368168b57119ff90f193aadf93b8311ab801b56a
parent4bde2d8a9788a47506004da0878775761ee3761d (diff)
downloadansible-a9f17d05320a56623e6736945fe18eb7c9c9f0c4.tar.gz
dont rely on path to set config defs for plugins (#77659) (#77695)
(cherry picked from commit a3cc6a581ef191faf1c9ec102d1c116c4c2a8778)
-rw-r--r--changelogs/fragments/config_load_by_name.yml2
-rw-r--r--lib/ansible/plugins/loader.py13
-rwxr-xr-xtest/integration/targets/plugin_loader/runme.sh3
-rw-r--r--test/integration/targets/plugin_loader/use_coll_name.yml7
4 files changed, 21 insertions, 4 deletions
diff --git a/changelogs/fragments/config_load_by_name.yml b/changelogs/fragments/config_load_by_name.yml
new file mode 100644
index 0000000000..8174bbb311
--- /dev/null
+++ b/changelogs/fragments/config_load_by_name.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - plugin loader will now load config data for plugin by name instead of by file to avoid issues with the same file being loaded under different names (fqcn + short name).
diff --git a/lib/ansible/plugins/loader.py b/lib/ansible/plugins/loader.py
index cd65581481..0fbaff31dd 100644
--- a/lib/ansible/plugins/loader.py
+++ b/lib/ansible/plugins/loader.py
@@ -395,7 +395,7 @@ class PluginLoader:
type_name = get_plugin_class(self.class_name)
# if type name != 'module_doc_fragment':
- if type_name in C.CONFIGURABLE_PLUGINS:
+ if type_name in C.CONFIGURABLE_PLUGINS and not C.config.get_configuration_definition(type_name, name):
dstring = AnsibleLoader(getattr(module, 'DOCUMENTATION', ''), file_name=path).get_single_data()
if dstring:
add_fragments(dstring, path, fragment_loader=fragment_loader, is_module=(type_name == 'module'))
@@ -825,10 +825,12 @@ class PluginLoader:
if path not in self._module_cache:
self._module_cache[path] = self._load_module_source(name, path)
- self._load_config_defs(name, self._module_cache[path], path)
found_in_cache = False
+ self._load_config_defs(name, self._module_cache[path], path)
+
obj = getattr(self._module_cache[path], self.class_name)
+
if self.base_class:
# The import path is hardcoded and should be the right place,
# so we are not expecting an ImportError.
@@ -955,15 +957,18 @@ class PluginLoader:
else:
full_name = basename
module = self._load_module_source(full_name, path)
- self._load_config_defs(basename, module, path)
except Exception as e:
display.warning("Skipping plugin (%s) as it seems to be invalid: %s" % (path, to_text(e)))
continue
self._module_cache[path] = module
found_in_cache = False
+ else:
+ module = self._module_cache[path]
+
+ self._load_config_defs(basename, module, path)
try:
- obj = getattr(self._module_cache[path], self.class_name)
+ obj = getattr(module, self.class_name)
except AttributeError as e:
display.warning("Skipping plugin (%s) as it seems to be invalid: %s" % (path, to_text(e)))
continue
diff --git a/test/integration/targets/plugin_loader/runme.sh b/test/integration/targets/plugin_loader/runme.sh
index 2a1bdedaca..1b8e1a84ab 100755
--- a/test/integration/targets/plugin_loader/runme.sh
+++ b/test/integration/targets/plugin_loader/runme.sh
@@ -22,3 +22,6 @@ do
exit 1
fi
done
+
+# test config loading
+ansible-playbook use_coll_name.yml -i ../../inventory -e 'ansible_connection=ansible.builtin.ssh' "$@"
diff --git a/test/integration/targets/plugin_loader/use_coll_name.yml b/test/integration/targets/plugin_loader/use_coll_name.yml
new file mode 100644
index 0000000000..66507ced2c
--- /dev/null
+++ b/test/integration/targets/plugin_loader/use_coll_name.yml
@@ -0,0 +1,7 @@
+- name: ensure configuration is loaded when we use FQCN and have already loaded using 'short namne' (which is case will all builtin connection plugins)
+ hosts: all
+ gather_facts: false
+ tasks:
+ - name: relies on extra var being passed in with connection and fqcn
+ ping:
+ ignore_unreachable: True