-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
ansible_parent_role_name/path variables for when a role is being included by another role #46687
Conversation
@Xaroth: thank you for submitting this pull-request! |
From what I can see the fails in the CI are not related to the code. |
Hi @Xaroth, It looks like an architectural change, which I believe requires a broader discussion. Thanks in advance! |
@webknjaz Thanks, proposal sent in. |
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.
Would be good to add some tests to defend this functionality
i would make this a list so you can trace back the full stack, not just the immediate parent |
test/integration/targets/include_parent_role_vars/tasks/main.yml
Outdated
Show resolved
Hide resolved
I added an extra test case to ensure that include_tasks and import_tasks does not affect the |
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.
shipit
This will bring very useful functionality, and appears to be well tested and documented. For bonus points, the code change itself is trivial.
test/integration/targets/include_parent_role_vars/tasks/included_by_ourselves.yml
Show resolved
Hide resolved
test/integration/targets/include_parent_role_vars/tasks/included_by_other_role.yml
Show resolved
Hide resolved
test/integration/targets/include_parent_role_vars/tasks/included_by_other_role.yml
Show resolved
Hide resolved
-Add: Test cases for ansible_parent_role_names and ansible_parent_role_paths -Add: ansible_parent_role_names/paths variables for when a role is being included by another role.
Added changes requested by @samdoran:
These changes add a lot of tests to the mix (around 50 new actions for the |
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'll merge this for 2.9 after we create a branch for 2.8.
-Add: Test cases for ansible_parent_role_names and ansible_parent_role_paths -Add: ansible_parent_role_names/paths variables for when a role is being included by another role.
SUMMARY
Currently it is not possible for roles to detect when they are being directly included by another role.
This PR does the following:
ansible_parent_role_name
to the name of the role that included this role.ansible_parent_role_path
to the path of the role that included this role.role_name
magic variable. It existed, but there was no existing documentation. Its companionrole_path
was already documented.The main rationale for this is that we currently have a large set of roles that, in addition of providing with a state that is being managed, also expose a set of extra callable task files to allow other roles to easily perform tasks related to that role, without having to duplicate logic several dozen times.
During these includes, it is often required to send an identifier along, so that comments can indicate which role/feature requested these actions. Currently this is done by passing variables to each include_role action, but this proves to be prone to error.
The
role_name
variable already exists, but since this only stores the current executing role, it doesn't help trace down the source if the role was included otherwise.The proposed new magic variables do specifically that; letting the included roles know who included them, so that it's easier to build conditions that only run (or should never run) when tasks are being included, and to be able to better debug the source of configuration.
ISSUE TYPE
COMPONENT NAME
Magic Variables
ANSIBLE VERSION
but this affects all versions.
ADDITIONAL INFORMATION