# Running specific tasks depending on subnet

**URL:** <https://forum.ansible.com/t/running-specific-tasks-depending-on-subnet/30605>\
**Category:** Ansible Project\
**Created:** [June 19, 2019, 5:25pm UTC](https://forum.ansible.com/t/running-specific-tasks-depending-on-subnet/30605 "2019-06-19T17:25:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Bidwell](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Chris\_Bidwell](https://forum.ansible.com/u/Chris_Bidwell)\
**Post date:** [June 19, 2019, 5:25pm UTC](https://forum.ansible.com/t/running-specific-tasks-depending-on-subnet/30605/1 "2019-06-19T17:25:06Z")

</div>

Does anyone know how I can run a task based off the subnet I'm in?

For example,

We've got an internal network that needs to pull packages through yum, but  
within that subnet, we need to go through a proxy to get out.

So something like if my IP is 192.168.223.x to use this task

and if I'm 192.168.224.x to use this task instead?

Thanks

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 19, 2019, 6:02pm UTC](https://forum.ansible.com/t/running-specific-tasks-depending-on-subnet/30605/2 "2019-06-19T18:02:41Z")

</div>

This should work, match is regexp so need to escape the dot

when: ansible\_default\_ipv4.address is match('192\.168\.223\.')
