-
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
import_role vars persist across plays #46824
Comments
This is indeed expected and is documented at https://docs.ansible.com/ansible/latest/porting_guides/porting_guide_2.7.html#include-role-and-import-role-variable-exposure If you have further questions please stop by IRC or the mailing list:
|
Perhaps you have not read my issue correctly. If the behaviour is intended by this statement: "import_role does not support the public argument, and will unconditionally expose the role’s defaults and vars to the rest of the playbook. This functionality brings import_role into closer alignment with roles listed within the roles header in a play." then:-
|
I will admit that I read your issue multiple times. However I struggled to see a problem outside of the documentation and implementation. However, it seems I was wrong. I've updated the title to better reflect your problem, in that vars from An example that misbehaves:
This should produce the following in the 2nd play, but it does not.
When any other role is listed under |
Yes. I have no idea what is expected/correct though, only what it did before. The porting guide clearly says expose to the rest of playbook (not rest of play) - which is very new behaviour. |
Just as an update here, the problem is that As such, if This is a potentially big problem for the future, so I'm going to look into a solution to address that root cause, instead of a one off for just roles. |
I was thinking this scoping issue in general was likely to hit big problems if not well defined. I only came across this particular issue while trying to improve my own docs. What would be most useful is to know what the ansible team want the scoping to work in the long term. For your reference I am pasting the current incarnation of my attempt to document it - if only for you to see that it is seems more complex than the docs suggest, at least to me. |
Sorry, hit the wrong button :-) |
Hi @torched99, thank you for submitting this issue! |
…g a callable for defaults of mutable types. Fixes ansible#46824
…g a callable for defaults of mutable types. Fixes ansible#46824 (ansible#46833)
…llow supplying a callable for defaults of mutable types. Fixes ansible#46824 (ansible#46833). (cherry picked from commit a06a5de) Co-authored-by: Matt Martz <matt@sivel.net>
…g a callable for defaults of mutable types. Fixes ansible#46824 (ansible#46833)
SUMMARY
Please confirm the ansible 2.7 scope change for import_role vars. It now behaves differently to previous versions in that for example role/vars/main.yml (or role/defaults/main.yml) definition live across plays (unlike roles: keyword inclusions, and meta dependency based inclusions, and also include_role with public: no).
The presence of 'roles:' keyword in either play makes behaviour revert to 2.6 form.
Also being a static var definition (pre-processor) it also works in reverse, where the import can exist in a play later in sequence, such that at earlier sequenced plays will resolve the variable to the value defined by the later play's role.
As far as I can tell old 2.6 behaviour allowed for variables to have a scope across plays in a playbook only via:
static:
global config
inventory
host and local facts
extra vars
dynamic:
local_facts task
include_vars task
So this introduces a role level cross play static variable capability. Apologies if my terminology is confusing but I find the ansible use of the word 'static' confusing myself (as it more akin to a pre-processor scope, that generally behaves with a programmatic dynamic scope across role/block/task within a play).
ISSUE TYPE
COMPONENT NAME
import_role
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
Oracle Linux 6
STEPS TO REPRODUCE
Try the following playbook on 2.6 and 2.7, compare diff.
EXPECTED RESULTS
With version 2.6.x the second play would show variable undefined for testvar.
Expected? I have no idea what to expect any more with the super complex scope rules ansible has (and that keep subtly changing). So please clarify either way, and ideally describe any future plans to change.
ACTUAL RESULTS
Extract of last section of stdout:
The text was updated successfully, but these errors were encountered: