-
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
Add feature to expose vars/defaults with include/import_role #41330
Conversation
not_bot_skip_any_more |
TODO:
|
lib/ansible/playbook/helpers.py
Outdated
@@ -355,8 +355,7 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h | |||
ir._role_name = templar.template(ir._role_name) | |||
|
|||
# uses compiled list from object | |||
blocks, _ = ir.get_block_list(variable_manager=variable_manager, loader=loader) | |||
task_list.extend(blocks) | |||
ir.get_block_list(variable_manager=variable_manager, loader=loader) |
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.
Without this change, the tasks get executed twice. Using this change causes the tasks of the role to execute before other tasks listed in tasks
.
d3f9ea9
to
a5726ce
Compare
One thing I'm wondering about is the timing of variable availability. Are role variables only available after the role has been called or immediately from the beginning of the play? I would think this is the case for Also, are the vars available to subsequent plays in the same playbook? I just thought these would be useful things to clarify in the final docs and possibly implement in the final code. |
At the moment, there are tests describing this. Once, exposed, the same rules apply to roles vars that are defined under the |
c45440e
to
a702926
Compare
I think this can come out of WIP now. |
4123cc8
to
c7c2ded
Compare
(rebased) |
…#41330) * First pass at making 'private' work on include_role, imports are always public * Prevent dupe task execution and overwriting handlers * New functionality will use public instead of deprecated private * Add tests for public exposure * Validate vars before import/include to ensure they don't expose too early * Add porting guide docs about public argument and change to import_role * Add additional docs about public and vars exposure to module docs * Insert role handlers at parse time, exposing them globally
This is awesome. My favorite feature of 2.7.0 Thanks @sivel |
SUMMARY
This PR aims to add functionality to
import_role
andinclude_role
to allow exposing vars/defaults from the role.import_role
always exposes.include_role
can be toggled, but defaults topublic=False
.This PR re-uses theprivate
argument, but I debate flipping that topublic
, or at minimum renaming to a different argument as to cause less confusion.ISSUE TYPE
COMPONENT NAME
lib/ansible/playbook/helpers.py
lib/ansible/playbook/role_include.py
ANSIBLE VERSION
ADDITIONAL INFORMATION