ansible and dependencies

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:

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.

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:

{

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

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

}