Hi I have run into an issue where I’m not sure if it’s a bug in Ansible or just my lack of understand how roles are activated. Using Ansible 1.7.2, I have a playbook defined as such:
app/site.yml
app/roles/core/tasks/main.yml
app/roles/app-common/tasks/main.yml
app/roles/app-compA/meta/main.yml → contains a dependency on app-common
app/roles/app-compA/tasks/main.yml
app/roles/app-compB/meta/main.yml → contains a dependency on app-common
app/roles/app-compB/tasks/main.yml
Where site.yml activates roles like such:
- hosts: all
vars:
home: /usr/local/app
release: “{{ lookup(‘env’,‘RELEASE’) }}”
group: “{{ lookup(‘env’,‘GROUP’) }}”
roles:
- core
Component Specific Stuff
-
{ role: app-compA, when: group== ‘compA’ }
-
{ role: app-compB, when: group== ‘compB’ }
When I run the playbook like so:
export GROUP=compA
ansible-playbook site.yml -c local
The roles core, app-common & app-compA execute like expected.
However when I run the playbook like so:
export GROUP=compB
ansible-playbook site.yml -c local
Only the roles core and app-compB are executed and the app-common role is not executed. Shouldn’t the app-common role also be executed in this case? Is this a bug or have I mis-understood how roles are executed when role dependencies exists? My intent was to minimize the duplication of the tasks defined in app-common that are required by the app-compA & app-compB roles, so if there is another way to do this I’m all ears.
Thanks