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/cb7cc93b-b68a-4103-8223-10cfc249d43f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to