How to get IP address from inventory file

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

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 ,
see if that makes it any clearer.

Hi,

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

Answere is also in this post

Problem to close.

Thanks :slight_smile:

Br,
Mateusz

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