Ansible: get current target host's IP address
<p>How do you get the current host's IP address in a role?</p>

<p>I know you can get the list of groups the host is a member of and the hostname of the host but I am unable to find a solution to getting the IP address.</p>

<p>You can get the hostname by using <code>{{inventory_hostname}}</code> and the group by using <code>{{group_names}}</code></p>

<p>I have tried things like <code>{{ hostvars[{{ inventory_hostname }}]['ansible_ssh_host'] }}</code>
and <code>ip="{{ hostvars.{{ inventory_hostname }}.ansible_ssh_host }}"</code></p>