Strategies for testing if network range available

16 views
Skip to first unread message

Josef Fortier

unread,
Jul 12, 2017, 5:54:40 PM7/12/17
to Ansible Project
My goal is to fail early and warn if storage network not set up (and set up mounts if it is set up).

I've an approach that seems to work OK, but was wondering if there is a preferred/better path

set_fact: 
  has_storage_lan:  '{{ ansible_all_ipv4_addresses|join()|match("10.0.20.") }}'

This amounts to flattening the IP address array and converting to string values to then match on leading network range.

Is there a better way?

(thanks)

Dick Visser

unread,
Jul 13, 2017, 6:55:29 AM7/13/17
to ansible...@googlegroups.com
On 12 July 2017 at 23:54, Josef Fortier <josef....@gmail.com> wrote:

> Is there a better way?

Yes, use the dedicated 'ipaddr' filter:

- set_fact:
has_storage_lan: "{{ ansible_all_ipv4_addresses |
ipaddr('10.0.20.0/24') }}"

http://docs.ansible.com/ansible/playbooks_filters_ipaddr.html#getting-information-about-hosts-and-networks

--
Dick Visser
Sr. System & Network Engineer
GÉANT

Want to join us? We're hiring: https://www.geant.org/jobs
Reply all
Reply to author
Forward
0 new messages