variable for server as entered in inventory

12 views
Skip to first unread message

Ed Greenberg

unread,
Dec 21, 2015, 9:13:11 PM12/21/15
to Ansible Project
I have an inventory that contains (for example):

[servers]
1.2.3.4
1.2.3.5
1.2.3.6
server1.foo.bar
server2.foo.bar

I'd like to access the entry under servers as a {{ variable }} in a playbook, for each of the entries that are processed.

I've read the pages on ansible variables, but didn't find anything that was a simple as what I'm looking for.

Can somebody point me appropriately?

Thanks,

Ed Greenberg


Brian Coca

unread,
Dec 21, 2015, 9:25:17 PM12/21/15
to Ansible Project
inventory_hostname has the name of the current host, so :

- hosts: servers
tasks:
- debug: var=inventory_hostname

should do what you want.



--
Brian Coca
Reply all
Reply to author
Forward
0 new messages