title: Variable in a variable dict name in Ansible
body: <p>I have dictionary like so:</p>
  <pre><code>mydatabases:
    group1:
      db_name: group1_database
    group2:
      db_name: group2_database
  </code></pre>
  <p>I want to be able to pass in <em>a_group</em> variable at runtime to retrieve the <em>db_name</em>. So something like this</p>
  <pre><code>{{ mydatabases.{{ a_group }}.db_name }}
  </code></pre>
  <p>but I know this method is not possible.</p>
  <p>Something like the below of course works and I can get the value which will return group1_database but not exactly what I want.</p>
  <pre><code>- debug: 
      msg:&quot;{{ mydatabases.group1.db_name }}&quot;
  </code></pre>
  <p>This give me an undefined variable</p>
  <pre><code>- debug:
      msg: &quot;{{ hostvars[inventory_hostname]['mydatabases' + a_group + 'db_name'] }}&quot;
  </code></pre>
  <p>Is there a way I can do this?</p>