# How to get IP address from inventory file

**URL:** <https://forum.ansible.com/t/how-to-get-ip-address-from-inventory-file/24402>\
**Category:** Ansible Project\
**Created:** [May 4, 2017, 9:15pm UTC](https://forum.ansible.com/t/how-to-get-ip-address-from-inventory-file/24402 "2017-05-04T21:15:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mateusz\_Panczyszyn](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Mateusz\_Panczyszyn](https://forum.ansible.com/u/Mateusz_Panczyszyn)\
**Post date:** [May 4, 2017, 9:15pm UTC](https://forum.ansible.com/t/how-to-get-ip-address-from-inventory-file/24402/1 "2017-05-04T21:15:23Z")

</div>

Hello,

I have no idea how to solve an IP address problem. I need some tips. I have an inventory file with defined hosts:

[clab111]  
11.11.11.11

[clab222]  
22.22.22.22

Then I will start working on one host, for example:

The path to the subtitles PLAYBOOK\_NAME.yml and inv -limit “clab111”

In the meantime, I will use in the playbook\_name.yml, lineinfile module, which should replace any IP address to address of the clab111. I have all the regex, but I do not know how to set the variable that will contain the IP address from the file inventory file for that particular clab111. I tried with hostvars, but without success.

So I need:

- get IP address of (for example) clab111 from inventory file,
- define variable with this clabxxx\_ip: {{ my\_problem }}
- put here: sed -r ‘s/([0-9]{1,3}.){3}[1-9]{1,3}’/{{ clabxxx\_ip }}/g

Thanks for the patience. I spent a ton of time on the “google” solution but without success, it’s my first steps in ansible.

Br,  
Mateusz

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [May 5, 2017, 6:45am UTC](https://forum.ansible.com/t/how-to-get-ip-address-from-inventory-file/24402/2 "2017-05-05T06:45:42Z")

</div>

Your inventory doesn't say what you think it does.

[clab111] is a group, not a host, and it contains one host called '11.11.11.11',  
and so on.

Inventory docs are at: [http://docs.ansible.com/ansible/intro\_inventory.html](http://docs.ansible.com/ansible/intro_inventory.html) ,  
see if that makes it any clearer.

---

<div class="post-metadata">

**Author:** ![Mateusz\_Panczyszyn](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Mateusz\_Panczyszyn](https://forum.ansible.com/u/Mateusz_Panczyszyn)\
**Post date:** [May 5, 2017, 8:06am UTC](https://forum.ansible.com/t/how-to-get-ip-address-from-inventory-file/24402/3 "2017-05-05T08:06:38Z")

</div>

Hi,

Ok I wrong understood idea of this file in first reading, I read too fast.

Answere is also in [this post](https://groups.google.com/d/msg/Ansible-project/gnKVupiWSIc/GRp7WoYVLwgJ)

Problem to close.

Thanks 🙂

Br,  
Mateusz

W dniu piątek, 5 maja 2017 08:45:48 UTC+2 użytkownik Dick Davies napisał:
