title: How to access a nested variable in a referenced Hash.
body: <p>I'm writing an Ansible Playbook and am trying to access a nested variable inside a referenced hash. </p>
  
  <p>Here is my vars file: </p>
  
  <pre><code>SourceIPs:
    192.168.33.20:
      DestIP: 192.168.33.30
      Port: 22
    192.168.33.30:
      DestIP: 192.168.33.20
      Port: 22
  </code></pre>
  
  <p>Here is my task file: </p>
  
  <pre><code>- name: Testing varibale access.
    debug:
      msg: " Source IP: {{ ansible_host }} corresponding Port IP and Port {{ SourceIPs[' {{ansible_host}} '] }}  "
  </code></pre>
  
  <p>It fails when executing this saying dict_object has no variable called {{ ansible_host }}. So clearly its not converting that to the IP address of the current host. </p>
  
  <p>However if I modify the task file to include a static host ip like so: </p>
  
  <pre><code>- name: Testing varibale access.
    debug:
      msg: " Source IP: {{ ansible_host }} corresponding Port IP and Port {{ SourceIPs['192.168.33.30'] }}  "
  </code></pre>
  
  <p>It works and get the values back for that particular host. </p>
  
  <p>What I'm trying to achieve is get the values back associated to the host I'm currently executing on. </p>