Created
September 27, 2018 14:32
-
-
Save halberom/cf1b24e5571756588baf2dbdf5979dce to your computer and use it in GitHub Desktop.
ansible - example of extracting all ipaddresses in the range 192.168.0.0/24 for hosts matching pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: "{{ pattern }}" | |
gather_facts: True | |
tasks: | |
- name: combine all ipv4 | |
set_fact: | |
all_ipv4: "{{ all_ipv4 + ansible_all_ipv4_addresses }}" | |
- name: reduce to matching ip's | |
set_fact: | |
matching_ipv4s: "{{ all_ipv4 | ipaddr('192.168.0.0/24') | unique }}" | |
- name: output | |
debug: | |
var: matching_ipv4s | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment