# Ansible Role dependencies After Role

**URL:** <https://forum.ansible.com/t/ansible-role-dependencies-after-role/20436>\
**Category:** Ansible Project\
**Created:** [February 3, 2016, 12:25pm UTC](https://forum.ansible.com/t/ansible-role-dependencies-after-role/20436 "2016-02-03T12:25:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![profhase85](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@profhase85](https://forum.ansible.com/u/profhase85)\
**Post date:** [February 3, 2016, 12:25pm UTC](https://forum.ansible.com/t/ansible-role-dependencies-after-role/20436/1 "2016-02-03T12:25:35Z")

</div>

Hello,

how do I declare a role dependency which is executed after the role, e.g. :

After every execution of role A, role B is executed

According to this ons:

[http://docs.ansible.com/ansible/playbooks\_roles.html#roles](http://docs.ansible.com/ansible/playbooks_roles.html#roles)

the roles in ‘dependencies’ are executed before.

The Background:  
My Role A starts an installer that always overrides the certificates. I also got a certificate deployment role Role B which should always be called after role A.

---

<div class="post-metadata">

**Author:** ![profhase85](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@profhase85](https://forum.ansible.com/u/profhase85)\
**Post date:** [February 17, 2016, 10:14am UTC](https://forum.ansible.com/t/ansible-role-dependencies-after-role/20436/2 "2016-02-17T10:14:54Z")

</div>

As there seems to be no way to do this, would it be a feature request?

---

<div class="post-metadata">

**Author:** ![alexey.vazhnov](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@alexey.vazhnov](https://forum.ansible.com/u/alexey.vazhnov)\
**Post date:** [February 17, 2016, 12:38pm UTC](https://forum.ansible.com/t/ansible-role-dependencies-after-role/20436/3 "2016-02-17T12:38:45Z")

</div>

Ansible tasks and roles must be idempotent. If your role can override something, I think it’s the wrong way.

---

<div class="post-metadata">

**Author:** ![alexey.vazhnov](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@alexey.vazhnov](https://forum.ansible.com/u/alexey.vazhnov)\
**Post date:** [February 17, 2016, 12:40pm UTC](https://forum.ansible.com/t/ansible-role-dependencies-after-role/20436/4 "2016-02-17T12:40:34Z")

</div>

May be the better way for you is make one playbook for non-idempotent installer role and one for idempotent configuring.

---

<div class="post-metadata">

**Author:** ![profhase85](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@profhase85](https://forum.ansible.com/u/profhase85)\
**Post date:** [February 18, 2016, 10:21am UTC](https://forum.ansible.com/t/ansible-role-dependencies-after-role/20436/5 "2016-02-18T10:21:56Z")

</div>

Actually everything is idempotent:

The role I consider does upgrade java to a certain release. Of course the cacarts file gets overridden (since some certs might have been revoked etc.).  
After each call of this role I need my company certificates to be reincluded into the new cacerts file.

Of course I could simply paste the tasks into this role. Unfortunately, there are some other roles (for e.g. patching some software) which also override the cacerts file.  
In this case I will have redundand code in multiple roles.

---

<div class="post-metadata">

**Author:** ![Bourgeois\_Ghislain\_6](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bourgeois\_Ghislain\_6](https://forum.ansible.com/u/Bourgeois_Ghislain_6)\
**Post date:** [February 18, 2016, 2:01pm UTC](https://forum.ansible.com/t/ansible-role-dependencies-after-role/20436/6 "2016-02-18T14:01:37Z")

</div>

This looks to me like a use case for handlers, but instead of the handler being in a single role, it would apply after many roles. I am not sure this is feasible yet, but would be interested in finding out the solution.

I would have to test, but I think something like this might work:

Role our-cacerts - Containing handler to replace ca-certs if they were changed  
Role java - depending on our-cacerts and notifying the handler  
Role x - depending on our-cacerts and notifying the handler

I will try to test this today, as we have a use case that would also be solved by this.

Regards,

Ghislain

---

<div class="post-metadata">

**Author:** ![profhase85](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@profhase85](https://forum.ansible.com/u/profhase85)\
**Post date:** [February 20, 2016, 11:54am UTC](https://forum.ansible.com/t/ansible-role-dependencies-after-role/20436/7 "2016-02-20T11:54:06Z")

</div>

Merci Ghislain, I ve tried it and it works as you described it, here my files:

`  
├── main.yml  
├── role\_a  
│ ├── meta  
│ │ └── main.yml  
│ └── tasks  
│ └── main.yml  
└── role\_handler  
├── handlers  
│ ├── do\_certs.yml  
│ └── main.yml  
└── tasks  
├── do\_certs.yml  
└── main.yml

`

`

# role\_a/tasks/main.yml

- debug:  
msg=“Starting Role a”

- command: /bin/false  
failed\_when: False  
changed\_when: True  
notify:

- do certs

`

`

# role\_handler/handlers/main.yml

- name: do certs  
include: do\_certs.yml

`

`

# role\_handler/ **tasks** /do\_certs.yml

- name: copy certs  
debug:  
msg=“Copy Certs”

- name: insert certs  
debug:  
msg=“{{ item }}”  
with\_items:

- cert1

- cert2

` `

# main.yml

- hosts: localhost  
connection: local  
roles:
- role\_a

`

Yields
