Inventory hostname as variable ?

7,315 views
Skip to first unread message

Julien Tognazzi

unread,
Sep 25, 2012, 10:47:59 AM9/25/12
to ansible...@googlegroups.com
Hi,

I try to search the doc and the list to see if it is possible to use the inventory hostname in playbooks (the one specified in /etc/ansible/hosts).

Because in case the name in the inventory doesn't match the remote hostname (/etc/hosts, cname, etc.), the setup module isn't reporting any ansible variable with this info.

Did I miss something ?

Julien.

Michael DeHaan

unread,
Sep 25, 2012, 11:19:31 AM9/25/12
to ansible...@googlegroups.com
There's a "magic" variable called $inventory_hostname that matches the
name given in the inventory file, that I think is what you want.

Derek Carter

unread,
Sep 25, 2012, 11:21:30 AM9/25/12
to ansible...@googlegroups.com
I'm not sure where it is on the docs but the two varibles you get
automatically are

$inventory_hostname

and

$inventory_hostname_short

The latter being everything up to the first '.' in $inventory_hostname

--
Derek aka goozbach

Julien Tognazzi

unread,
Sep 27, 2012, 3:45:58 AM9/27/12
to ansible...@googlegroups.com
Great !
Exactly what I was looking for.
And, it is mentioned in the docs in the following section.

So all is good.

Thank you.
Reply all
Reply to author
Forward
0 new messages