summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Borean <jborean93@gmail.com>2021-01-11 16:41:56 +1000
committerGitHub <noreply@github.com>2021-01-11 00:41:56 -0600
commitc5248f756c43a0ea0e6bd11249c466fa17c8fab2 (patch)
tree726f5b92f30ffbd4ae123e1a945af130b92686fb
parent511ffdeff79844c2125d8e4438738e7f1d045598 (diff)
downloadansible-c5248f756c43a0ea0e6bd11249c466fa17c8fab2.tar.gz
Collection list site packages (#70173) (#72940)
* ansible-galaxy collection list and verify now utilize collections in site-packages. This is a short term fix for #70147. The long term fix needs to handle install (but that discussion is also bound up in how upgrade is going to work and where things can get installed so it's deferred for 2.11.) * Add test for ansible-galaxy collection list with site-packages Co-authored-by: David Moreau Simard <moi@dmsimard.com> Co-authored-by: Jordan Borean <jborean93@gmail.com> (cherry picked from commit e7dee73774b0b436551e4993ba917eec1e03af2d) Co-authored-by: Toshio Kuratomi <a.badger@gmail.com>
-rw-r--r--changelogs/fragments/collection-list-site-packages.yaml3
-rw-r--r--lib/ansible/cli/galaxy.py6
-rwxr-xr-xtest/integration/targets/ansible-galaxy/runme.sh11
3 files changed, 18 insertions, 2 deletions
diff --git a/changelogs/fragments/collection-list-site-packages.yaml b/changelogs/fragments/collection-list-site-packages.yaml
new file mode 100644
index 0000000000..2f169fd77b
--- /dev/null
+++ b/changelogs/fragments/collection-list-site-packages.yaml
@@ -0,0 +1,3 @@
+bugfixes:
+- Fix ansible-galaxy collection list to show collections in site-packages
+ (https://github.com/ansible/ansible/issues/70147)
diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py
index 447fd128a4..71cdee4963 100644
--- a/lib/ansible/cli/galaxy.py
+++ b/lib/ansible/cli/galaxy.py
@@ -43,6 +43,7 @@ from ansible.parsing.dataloader import DataLoader
from ansible.parsing.yaml.loader import AnsibleLoader
from ansible.playbook.role.requirement import RoleRequirement
from ansible.template import Templar
+from ansible.utils.collection_loader import AnsibleCollectionConfig
from ansible.utils.display import Display
from ansible.utils.plugin_docs import get_versioned_doclink
@@ -163,7 +164,8 @@ class GalaxyCLI(CLI):
collections_path = opt_help.argparse.ArgumentParser(add_help=False)
collections_path.add_argument('-p', '--collection-path', dest='collections_path', type=opt_help.unfrack_path(pathsep=True),
- default=C.COLLECTIONS_PATHS, action=opt_help.PrependListAction,
+ default=AnsibleCollectionConfig.collection_paths,
+ action=opt_help.PrependListAction,
help="One or more directories to search for collections in addition "
"to the default COLLECTIONS_PATHS. Separate multiple paths "
"with '{0}'.".format(os.path.pathsep))
@@ -1253,7 +1255,7 @@ class GalaxyCLI(CLI):
collections_search_paths = set(context.CLIARGS['collections_path'])
collection_name = context.CLIARGS['collection']
- default_collections_path = C.config.get_configuration_definition('COLLECTIONS_PATHS').get('default')
+ default_collections_path = AnsibleCollectionConfig.collection_paths
warnings = []
path_found = False
diff --git a/test/integration/targets/ansible-galaxy/runme.sh b/test/integration/targets/ansible-galaxy/runme.sh
index 2cd59825bf..3a7c4a3908 100755
--- a/test/integration/targets/ansible-galaxy/runme.sh
+++ b/test/integration/targets/ansible-galaxy/runme.sh
@@ -415,6 +415,17 @@ f_ansible_galaxy_status \
unset ANSIBLE_COLLECTIONS_PATH
+f_ansible_galaxy_status \
+ "collection list with collections installed from python package"
+
+ mkdir -p test-site-packages
+ ln -s "${galaxy_testdir}/local/ansible_collections" test-site-packages/ansible_collections
+ ansible-galaxy collection list
+ PYTHONPATH="./test-site-packages/:$PYTHONPATH" ansible-galaxy collection list | tee out.txt
+
+ grep ".ansible/collections/ansible_collections" out.txt
+ grep "test-site-packages/ansible_collections" out.txt
+
## end ansible-galaxy collection list