Question about partial matching in Ansible 2.2

7 views
Skip to first unread message

Dave

unread,
Oct 31, 2017, 11:26:05 AM10/31/17
to Ansible Project
Is it possible to test for conditions based on partial matches? I'm trying to test for variables that match a specific /24 range and I have the following so far:

 - name: If the IP address is destined for the .1 subnet...

     
when: set_machinename | match("192.168.1.")

I tried a wildcard as shown here but that didn't seem to work either. Any ideas?

Dick Visser

unread,
Nov 3, 2017, 9:13:25 PM11/3/17
to ansible...@googlegroups.com
Don't do string manipulation on IP addresses - use the dedicated
ipaddr filter instead:

http://docs.ansible.com/ansible/latest/playbooks_filters_ipaddr.html


Your 'when' construct would look like:

when: set_machinename | ipaddr('192.168.1.0/24')



--
Dick Visser
GÉANT

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