Skip to content
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

E106: Don't use relative paths for meta/main.yml #1044

Merged

Conversation

nre-ableton
Copy link
Contributor

@nre-ableton nre-ableton commented Sep 9, 2020

This change calculates the role's root directory by finding the
"tasks" directory first, rather than using the parent of the parent of
the current file. The problem with using the parent/parent scheme is
that roles which organize their tasks into subdirectories would cause
ansible-lint to erroneously raise E106 for an invalid role name.


Fixes #1001

Copy link
Member

@ssbarnea ssbarnea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, roles can exist without tasks but they cannot exist without meta. Also, meta is always at predictable location, regardless how the tasks are organized.

If we are fixing an existing bug, we clearly need a test that prevents a future regression, a test that would reproduce the current bug.

It would even be better if you can add a test that reproduces the current bug and add it using @pytest.mark.xfail before making this fix.

I am saying this because I want to avoid future regressions, especially as this area was touched multiple times, and recently too.

@nre-ableton nre-ableton force-pushed the nre/master/fix-e106-with-subdirs branch from 9660e46 to 5d6970d Compare September 9, 2020 13:41
@nre-ableton
Copy link
Contributor Author

nre-ableton commented Sep 9, 2020

Adding a task in a subdirectory of an existing role (such as valid-due-to-meta) will result in a failing test and reproduce the behavior. I tried to explain this in the commit message, but I think that your suggestion is much better. As such, I split the original commit to added the subdirectory and @pytest.mark.xfail in a separate commit with explanation there.

@ssbarnea
Copy link
Member

ssbarnea commented Sep 9, 2020

Adding a task in a subdirectory of an existing role (such as valid-due-to-meta) will result in a failing test and reproduce the behavior. I tried to explain this in the commit message, but I think that your suggestion is much better. As such, I split the original commit to added the subdirectory and @pytest.mark.xfail in a separate commit with explanation there.

In that case maybe just add a comment on the empty task file explaining why the file is there, so we do not remove it by mistake?

@ssbarnea ssbarnea added the bug label Sep 9, 2020
@ssbarnea ssbarnea self-assigned this Sep 9, 2020
The present behavior of ansible-lint will raise E106 in this case,
since it miscalculates the location of meta/main.yml from the task
subdirectory.
This change calculates the role's root directory by finding the
"tasks" directory first, rather than using the parent of the parent of
the current file. The problem with using the parent/parent scheme is
that roles which organize their tasks into subdirectories would cause
ansible-lint to erroneously raise E106 for an invalid role name.
@nre-ableton nre-ableton force-pushed the nre/master/fix-e106-with-subdirs branch from 5d6970d to 65d4ede Compare September 9, 2020 14:09
@nre-ableton
Copy link
Contributor Author

Adding a task in a subdirectory of an existing role (such as valid-due-to-meta) will result in a failing test and reproduce the behavior. I tried to explain this in the commit message, but I think that your suggestion is much better. As such, I split the original commit to added the subdirectory and @pytest.mark.xfail in a separate commit with explanation there.

In that case maybe just add a comment on the empty task file explaining why the file is there, so we do not remove it by mistake?

Great suggestion, done! Also, I removed the @pytest.mark.xfail comment in the subsequent commit that fixes the problem, I forgot to do this before. 😅

@ssbarnea ssbarnea merged commit 35ffeb8 into ansible:master Sep 9, 2020
@nre-ableton nre-ableton deleted the nre/master/fix-e106-with-subdirs branch September 9, 2020 16:03
@nre-ableton
Copy link
Contributor Author

@ssbarnea Thanks for the quick review and merge! 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

E106 is raised if subdirectories are present in the "tasks" folder
2 participants