Question:
I’ve tried something like this:
1 2 3 4 5 6 7 8 9 |
gather_facts: yes tasks: - debug: var=ansible_all_ipv4_addresses - set_fact: man_ip: "{{ item }}" with_items: ansible_all_ipv4_addresses when: "item.startswith('10.')" - debug: var=man_ip |
It works, but I have problem with servers where I use docker, ’cause docker containers also have interface adress started with 10.x.x.x
.
So, how can I get host private network address?
Answer:
You could use ansible_all_ip_addresses
fact and the ipaddr
filter.
1 2 |
{{ ansible_all_ipv4_addresses | ipaddr('private') | first }} |
Note: You can check what ansible facts you have available with ansible -m setup localhost
Edit: You can also filter by ip using ipaddr
1 2 |
{{ ansible_all_ipv4_addresses | ipaddr('10.0.0.0/8') | first }} |