Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
defaults role variables have global namespace #12373
I have a project with multiple roles, and I need defaults vars for these with lowest priority.
I created the yaml file which describes my variable for each roles. And made link to it in the "defaults" directory for each role.
config_role1.yml and config_role2.yml have the variables with the same name.
The problem is that role2 "knows" about the variables from role1. If var1 is defined in the ansible/configs/config_role1.yml and var1 is not defined in the ansible/configs/config_role2.yml.
From defaults variables description I believe, that var1 should be defined only for role1
Hi @mik735824, this is how role defaults were designed. We typically recommend that default vars be "name-spaced" to prevent collisions like this, ie role1_var1 and role2_var1 (this is common for variable names like port, etc.)
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.
Although the convention role_varname is followed in an ansible project, it does not solve the problem of name-spacing of external roles which get integrated into an existing ansible project. How do you force an external role to namespace the variables or for that matter if there is a role name conflict?
Please correct me if I'm wrong, but this makes external role unusable without excessive review. It's enough to have one role and one playbook, or two (external) roles to not follow a sane convention and use variable like
(Also, from what I've seen, this also applies to other things like handler names.)