A template for deploying your containerized projects on a single-node server.
An extension of: https://redhat-cop.github.io/automation-good-practices/
- variables should be defined in two places only: In the
defaults/main.ymlsection of a role, and in thegroup_vars/<name>/main.ymlsection. - prefix all variables used by a role with the role name, and if you want a default value define it in
defaults/main.yml. - prefix all generic variables defined in
group_vars/<name>/main.ymlwith_, and only use them to explicity override role variables:#group_vars/all/main.yml vars: _replicas: 1 rolename__replicas: {{ _replicas }} database__replicas: {{ _replicas }} - you can define temporary variables in a role using
set_facts, but only when it's part of the role logic. Use any name you want, but avoid reserved names or names that start with_.
Why these strict rules? Ansible variables are untyped, and extremely flexible. You can define them everywhere: in a playbook, in a role, in a task, in an inventory, in group_var/, in host_vars/, you can even manually define them from the command line when running a playbook.
Because of this, managing variables can become extremely hard. When you meet a variable, how do you know where it's defined? when you change a variable, how do you know what roles will be affected?
With these additional rules, following variables becomes verbose, but simple:
- when you change a vatialbe in
group_vars, what role does it affect? just look at the variable prefix. if the variable is calledrolename__passwordfor example, the affected role isrolename. - when you meet a variable in a role, where is it defined? the default value is in
rolename/defaults/main.yml. it can be overridden ingroup_vars/groupname/main.yml. Ansible will not start if the variable is not defined in one of those two places. Remember the variable lookup precendence. variables defined in group_vars will override defaults values.
Is this web scale? yes, it's web scale. And blazing fast