# How can I use the ip in a playbook when inventory has ansible\_host

**URL:** <https://forum.ansible.com/t/how-can-i-use-the-ip-in-a-playbook-when-inventory-has-ansible-host/32740>\
**Category:** Ansible Project\
**Created:** [April 21, 2020, 1:11am UTC](https://forum.ansible.com/t/how-can-i-use-the-ip-in-a-playbook-when-inventory-has-ansible-host/32740 "2020-04-21T01:11:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott\_Fella](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@Scott\_Fella](https://forum.ansible.com/u/Scott_Fella)\
**Post date:** [April 21, 2020, 1:11am UTC](https://forum.ansible.com/t/how-can-i-use-the-ip-in-a-playbook-when-inventory-has-ansible-host/32740/1 "2020-04-21T01:11:02Z")

</div>

Currently trying to see if there is a way I can grab the ip defined in the ansible\_host and use that in a playbook. I know there is inventory\_hostaname, but these for example are not in dns.

hosts inventory example:

[aireos]  
wlc2504-01 ansible\_host=10.10.201.24  
wlc2504-02 ansible\_host=10.10.201.25  
wlc5520-01 ansible\_host=10.11.201.24  
wlc5520-02 ansible\_host=10.11.201.25

Here is a sample of a playbook which works if the device is registered in dns but fails of course when not. Is there any way I can extract the ip address so I can loop through all devices in the inventory group?

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [April 21, 2020, 4:47am UTC](https://forum.ansible.com/t/how-can-i-use-the-ip-in-a-playbook-when-inventory-has-ansible-host/32740/2 "2020-04-21T04:47:55Z")

</div>

Try ‘ansible\_host’

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [April 21, 2020, 4:49am UTC](https://forum.ansible.com/t/how-can-i-use-the-ip-in-a-playbook-when-inventory-has-ansible-host/32740/3 "2020-04-21T04:49:10Z")

</div>

From:  
[https://docs.ansible.com/ansible/latest/reference\_appendices/special\_variables.html](https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html)

---

<div class="post-metadata">

**Author:** ![Scott\_Fella](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@Scott\_Fella](https://forum.ansible.com/u/Scott_Fella)\
**Post date:** [April 21, 2020, 4:55am UTC](https://forum.ansible.com/t/how-can-i-use-the-ip-in-a-playbook-when-inventory-has-ansible-host/32740/4 "2020-04-21T04:55:08Z")

</div>

Thank you very much! I can’t believe that I didn’t scroll down that page far enough, basically was looking at the magic variables.

-Scott

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [April 21, 2020, 5:01am UTC](https://forum.ansible.com/t/how-can-i-use-the-ip-in-a-playbook-when-inventory-has-ansible-host/32740/5 "2020-04-21T05:01:32Z")

</div>

> Thank you very much! I can't believe that I didn't scroll down that page far enough, basically was looking at the magic  
> variables.
> 
> -Scott

Hello Scott,

in fact ansible\_host is a special variable, but any variable you stick on the host line will be available as  
variable later.

[aireos]  
wlc2504-01 ansible\_host=10.10.201.24 myvar=foo

Can be used as {{ myvar }}.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Scott\_Fella](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@Scott\_Fella](https://forum.ansible.com/u/Scott_Fella)\
**Post date:** [April 21, 2020, 5:09am UTC](https://forum.ansible.com/t/how-can-i-use-the-ip-in-a-playbook-when-inventory-has-ansible-host/32740/6 "2020-04-21T05:09:40Z")

</div>

Thanks for that info also. I will play around with that in the inventory or in the host\_vars. That gives me more options I can use during a play.

-Scott
