Skip to content

Commit

Permalink
Collection list site packages (ansible#70173)
Browse files Browse the repository at this point in the history
* ansible-galaxy collection list and verify now utilize collections in site-packages.

This is a short term fix for ansible#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

* Fix sanity issue

Co-authored-by: David Moreau Simard <[email protected]>
Co-authored-by: Jordan Borean <[email protected]>
  • Loading branch information
3 people authored Dec 10, 2020
1 parent 0a60e5e commit e7dee73
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/collection-list-site-packages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- Fix ansible-galaxy collection list to show collections in site-packages
(https://github.com/ansible/ansible/issues/70147)
6 changes: 4 additions & 2 deletions lib/ansible/cli/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
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

Expand Down Expand Up @@ -165,7 +166,8 @@ def init_parser(self):

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))
Expand Down Expand Up @@ -1288,7 +1290,7 @@ def execute_list_collection(self):

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
Expand Down
11 changes: 11 additions & 0 deletions test/integration/targets/ansible-galaxy/runme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,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


Expand Down

0 comments on commit e7dee73

Please sign in to comment.