diff --git a/changelogs/fragments/71977-ansible-galaxy-role-init.yml b/changelogs/fragments/71977-ansible-galaxy-role-init.yml new file mode 100644 index 00000000000..f37eb1a6c86 --- /dev/null +++ b/changelogs/fragments/71977-ansible-galaxy-role-init.yml @@ -0,0 +1,2 @@ +bugfixes: +- "ansible-galaxy - fixed galaxy role init command (https://github.com/ansible/ansible/issues/71977)." diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index dedceced7e4..d34544e37b0 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -980,7 +980,9 @@ class GalaxyCLI(CLI): else: in_templates_dir = rel_root_dir == 'templates' - dirs = [d for d in dirs if not any(r.match(d) for r in skeleton_ignore_re)] + # Filter out ignored directory names + # Use [:] to mutate the list os.walk uses + dirs[:] = [d for d in dirs if not any(r.match(d) for r in skeleton_ignore_re)] for f in files: filename, ext = os.path.splitext(f) diff --git a/test/integration/targets/ansible-galaxy/runme.sh b/test/integration/targets/ansible-galaxy/runme.sh index 165601cc62c..1f2d56b311e 100755 --- a/test/integration/targets/ansible-galaxy/runme.sh +++ b/test/integration/targets/ansible-galaxy/runme.sh @@ -324,6 +324,19 @@ pushd "${role_testdir}" popd # ${role_testdir} rm -rf "${role_testdir}" +f_ansible_galaxy_status \ + "Test if git hidden directories are skipped while using role skeleton (#71977)" + +role_testdir=$(mktemp -d) +pushd "${role_testdir}" + + ansible-galaxy role init sample-role-skeleton + git init ./sample-role-skeleton + ansible-galaxy role init --role-skeleton=sample-role-skeleton example + +popd # ${role_testdir} +rm -rf "${role_testdir}" + ################################# # ansible-galaxy collection tests #################################