In my school's computer lab, I am tasked to manage a cluster of servers recently and have discovered ansible
to be of great help. Being new to it, I need help with the following scenario:
The servers in the cluster all should be configured nearly identically based on a certain condition.
To apply some variables to all the machines in the cluster, I have learned to use group_vars
files with the inventory
. Nevertheless, there is a situation that I have not figured out what to do.
Depending on the specific operation that these servers are expected to handle, some variables should be set to values as appropriate for the desired condition; the value of each condition can be set to an variable. After some deliberation, I have came to the conclusion the easiest way is to use ansible-playbook
's -e
option (i.e. external variables).
But where I got stuck is to make the corresponding variables in the group_vars
files to take on new values based on the given operation condition variable's value.
Let's call the operation condition variable opv
. The variables in a group_vars file let's say var0
, var1
, var2
- for
opv=0
,var0=v00
,var1=v01
,var2=v02
- for
opv=1
,var0=v10
,var1=v11
,var2=v12
- for
opv=2
,var0=v20
,var1=v21
,var2=v22
etc.
Is there an elegant way to accomplish the above? Thanks in advance for any tips/hints. I am willing to dig. So, just pointers are great.