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:

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

}

On Friday, November 13, 2015 at 4:39:15 PM UTC-6, Stuart Cracraft wrote:
>
> 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:
>
> ---
>
> # tasks file for host
>
>
> - name: Add the OS specific variables
>
>   include_vars: "{{ ansible_os_family }}.yml"
>
>
> - name: Install /etc/hosts
>
>   template: >
>
>     src=hosts.j2
>
>     dest=/etc/hosts
>
>     owner=root
>
>     group=root
>
>     mode=0644
>
>   register: filechanged
>
>   tags: hosts
>
>
> - name: Install /etc/hostname
>
>   template: >
>
>     src=hostname.j2
>
>     dest=/etc/hostname
>
>     owner=root
>
>     group=root
>
>     mode=0644
>
>   register: filechanged
>
>   tags: hostname
>
>
> - name: Install /etc/network/interfaces
>
>   template: >
>
>     src=interfaces.j2
>
>     dest=/etc/network/interfaces
>
>     owner=root
>
>     group=root
>
>     mode=0644
>
>   register: filechanged
>
>   tags: interfaces
>
>
> - name: Run hostname
>
>   command: /bin/hostname {{ hostalias }}
>
>   when: filechanged|success
>
>   tags: hostname-run
>
>
> - name: Restart networking
>
>   service: name=networking state=restarted
>
>   when: filechanged|success
>
>   tags: network
>
>
> which produces this even though nothing is changed:
>
>
> ansible-playbook host.yml --check --ask-sudo-pass
>
>
> PLAY [testers] 
> ****************************************************************
>
>
> GATHERING FACTS 
> ***************************************************************
>
> ok: [tstsmc1]
>
>
> TASK: [host | Add the OS specific variables] 
> ********************************** 
>
> ok: [tstsmc1]
>
>
> TASK: [host | Install /etc/hosts] 
> ********************************************* 
>
> ok: [tstsmc1]
>
>
> TASK: [host | Install /etc/hostname] 
> ****************************************** 
>
> ok: [tstsmc1]
>
>
> TASK: [host | Install /etc/network/interfaces] 
> ******************************** 
>
> ok: [tstsmc1]
>
>
> TASK: [host | Run hostname] 
> *************************************************** 
>
> skipping: [tstsmc1]
>
>
> TASK: [host | Restart networking] 
> ********************************************* 
>
> changed: [tstsmc1]
>
>
> PLAY RECAP 
> ********************************************************************
>
> tstsmc1                    : ok=6    changed=1    unreachable=0    failed=0
>
>
> My concern is why the restart networking would be run given that 
> filechanged is not asserted
>
> by the first four tasks (nor any of the tasks.)
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/05bea62d-5028-4225-a391-a13247679f8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to