Headache with variables: how to define same variable for multiple situation
Hi,
I'm struggling about how best to manage variables with ansible.
First, declaration of hosts:
cat inventory/hosts
---
redhat:
hosts:
w.x.y.z
w.x.y.z
w.x.y.z
webserver:
hosts:
w.x.y.z
For example, I want to use a single variable for software installation, e.g. "packages". I defined the following variable for all my RedHat systems.
cat inventory/group_vars/redhat
---
packages:
- a
- b
- c
Another role, e.g. webserver, use "package" too for web-specific installation. I declared this variable under group_vars for hosts.
cat inventory/group_vars/webserver
---
packages:
- httpd
The problem in this case is when I start the first role for default configuration, the variable defined under group_vars will take precedence for webserver host and default packages will neither be installed on it.
Is it possible to join such variables?
What does ansible recommend for this type of situation or what do you suggest?