-
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
Variables in role dependencies not correctly scoped so defaults are overriden by different role invocations in Ansible 2.0.0.2 #14472
Comments
Trying to fix earlier issue resulted into me bumping in another bug: ansible/ansible#14472 So this is a workaround to not touch to variable until the scoping is right.
I am encountering a variation of this issue, when I have a role with a dependency, say something along the lines of :
All subsequent reference to This happened to work as I expect in latest Ansible versions. |
I'm having the same problem in 2.0.1.0. |
* Make role param resolution follow the role dependency chain, rather than using all roles within the play * Also move params to be merged in after role vars in general, to match our variable precedence rules * Changes to the way var lookup is done in role helper methods for get_vars(), get_inherited_vars(), and get_role_params() to make the above possible without trampling on previously merged vars Fixes #14472 Fixes #14475
Closing This TicketHi! We believe the above commit should resolve this problem for you. This will also be included in the next release. If you continue seeing any problems related to this issue, or 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! |
* Make role param resolution follow the role dependency chain, rather than using all roles within the play * Also move params to be merged in after role vars in general, to match our variable precedence rules * Changes to the way var lookup is done in role helper methods for get_vars(), get_inherited_vars(), and get_role_params() to make the above possible without trampling on previously merged vars Fixes #14472 Fixes #14475
If I have a role that I use multiple times in the same playbook with different variables each time, a variable declared in one invocation of the role will override defaults in other invocations of the same role.
I've committed a playbook with roles that illustrates the problem: https://github.com/dwcramer/ansible-bug
Notice that the role example2 depends on the role example more than one time but passes different variables each time. The effect would also exist if I have several different roles depending on the same role with different variables passed in. For example, say I'm using a role that sets up upstart jobs for different services I lay down.
Notice that in Ansible 2.x, a value assigned to a variable in one invocation of the role (
some_variable: [1,2]
overrides the default in all invocations of the role, not just the one to which it applies.A workaround is to explicitly assign a value to the role each time you invoke it, but that's not how it should work.
The actual output of this playbook is:
The expected output and the output from Ansible 1.9.x is:
The text was updated successfully, but these errors were encountered: