Running specific tasks depending on subnet

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

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

when: ansible_default_ipv4.address is match('192\.168\.223\.')