Variable prefix
Prefix variable names with role or project prefix.
Categories:
Prefix variables in Ansible roles / collections with the role name. For example
harbor_hostname. Prefix other / project variables with a project prefix for
example c2_cacerts2_ca_dir.Problem
Without a project of role prefix it is not always clear where variables are used. Without a prefix there is also a chance of conflicting duplicating variables.
Context
In a typical project typically all kinds of variables are created / used. Some variables are used in Ansible roles but some do not. This can be confusing and lead to mistakes / problems.
Solution
- Prefix all variables used in an Ansible role with the role name for example
harbor_. - Prefix all other / project variables - that only exists in
group_varsorhost_varsfolder - with a project prefix for examplec2_.
Examples and implementation
- For example
harbor_hostnamefor the hostname of the Harbor instance. The prefix isharbor_because this is a variable that is part of thec2platform.mgmt.harborAnsible role. - In C2 Inventory project
c2platform/ansiblec2_is used as a prefix see for examplec2_cacerts2_ca_diringroup_vars/all/smallca.yml. - In the RWS Inventory project
c2platform/rws/ansible-gisgs_is used as prefix. See Configuring a Web Proxy Server Example for MS Windows Hosts for an example on howgs_proxy_regeditis utilized to configure a web proxy.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.