It depends on the context. if you want to private_ip over the private_ip variable in the task, you can do it like this:
- hosts: all tasks: - name: Print private_ips debug: var={{ hostvars[item]['private_ip'] }} with_items: - "{{ groups['webservers'] }}"
Please note that this will print the IP addresses 3 times, as they will run on each server, so depending on what you are trying to achieve, you need to install hosts: all on your external server or something else.
You can also do this in a Jinja2 file if you plan to generate some configuration file. Again, it all depends on what you are striving for.
Please note that you can access IP information in facts collected automatically by:
$ ansible someserver -m setup .... "ansible_eth1": { "active": true, "device": "eth1", "ipv4": { "address": "192.168.252.6", "netmask": "255.255.255.255", "network": "192.168.252.6" }, "mtu": 1500, "promisc": false }, ....
which may also be more appropriate, depending on what you are trying to do.
Good luck.
source share