ansible-galaxy - fix role list bug (#67391)

Properly list roles even when the role name is the same or a substring of the
path to the role.
pull/45569/head
Sam Doran 6 years ago committed by GitHub
parent 343de73f2d
commit c64202a495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- ansible-galaxy - properly list roles when the role name also happens to be in the role path (https://github.com/ansible/ansible/issues/67365)

@ -66,8 +66,18 @@ class GalaxyRole(object):
self.scm = scm
if path is not None:
if self.name not in path:
if not path.endswith(os.path.join(os.path.sep, self.name)):
path = os.path.join(path, self.name)
else:
# Look for a meta/main.ya?ml inside the potential role dir in case
# the role name is the same as parent directory of the role.
#
# Example:
# ./roles/testing/testing/meta/main.yml
for meta_main in self.META_MAIN:
if os.path.exists(os.path.join(path, name, meta_main)):
path = os.path.join(path, self.name)
break
self.path = path
else:
# use the first path by default

@ -108,7 +108,7 @@ popd # ${galaxy_testdir}
rm -fr "${galaxy_testdir}"
# Galaxy role list test case
# Galaxy role list tests
#
# Basic tests to ensure listing roles works
@ -121,6 +121,33 @@ f_ansible_galaxy_status \
[[ $(grep -c '^- test-role' out.txt ) -eq 2 ]]
# Properly list roles when the role name is a subset of the path, or the role
# name is the same name as the parent directory of the role. Issue #67365
#
# ./parrot/parrot
# ./parrot/arr
# ./testing-roles/test
f_ansible_galaxy_status \
"list roles where the role name is the same or a subset of the role path (#67365)"
role_testdir=$(mktemp -d)
pushd "${role_testdir}"
mkdir parrot
ansible-galaxy role init --init-path ./parrot parrot
ansible-galaxy role init --init-path ./parrot parrot-ship
ansible-galaxy role init --init-path ./parrot arr
ansible-galaxy role list -p ./parrot | tee out.txt
[[ $(grep -Ec '\- (parrot|arr)' out.txt) -eq 3 ]]
ansible-galaxy role list test-role | tee -a out.txt
popd # ${role_testdir}
rm -rf "${role_testdir}"
#################################
# ansible-galaxy collection tests
#################################

Loading…
Cancel
Save