title: Dynamic ansible host_vars
body: <p>I have a use case for a play where the installation path for tomcat changes based on the hostname and the value of a variable.  Not sure how to handle this.  For example, I have the following inventory:</p>
  
  <p>[servers]<br>
  server1<br>
  server2<br>
  server3</p>
  
  <p>I have a global_var that specifies the type of platform for my install like so:
  platform: training</p>
  
  <p>My platform variable could be set to training, production, development</p>
  
  <p>Based on the value of platform and the hostname, my tomcat installation path will be different, so I can't just have:</p>
  
  <p>host_vars/server1.yml<br>
  tomcat_path: /somepath1<br>
  host_vars/server2.yml<br>
  tomcat_path: /somepath2<br>
  host_vars/server3.yml<br>
  tomcat_path: /somepath3</p>
  
  <p>I'm looking to do something akin too:</p>
  
  <p>server1.yml<br>
  tomcat_path: /somepath1<br>
  when: "{{ platform }} == training"<br>
  tomcat_path: /somepath2<br>
  when: "{{ platform }} == production"<br>
  tomcat_path: /somepath3<br>
  when: "{{ platform }} == development"</p>
  
  <p>How do you handle such a case in ansible?  </p>