Skip to content

Instantly share code, notes, and snippets.

@halberom
Created September 27, 2018 14:32
Show Gist options
  • Save halberom/cf1b24e5571756588baf2dbdf5979dce to your computer and use it in GitHub Desktop.
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
---
- 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