summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2022-03-15 13:09:40 -0500
committerGitHub <noreply@github.com>2022-03-15 11:09:40 -0700
commitef46bc46f459cf702f098d64b37c74cf0557ebd7 (patch)
tree8088706851ed034c19d4a417d6c2c11ade73adc9
parent7a8c6d74188b56228db77fed727cf1fdf3cc141d (diff)
downloadansible-ef46bc46f459cf702f098d64b37c74cf0557ebd7.tar.gz
[stable-2.11] Use full python package for ansiballz cache filenames (#77090) (#77126)
* [stable-2.11] Use full python package for ansiballz cache filenames (#77090) * Use full python package for ansiballz cache filenames * Be a little more explicit about test goals (cherry picked from commit 8cbe143) Co-authored-by: Matt Martz <matt@sivel.net> * linting
-rw-r--r--changelogs/fragments/fqn-module-cache.yml5
-rw-r--r--lib/ansible/executor/module_common.py2
-rw-r--r--test/integration/targets/collections/ansiballz_dupe/collections/ansible_collections/duplicate/name/plugins/modules/ping.py5
-rw-r--r--test/integration/targets/collections/ansiballz_dupe/test_ansiballz_cache_dupe_shortname.yml15
-rwxr-xr-xtest/integration/targets/collections/runme.sh3
5 files changed, 29 insertions, 1 deletions
diff --git a/changelogs/fragments/fqn-module-cache.yml b/changelogs/fragments/fqn-module-cache.yml
new file mode 100644
index 0000000000..9dffb3d231
--- /dev/null
+++ b/changelogs/fragments/fqn-module-cache.yml
@@ -0,0 +1,5 @@
+bugfixes:
+- AnsiballZ - Ensure we use the full python package in the module cache filename
+ to avoid a case where ``collections:`` is used to execute a module via short name,
+ where the short name duplicates another module from ``ansible.builtin`` or another
+ collection that was executed previously.
diff --git a/lib/ansible/executor/module_common.py b/lib/ansible/executor/module_common.py
index 8c48f72bc4..73a7a57e24 100644
--- a/lib/ansible/executor/module_common.py
+++ b/lib/ansible/executor/module_common.py
@@ -1156,7 +1156,7 @@ def _find_module_utils(module_name, b_module_data, module_path, module_args, tas
compression_method = zipfile.ZIP_STORED
lookup_path = os.path.join(C.DEFAULT_LOCAL_TMP, 'ansiballz_cache')
- cached_module_filename = os.path.join(lookup_path, "%s-%s" % (module_name, module_compression))
+ cached_module_filename = os.path.join(lookup_path, "%s-%s" % (remote_module_fqn, module_compression))
zipdata = None
# Optimization -- don't lock if the module has already been cached
diff --git a/test/integration/targets/collections/ansiballz_dupe/collections/ansible_collections/duplicate/name/plugins/modules/ping.py b/test/integration/targets/collections/ansiballz_dupe/collections/ansible_collections/duplicate/name/plugins/modules/ping.py
new file mode 100644
index 0000000000..c1a22c5a0e
--- /dev/null
+++ b/test/integration/targets/collections/ansiballz_dupe/collections/ansible_collections/duplicate/name/plugins/modules/ping.py
@@ -0,0 +1,5 @@
+#!/usr/bin/python
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+from ansible.module_utils.basic import AnsibleModule
+AnsibleModule({}).exit_json(ping='duplicate.name.pong')
diff --git a/test/integration/targets/collections/ansiballz_dupe/test_ansiballz_cache_dupe_shortname.yml b/test/integration/targets/collections/ansiballz_dupe/test_ansiballz_cache_dupe_shortname.yml
new file mode 100644
index 0000000000..25526246e7
--- /dev/null
+++ b/test/integration/targets/collections/ansiballz_dupe/test_ansiballz_cache_dupe_shortname.yml
@@ -0,0 +1,15 @@
+- hosts: localhost
+ gather_facts: false
+ tasks:
+ - ping:
+ register: result1
+
+ - ping:
+ collections:
+ - duplicate.name
+ register: result2
+
+ - assert:
+ that:
+ - result1.ping == 'pong'
+ - result2.ping == 'duplicate.name.pong'
diff --git a/test/integration/targets/collections/runme.sh b/test/integration/targets/collections/runme.sh
index 1e9584ff43..663b3e1cd7 100755
--- a/test/integration/targets/collections/runme.sh
+++ b/test/integration/targets/collections/runme.sh
@@ -104,6 +104,9 @@ ansible-playbook inventory_test.yml -i a.statichost.yml -i redirected.statichost
# test plugin loader redirect_list
ansible-playbook test_redirect_list.yml -v "$@"
+# test ansiballz cache dupe
+ansible-playbook ansiballz_dupe/test_ansiballz_cache_dupe_shortname.yml -v "$@"
+
# test adjacent with --playbook-dir
export ANSIBLE_COLLECTIONS_PATH=''
ANSIBLE_INVENTORY_ANY_UNPARSED_IS_FAILED=1 ansible-inventory --list --export --playbook-dir=. -v "$@"