# Question about partial matching in Ansible 2.2

**URL:** <https://forum.ansible.com/t/question-about-partial-matching-in-ansible-2-2/25875>\
**Category:** Ansible Project\
**Created:** [October 31, 2017, 3:26pm UTC](https://forum.ansible.com/t/question-about-partial-matching-in-ansible-2-2/25875 "2017-10-31T15:26:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Dave](https://forum.ansible.com/u/Dave)\
**Post date:** [October 31, 2017, 3:26pm UTC](https://forum.ansible.com/t/question-about-partial-matching-in-ansible-2-2/25875/1 "2017-10-31T15:26:05Z")

</div>

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](http://docs.ansible.com/ansible/latest/playbooks_tests.html) but that didn’t seem to work either. Any ideas?

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [November 4, 2017, 1:12am UTC](https://forum.ansible.com/t/question-about-partial-matching-in-ansible-2-2/25875/2 "2017-11-04T01:12:48Z")

</div>

Don't do string manipulation on IP addresses - use the dedicated  
ipaddr filter instead:

[http://docs.ansible.com/ansible/latest/playbooks\_filters\_ipaddr.html](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')
