The new roles feature in 1.2 provides a very interesting level of modularity and re-usability. While ansible is ‘batteries included’ because of its rich set of modules, roles seem like higher level service definitions (built upon modules).
I have begun concerting over certain higher level functionality (e.g. apache, varnish, etc) to roles and in doing so I leverage the roles//vars/main.yml (vars_file) as the location to define the sane default values for variables. However, I would like to enable users of the role to be able to override these defaults if/as necessary.
I’ve found that vars_files defined at the playbooks level have higher precedence than roles//vars/main.yml, and role params (e.g
roles:
- { role: foo, param1: 1000 }
have higher precedence than var_files. But what I am wondering is if it makes sense, in the case of roles, to have even inventory variables higher precedent than role vars. My rationale is:
- Roles are discrete re-usable definitions of higher level functionality/capability that could (should?) be shared (I could even see a roles repository at some point down the rode). Providing sensible defaults in roles/<rolename>/vars/main.yml makes the most sense to me.
- GIven the above, inventory variables make sense, and are an easy way to override role vars. Requiring the user of the role to specify the variable override as a role param or even in a vars_file (via the playbook) just does not feel as simple to me. Even if you disagree, having
the option to use inventory vars instead of playbook vars_file and role params seems a good idea.
- Some of us use inventory scripts and our primary means of setting custom vars is via inventory vars. My inventory script accesses a DB which contains not just groups of servers, but also the vars for that specific environment.
So to summarize, would it make sense to treat role var_files with lowest precedent so they can be easily decoupled from playbooks and yet overridden with inventory variables?