Problems with global scoping & lazy template evaluation in playbooks & roles/includes

Hello Ansible Users & Devs,

I’m writing because I’ve found some strange behavior when trying to build abstractions out of roles (roles that include more generic roles in specific, configurable ways).

I intend to use roles to create re-usable components that many people can use for many different purposes. (tarball installers, git deployers, etc). However, sometimes I find I cannot use information which should be in the environment of the role and am forced instead to use vars from some other roles environment, one that I can’t control. Because of this behavior prior roles can leave around variables and break ‘undefined variable’ behavior and cause all sorts of other confusing and unexpected behavior.

I believe this is due to ansible roles not having unique environments but instead sharing an environment with the play as a whole.

I made a project to demonstrate this behavior:

https://github.com/eggsby/ansible-weirdness

I love roles, but if we are moving toward a global index similar to pypi or maven will I have to worry about some role doing something malicious with information left behind by some other role (say ssh key provisioning?)

Thanks, Ansible Rocks!
– Thomas Omans

Hi Thomas,

Thanks for posting this to the list.

I generally find discussions much easier to understandwhen we talk in terms of real world examples, and we can show how something can best be done in Ansible.

Do you have a real world example you can share and understand what you are trying to pass?

Then we can better talk about how to suggest doing what you are trying to do.

–Michael