-
Notifications
You must be signed in to change notification settings - Fork 23.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
galaxy: Handle hidden git directories in role skeleton #72035
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a test (so we don't revert again) and a changelog so we can backport this.
Hi @bcoca I'm new to this. Could you please guide me on how to do the above mentioned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a priority bug preventing downstream testing from working properly in many places.
Typically speaking, you would use an integration test. We already have a directory at You would effectively add a test that roughly replicates the issue originally reported. It should fail without the fix, and pass with the fix. |
@manas-init Are you still working on this? Thanks. |
ansible-galaxy role init --role-skeleton=ansible-role-skeleton example fails. The issue was because 'dir' variable was changed to reference to a different list, but since it is a global variable so the update was causing issues. Now updating 'dir' variable to change value of variable in local scope. Fixes: ansible#71977
@bcoca I updated the test, could you please take a look? |
@@ -912,7 +912,7 @@ def execute_init(self): | |||
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)] | |||
dirs[:] = [d for d in dirs if not any(r.match(d) for r in skeleton_ignore_re)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could anybody explain why this works/necessary? I think it deserves a code comment. It looks to me like it exploits some side-effect of changing the list in-place instead of reassigning the object but I don't get why this fixes the bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it is due to mutating the dirs
created by os.walk
, which impacts future iterations that include that same dirs
reference.
I'm sure we could refactor the code, to not require it, but this is a known good change that works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking at the PR description, it sounds like it'd be saner to use a different variable name. Also, it looks like this could be moved closer to the loop that iterates over these dirs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's the point, it needs to mutate the existing reference, or the code needs refactored in a larger scale.
Hi there, I found that this may also be fixed by updating ansible/config/base.yml changing line 1414 to be:
this would be a smaller change |
@pbpblush This is a one-liner too 😄 Just has tests and changelog and a little baggage. Using the configuration setting is a good workaround, but I think we should fix it more generally like this. The setting matches files and directory names, so if "^.git$" matches a directory, the files inside of it should also be ignored. It doesn't look like the docs mention that the setting applies to directory names, but it looks intentional: c20beee. Anyone ignoring a directory name could experience this bug. For example, ANSIBLE_GALAXY_ROLE_SKELETON_IGNORE='^ignored_dir$' would skip the directory still but try to add any files inside of it, which causes the traceback, whereas before os.walk wouldn't consider the contents of skipped directories at all because we mutated the list instead of reassigning it. |
* 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: ansible#71977 Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com> (cherry picked from commit eb72c36)
) * 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 eb72c36) Co-authored-by: manas-init <70483021+manas-init@users.noreply.github.com>
ansible-galaxy role init --role-skeleton=ansible-role-skeleton example fails fix.
The issue was because 'dir' variable was changed to reference to a different list, but since it is a global variable so the update was causing issues.
Now updating 'dir' variable to change value of variable in local scope.
fixes #71977
SUMMARY
ISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION