title: Ansible - Access inventory alias
body: <p>Having an inventory file like:</p>
  
  <pre><code>[my_hosts]
  my_host ansible_ssh_host=123.123.123.123
  my_host2 ansible_ssh_host=234.234.234.234
  </code></pre>
  
  <p>I want to gather some debug information in my templates.</p>
  
  <ul>
  <li><p>How do I acces the alias variable in a playbook/template?
  I.e.:</p>
  
  <pre><code>debug: msg=Myhost is {{ ansible_host_alias }} 
  # Myhost is my_host
  # Myhost is myhost2
  </code></pre></li>
  </ul>
  
  <p>I tried to gather facts using <code>ansible -m setup my_host</code> . The variables <code>ansible_hostname</code> , <code>HOSTNAME</code> and <code>HOST</code> contain the machine's hostname, i.e. <code>echo $HOSTNAME</code> which differs from my ansible alias.</p>