ansible-playbook structure

Hi
I make a playbook with structure:

ansible-test/
├── playbook.yaml
└── staging
├── group_vars
│ ├── test1
│ └── test2
└── inventory

playbook.yaml:

  • hosts: test1
    gather_facts: false
    tasks:

    • debug: var={{ env_name }}
  • hosts: test2
    gather_facts: false
    tasks:

    • debug: var={{ env_name }}

staging:
[test1]
127.0.0.1
[test2]
127.0.0.1

test1
env_name: test1
test2
env_name: test2

The result:
PLAY [test1] ******************************************************************

TASK: [debug var={{env_name}}] ************************************************
ok: [127.0.0.1] => {
“test2”: “{{ test2 }}”
}

PLAY [test2] ******************************************************************

TASK: [debug var={{env_name}}] ************************************************
ok: [127.0.0.1] => {
“test2”: “{{ test2 }}”
}

PLAY RECAP ********************************************************************
127.0.0.1 : ok=2 changed=0 unreachable=0 failed=0

When ansible access test1 host, It load test2 in group_vars.
But I think It should load test1 in group_vars. I posted this problem here

https://github.com/ansible/ansible/issues/10370

However, I still don’t understand .

Please help me deal with this problem.

Thank you in advance

Thanks and Regards,

Khoa Nguyen