I have filled an issue on the ansible repository but I would like to confirm that it is really a bug and that I am not doing anything wrong. https://github.com/ansible/ansible/issues/14945
It seems that a variable defined in a group_vars is not reloaded when the host group change in the playbook.
This is my playbook using ansible 2.0.1.0
├── inventory
│ └── dev
│ ├── group_vars
│ │ ├── all
│ │ ├── backend
│ │ └── backoffice
│ └── hosts
├── playbook.yml
└── roles
└── deploy
└── tasks
└── main.yml
The inventory in host :
[shop]
weenect.dev ansible_user=vagrant
[backend]
weenect.dev ansible_user=vagrant
[backoffice]
weenect.dev ansible_user=vagrant
The tasks in the deploy role executed for each host group :
---
- debug: msg="{{ deploy_source_folder }}"
And the value of this variable :
Content of inventory/dev/group_vars/all :
---
deploy_source_folder: "default"
Content of inventory/dev/group_vars/backend :
---
deploy_source_folder: "backend"
Content of inventory/dev/group_vars/backoffice :
---
deploy_source_folder: "backoffice"
When executing my playbook, the expected result would be :
Debug of deploy_source_folder for backend : "backend"
Debug of deploy_source_folder for backoffice : "backoffice"
Debug of deploy_source_folder for shop : "default"
But instead I have :
Debug of deploy_source_folder for backend : "backend"
Debug of deploy_source_folder for backoffice : "backend"
Debug of deploy_source_folder for shop : "backend"