# ansible and dependencies

**URL:** <https://forum.ansible.com/t/ansible-and-dependencies/19763>\
**Category:** Ansible Project\
**Created:** [November 13, 2015, 10:21pm UTC](https://forum.ansible.com/t/ansible-and-dependencies/19763 "2015-11-13T22:21:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stuart\_Cracraft](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Stuart\_Cracraft](https://forum.ansible.com/u/Stuart_Cracraft)\
**Post date:** [November 13, 2015, 10:21pm UTC](https://forum.ansible.com/t/ansible-and-dependencies/19763/1 "2015-11-13T22:21:07Z")

</div>

Hi - trying to ensure I can make tasks dependent on prior task successes in roles inside playbooks.

So far it doesn’t happen. I’m using a combination of register/when.

What is the method within a series of tasks in a role’s tasks/main.yml to make one dependent upon the prior one’s running as success?

This only partially works:

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 13, 2015, 11:54pm UTC](https://forum.ansible.com/t/ansible-and-dependencies/19763/2 "2015-11-13T23:54:39Z")

</div>

you are using the same registered var in several tasks, the last one  
will overwrite the previous ones, you might want to create a diff var  
per task and then have a aggregated one.

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [November 13, 2015, 11:54pm UTC](https://forum.ansible.com/t/ansible-and-dependencies/19763/3 "2015-11-13T23:54:43Z")

</div>

I’m not sure I understand what you are asking for…by design, a playbook (and therefore a role) will stop processing if any task fails. So, it is implicit that the next task won’t happen unless the previous one succeeds.

Also, it looks like you are trying to change the hostname…is that correct? There is a hostname module that performs many of these steps.

Is there a reason you wouldn’t use notify to trigger the network service restart, and call it as a handler?

For example, [from Ansible docs](http://docs.ansible.com/ansible/playbooks_intro.html):

{

Here’s an example of restarting two services when the contents of a file change, but only if the file changes:

```auto
- name: template configuration file
  template: src=template.j2 dest=/etc/foo.conf
  notify:
     - restart memcached
     - restart apache

```

}
