Multiple plays in the same playbook resolve group variables incorrectly

Source code: https://github.com/behrangsa/sample-ansible-role

Background:

I have three different environments: test, staging, and prod and 3 applications that I deploy to them.

In staging and prod, each application have a dedicated server. In test, they all will be deployed to the same box.

The test inventory looks like this:

.
├── group_vars
│ ├── accounting.yml
│ ├── all.yml
│ ├── payroll.yml
│ └── timesheets.yml
└── hosts

The contents of these files are shown here:

hosts

[timesheets]
test.vagrant.local

[payroll]
test.vagrant.local

[accounting]
test.vagrant.local

all.yml

Turned out this was expected behavior. From the docs:

It is ok to put systems in more than one group, for instance a server could be both a webserver and a dbserver. If you do, note that variables will come from all of the groups they are a member of.

In the meantime, I have worked around it by using play vars/var_files. For example: