I’m not entirely sure that I understand your post…
Concerning the role generated by ansible-galaxy:
Technically the roles were generated by their authors, you load them from the galaxy repository using ansibe-galaxy.
I question the inclusion of the /vars directory in the generated role. Populated /vars directories in roles found in the wold are a barrier to reuse. While it is great that variables defined in /vars are scoped to the role, I believe the same results can always be achieved by including variables in /defaults when developing roles for others to used.
So, you are saying that people writing roles should only include vars set in /defaults and not in /vars. I would suggest that most people developing roles are developing roles for themselves and are then sharing their roles as a way to give back to the community. As a result they are sharing a sample /vars file.
Populating the /vars directory should be left completely to the end user of a role. A user who downloads a role should be free to add a /vars directory if they choose (or symlink to some vars directory or do anything else they please - these vars are for the end user). A user adding /vars should also not be tracked in version control. Currently, /vars are frequently included with roles that I see around github and tweaking them to customize the behavior of the role is a change that is tracked preventing clean pull upgrades. I believe /vars should be added to the .gitignore of the generated role.
That’s nice… I would suggest that when I create a role for myself, to scratch my own personal itches, I should be free to include /vars as that makes sense for what I want to do. If I then decide that I want to publicly share my work then I should be allowed to include the /vars file if that is what I want to do.
As far as I know, placing role variables in /defaults can always achieve the same results as placing variables in /vars. But adding some discipline to make role developers use /defaults provides benefits for reuse and end users of roles.
To my mind /defaults has different connotations than /vars… You might disagree but please follow along and see if this makes sense…
Let’s say I have developed a role, Widget, and that role needs to configure something to talk to another server. I don’t know what server name is going to work in your environment, but I can pretty much guarantee that it won’t be whatever worked for me. So If I put that server name in /defaults the implication is that that value will work for you out of the box. It’s a default, not a placeholder. In reality that “default” is not a default at all. So I could document somewhere that you will need to set variable “FooServer” to point to your FooServer, but then you have to remember to do that. If I instead put in a /vars file with “FooServer” set then my assumption would be that you would look at that file BEFORE applying the role to ensure that the contents made sense for your environment.
I realise that this is reading something into the names of the directories that is not actually imposed by the technology, but my assumption would always be that /defaults are just that, default values that should work.
To be clear, Ansible should absolutely still read variables from /vars, just encourage that populating /vars be left to role users. Too many role developers are using /vars. If the Ansible community doesn’t agree that this would be beneficial (which is fine, that’s up to you guys), our tooling will probably be considering only a subset of roles (those that exclude /vars from VCS) to be “valid”.
You are free to do what you want, this is a big world and I think that there should be room enough for everyone… (I could be wrong of course)
I understand where you are coming from, but I do not entirely agree with your conclusions.
Of course I have nothing to do with Ansible (except as a user) so none of this means anything to anyone other than me… ![:slight_smile: :slight_smile:](/images/emoji/twitter/slight_smile.png?v=12)
I hope that you can at least understand why I feel that /defaults and /vars are not the same thing.
Adam