# variable for server as entered in inventory

**URL:** <https://forum.ansible.com/t/variable-for-server-as-entered-in-inventory/20059>\
**Category:** Ansible Project\
**Created:** [December 22, 2015, 2:13am UTC](https://forum.ansible.com/t/variable-for-server-as-entered-in-inventory/20059 "2015-12-22T02:13:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ed\_Greenberg](https://avatars.discourse-cdn.com/v4/letter/e/7ab992/32.png) [@Ed\_Greenberg](https://forum.ansible.com/u/Ed_Greenberg)\
**Post date:** [December 22, 2015, 2:13am UTC](https://forum.ansible.com/t/variable-for-server-as-entered-in-inventory/20059/1 "2015-12-22T02:13:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 22, 2015, 2:25am UTC](https://forum.ansible.com/t/variable-for-server-as-entered-in-inventory/20059/2 "2015-12-22T02:25:12Z")

</div>

inventory\_hostname has the name of the current host, so :

- hosts: servers  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- debug: var=inventory\_hostname

should do what you want.
