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

defaults role variables have global namespace #12373

mik735824 opened this Issue Sep 15, 2015 · 4 comments


None yet
4 participants

mik735824 commented Sep 15, 2015

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.

ansible/roles/role1/defaults/main.yml( main.yml is symlink to configs/config_role1.yml )
ansible/roles/role2/defaults/main.yml( main.yml is symlink to configs//config_role2.yml )

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.
Expected result:
var1 is defined for role1 and var1 is NOT defined for role1
Actiual result:
var1 is defined for role1 - good
var1 is defined for role2 too - bad.

From defaults variables description I believe, that var1 should be defined only for role1


This comment has been minimized.


jimi-c commented Sep 15, 2015

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.

Thank you!

@jimi-c jimi-c closed this Sep 15, 2015


This comment has been minimized.

ghost commented Aug 10, 2017

Despite the fact that this probably does not get read – am I the only one who thinks that the missing namespace is an issue and using a prefix for variables like role_varname feels ugly?


This comment has been minimized.

vijaykatam commented Aug 13, 2017

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?


This comment has been minimized.

AloisMahdal commented Oct 6, 2017

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 hostname, and trouble is inevitable.

(Also, from what I've seen, this also applies to other things like handler names.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment