Performance issue when loading all host group vars before starting playbook

Hi everyone,

We have a large ‘hosts’ file with many different host groups defined.
When running ansible-playbook command with ‘-i’ pointing to our hosts file, Ansible will then call our custom code in the VarsModule class of our vars plugin. Ansible calls the get_group_vars() function for each host group in the hosts file. As our hosts file contains a lot of host groups, this increases the time to load all of the vars from all of the host groups.
I tried to limit the host group by using the “–limit” parameter but this still results in Ansible triggering for all host groups.
Basically this results in about 7 seconds delay before Ansible starts the playbook. This can be costly since we run a lot of playbooks during our deployments.

Is there a better way to do this?

Thanks