Skip to content

Add warning when later roles are overridden#48587

Closed
ianw wants to merge 1 commit intoansible:develfrom
ianw:note-role-overrides
Closed

Add warning when later roles are overridden#48587
ianw wants to merge 1 commit intoansible:develfrom
ianw:note-role-overrides

Conversation

@ianw
Copy link
Contributor

@ianw ianw commented Nov 13, 2018

SUMMARY

You currently don't get any sort of help diagnosing a situation where
a role in a later entry of ANSIBLE_ROLES_PATH is overriden by a role
with the same name earlier in the path. Although you can pick things
out of the task paths from when it's running, since the names are the
same (kind of the point :) it can be very confusing as to what's
happening.

This continues the path walk when importing the roles, and warns if
you have later roles that are being ignored due to earlier matches.

The documentation is enhanced to discuss the role import precedence.

An integration test is added to match the new behaviour.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

playbook/role

ADDITIONAL INFORMATION

This situation arose because we moved a role in our git tree. This particular role had a filter_plugin so it actually left behind a __pycache__ directory and .pyc file from when it had run. This meant we had essentially a blank role -- no tasks, variables or anything else in the role -- but it was still being picked up and "run". With no tasks it just appeared that the role was being read (I mean, the role: -roleinquestion was not giving a not found error) but somehow doing nothing at all. This was even more vexing, as "git status" usually ignores .pyc files so it was completely opaque as to what was going on, and it had only moved up a directory so you can very easily miss this in long paths.

Of course, when it is explained, it all becomes rather obvious. However, I feel a warning like this would have made it much clearer much sooner. I think a warning is justified as it is best practice to avoid pointing guns at your foot by giving roles the same name.

@ansibot
Copy link
Contributor

ansibot commented Nov 13, 2018

Hi @ianw, thank you for submitting this pull-request!

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Nov 13, 2018

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 core_review In order to be merged, this PR must follow the core review workflow. docs This issue/PR relates to or includes documentation. feature This issue/PR relates to a feature request. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Nov 13, 2018
@ansibot
Copy link
Contributor

ansibot commented Nov 13, 2018

The test ansible-test sanity --test yamllint [explain] failed with 1 error:

test/integration/targets/include_import/override_role/role1/tasks/main.yml:3:1: empty-lines too many blank lines (1 > 0)

click here for bot help

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Nov 13, 2018
@ianw ianw force-pushed the note-role-overrides branch from 90c7599 to 109dda7 Compare November 13, 2018 04:41
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Nov 13, 2018
@bcoca bcoca assigned bcoca and sivel Nov 13, 2018
@mattclay
Copy link
Member

CI failure in integration tests: https://app.shippable.com/github/ansible/ansible/runs/93400/65/console

@mattclay mattclay added the ci_verified Changes made in this PR are causing tests to fail. label Nov 16, 2018
@ianw
Copy link
Contributor Author

ianw commented Nov 16, 2018

@mattclay would you have any suggestions here? When I run ./bin/ansible-test integration --tox include_import it seems to work

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Nov 24, 2018
@bcoca
Copy link
Member

bcoca commented Nov 30, 2018

This seems expensive to have in runtime, ansible-galaxy list will show duplicate roles in different paths

@ansibot ansibot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label Nov 30, 2018
@ianw ianw force-pushed the note-role-overrides branch from 109dda7 to 2194e27 Compare November 30, 2018 04:55
@ansibot ansibot removed ci_verified Changes made in this PR are causing tests to fail. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Nov 30, 2018
You currently don't get any sort of help diagnosing a situation where
a role in a later entry of ANSIBLE_ROLES_PATH is overriden by a role
with the same name earlier in the path.  Although you can pick things
out of the task paths from when it's running, since the names are the
same (kind of the point :) it can be very confusing as to what's
happening.

This continues the path walk when importing the roles, and warns if
you have later roles that are being ignored due to earlier matches.

The documentation is enhanced to discuss the role import precedence.

An integration test is added to match the new behaviour.
@ianw ianw force-pushed the note-role-overrides branch from 2194e27 to 2438834 Compare November 30, 2018 05:53
@ianw ianw closed this Nov 30, 2018
@ianw ianw reopened this Nov 30, 2018
@ansibot ansibot added the docsite This issue/PR relates to the documentation website. label Nov 30, 2018
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Dec 8, 2018
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Dec 23, 2018
@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Jan 8, 2019
@jimi-c
Copy link
Member

jimi-c commented Jun 5, 2020

Hi @ianw, sorry for taking so long to get back to this. Unfortunately I think we're going to pass on merging this for now for the following reasons:

  • Collections help to avoid collisions, so using the FQCN for roles should prevent the problem.
  • Using verbose output shows the path to the task as it's run, so while debugging issues you can see exactly where the task definition came from including the role path.
  • Due to the addition of collections, additional checks would need to be made while looking up the role path.

If you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:

Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved.

Thank you!

@jimi-c jimi-c closed this Jun 5, 2020
@ansible ansible locked and limited conversation to collaborators Jul 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

affects_2.8 This issue/PR affects Ansible v2.8 docs This issue/PR relates to or includes documentation. docsite This issue/PR relates to the documentation website. feature This issue/PR relates to a feature request. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants