title: How to model a multi db setup on one host in ansible?
body: <p><strong>Here is the setup</strong><br>
  Each of the environments have one or many dbserves.<br>
  Each dbserver can, but must not, have databases running on different ports. E.g:</p>
  
  <p>server1:port1 -> db1<br>
  server1:port2 -> db2<br>
  server2:port1 -> db3  </p>
  
  <p>I want to insert configuration updates to the databases. The question is now how to model this setup in ansible: </p>
  
  <ul>
  <li>I can not go by host_vars since the ports are not unique by host</li>
  <li>since I do not know how many db servers I have I would need to have a generic approach (so the option to pass via -e or as role var is not possible)</li>
  <li>I can not use nested loops (e.g. over the ports) since the ports differ </li>
  </ul>
  
  <p><strong>My workaround</strong><br>
  I came up with a workaround to have groups as like:  </p>
  
  <p>dbservers_db1<br>
  dbservers_db2  </p>
  
  <p>That way I can do the following:</p>
  
  <pre><code>- include_tasks: db_config_update.yml 
    with_items:
      - "{{ groups['dbservers_db1'] }}"   
    loop_control:
      loop_var: host
  
  - include_tasks: db_config_update.yml 
    with_items:
      - "{{ groups['dbservers_db2'] }}"   
    loop_control:
      loop_var: host
  </code></pre>
  
  <p>Note: this can not be done in ONE loop since ansible would detect the same host and process it only once.</p>
  
  <p>But this workaround has its limitations:  </p>
  
  <ul>
  <li>I need for every further db a new group </li>
  <li>it is not intuitive</li>
  </ul>
  
  <p><strong>How could this be modeled in a smarter way ?</strong></p>