Determine which network a host is on

So I’ve got a playbook I’ve written where the config is different depending on the network it resides on.

How can I determine this and be able to save the network as a variable?

Did you get any chance to through setup module?

https://docs.ansible.com/ansible/latest/modules/setup_module.html

Synopsis- This module is automatically called by playbooks to gather useful variables about remote hosts that can be used in playbooks. It can also be executed directly by /usr/bin/ansible to check what variables are available to a host. Ansible provides many facts about the system, automatically.