title: Is there a way to use dynamic variables in ansible inventory group_vars files
body: <p>In my school's computer lab, I am tasked to manage a cluster of servers recently and have discovered <code>ansible</code> to be of great help.  Being new to it, I need help with the following scenario:</p>
  
  <p>The servers in the cluster all should be configured <em>nearly</em> identically based on a certain condition.</p>
  
  <p>To apply some variables to all the machines in the cluster, I have learned to use <code>group_vars</code> files with the <code>inventory</code>.  Nevertheless, there is a situation that I have not figured out what to do.</p>
  
  <p>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 <code>ansible-playbook</code>'s <code>-e</code> option (i.e. external variables).</p>
  
  <p>But where I got stuck is to make the corresponding variables in the <code>group_vars</code> files to take on new values based on the given operation condition variable's value.  </p>
  
  <p>Let's call <em>the operation condition</em> variable <code>opv</code>. The variables in a group_vars file let's say <code>var0</code>, <code>var1</code>, <code>var2</code></p>
  
  <ul>
  <li>for <code>opv=0</code>, <code>var0=v00</code>, <code>var1=v01</code>, <code>var2=v02</code></li>
  <li>for <code>opv=1</code>, <code>var0=v10</code>, <code>var1=v11</code>, <code>var2=v12</code></li>
  <li>for <code>opv=2</code>, <code>var0=v20</code>, <code>var1=v21</code>, <code>var2=v22</code>
  etc.</li>
  </ul>
  
  <p>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.</p>