title: Ansible - read inventory hosts and variables to group_vars/all file
body: <p>I have a dummy doubt that keeps me stuck for a long time. I have a very banal inventory file with hosts and variables:</p>
  
  <pre><code>[lb]
  10.112.84.122
  
  [tomcat]
  10.112.84.124
  
  [jboss5]
  10.112.84.122
  
  ...
  
  [tests:children]
  lb
  tomcat
  jboss5
  
  [default:children]
  tests
  
  [tests:vars]
  data_base_user=NETWIN-4.3
  data_base_password=NETWIN
  data_base_encrypted_password=
  data_base_host=10.112.69.48
  data_base_port=1521
  data_base_service=ssdenwdb
  data_base_url=jdbc:oracle:thin:@10.112.69.48:1521/ssdenwdb
  </code></pre>
  
  <p>The problem is that I need to access all these hosts and variables, in the inventory file, from the group_vars/all file.</p>
  
  <p>I've tried the following manners to access the host IP:</p>
  
  <pre><code>{{ lb }}
  "{{ hostvars[lb] }}"
  "{{ hostvars['lb'] }}"
  {{ hostvars[lb] }}
  </code></pre>
  
  <p>To access a host variable I tried:</p>
  
  <pre><code>"{{ hostvars[tests].['data_base_host'] }}"
  </code></pre>
  
  <p>All of them are wrong!!! Can anyone help me find out the best practice to access hosts and variables, not from a playbook but from a variables file?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Ok. Let's clarify.</p>
  
  <p><em>Problem:</em> Use a host declared in the inventory file in a variable file, let's say: group_vars/all.</p>
  
  <p><em>Example:</em> I have a DB host with <code>IP:10.112.83.37</code>.</p>
  
  <p>Inventory file:</p>
  
  <pre><code>[db]
  10.112.83.37
  </code></pre>
  
  <p>In the group:vars/all file I want to use that IP to build a variable.</p>
  
  <p>group_vars/all file:</p>
  
  <pre><code>data_base_url=jdbc:oracle:thin:@{{ db }}:1521/ssdenwdb
  </code></pre>
  
  <p>In a template I use the variable built in the group_vars/all file.</p>
  
  <p>Template file:</p>
  
  <pre><code>oracle_url = {{ data_base_url }}
  </code></pre>
  
  <p>The problem is that the <code>{{ db }}</code> variable in the group_vars/all file is not replaced by the DB host IP. The user can only edit the inventory file.</p>