title: Accessing inventory host variable in Ansible playbook
body: <p>In Ansible 2.1, I have a role being called by a playbook that needs access to a host file variable.  Any thoughts on how to access it?</p>
  <p>I am trying to access the <code>ansible_ssh_host</code> in the <code>test1</code> section of the following inventory <code>host</code> file:</p>
  <pre><code>[test1]
  test-1 ansible_ssh_host=abc.def.ghi.jkl ansible_ssh_port=1212
  
  [test2]
  test2-1 ansible_ssh_host=abc.def.ghi.mno ansible_ssh_port=1212
  
  [test3]
  test3-1 ansible_ssh_host=abc.def.ghi.pqr ansible_ssh_port=1212
  test3-2 ansible_ssh_host=abc.def.ghi.stu ansible_ssh_port=1212
  
  [all:children]
  test1
  test2
  test3
  </code></pre>
  <p>I have tried accessing the role in the following fashions:</p>
  <pre><code>{{ hostvars.ansible_ssh_host }} 
  </code></pre>
  <p>and</p>
  <pre><code>{{ hostvars.test1.ansible_ssh_host }}
  </code></pre>
  <p>I get this error:</p>
  <pre><code>fatal: [localhost]: FAILED! =&gt; {&quot;failed&quot;: true, &quot;msg&quot;: &quot;'ansible.vars.hostvars.HostVars object' has no attribute 'ansible'&quot;}
  </code></pre>