diff options
author | Sloane Hertel <19572925+s-hertel@users.noreply.github.com> | 2021-03-08 05:26:47 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-08 04:26:47 -0600 |
commit | 3e95e3c0a0ae7fc6bf55ccce5cdd6d7c3c4a3d99 (patch) | |
tree | 0eb8f39bfe0d3885a14a6c7debf9d097dc6b7bc2 | |
parent | ece31e1b51ce923d4ca3a9f649fd055ab0656ece (diff) | |
download | ansible-3e95e3c0a0ae7fc6bf55ccce5cdd6d7c3c4a3d99.tar.gz |
galaxy: Handle ignored directory names in role skeleton (#72035) (#73806)
* galaxy: restore left hand slicing in assignment
Fix 'ansible-galaxy role init --role-skeleton=role-skeleton' when the role skeleton
contains an ignored directory.
The issue was because the 'dirs' variable was changed to reference a different list,
but needs to be mutated instead to stop os.walk from traversing ignored directories.
Fixes: #71977
Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit eb72c36a71c8bf786d575a31246f602ad69cc9c9)
Co-authored-by: manas-init <70483021+manas-init@users.noreply.github.com>
-rw-r--r-- | changelogs/fragments/71977-ansible-galaxy-role-init.yml | 2 | ||||
-rw-r--r-- | lib/ansible/cli/galaxy.py | 4 | ||||
-rwxr-xr-x | test/integration/targets/ansible-galaxy/runme.sh | 13 |
3 files changed, 18 insertions, 1 deletions
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 0000000000..f37eb1a6c8 --- /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 71cdee4963..35d8fa8046 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -877,7 +877,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 3a7c4a3908..22587001ef 100755 --- a/test/integration/targets/ansible-galaxy/runme.sh +++ b/test/integration/targets/ansible-galaxy/runme.sh @@ -317,6 +317,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 ################################# |