How can I use the ip in a playbook when inventory has ansible_host

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?

Try ‘ansible_host’

From:
https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html

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

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
       Racke

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