Ansible using Having same host in multiple groups but while running playbooy even after specifying groupname its taking another groups variable

ansibleansible-playbook

We have Apache setup chrooted, so we can multiple apache on single directory for multiple httpd instance. I have added all the different groups with the instance name in inventory but their hosts are same.

While I am running tasks on one httpd instance, it takes groups vars of different group even though the hosts are same in all groups.

Best Answer

This answer can help: Ansible same host on different groups with group_vars

Try overriding host variables each time it is required with "vars_files":

hosts: {{ group_name }}
vars_files:
 - group_vars/{{ group_name }}.yml
tasks: