Hi,

it is actually not possible on task level, Ansible is going thru them from
top to bottom. But there can be some possibilities how to do it:
  - (maybe) try to think about your own Execution strategy:
http://docs.ansible.com/ansible/playbooks_strategies.html but really do not
know, if it is possible by them
  - you can use handlers, defne not a tasks but handlers, than do:

- name: open the door then get mails, because mail box is inside the room
  debug: msg="calling handlers to do a job"
  changed_when: true
  notify:
    - "open the door"
    - "turn on the light"
    - "get mails from mailbox"

- meta: flush_handlers

Handlers are evaliuated from top to bottom too, so you can use different
sorting.

But, to be honest, it does not look like somethink that can be easilly done
in Ansible. Maybe try to describe your problem, what you try to solve (not
a solution you try to implement, but description of your problem in more
general way).

David
Linux server specialist/Specialista na správu linuxových serverů
www.karban.eu

2016-01-18 13:44 GMT+01:00 Wukang Lin <[email protected]>:

> Hi,
>    all. I have review some similar topic on task reusability of ansible
> role and task execute order. But i still cannot get an answer to my
> problem. here it is:
>    suppose i have a role named 'service_a', and I have write a set of
> tasks in 'service_a/tasks/tasks.yml', such like this:
>
>   # service_a/tasks/tasks.yml
>   - name: open the door
>     ....
>   - name: get mails from mailbox
>     ....
>   - name: turn on the light
>     ....
>
>   Now, I want to organize those actions in different orders, as below
> (just some fake code to explain my needs):
>
>   # service_a/tasks/main.yml
>   - name: get mails then open the door, because mail box is outside the
> room
>     tasks:
>         - "get mails from mailbox"
>         - "open the door"
>         - "turn on the light"
>         ...
>     tags: mailbox_outside_the_room
>
>   - name: open the door then get mails, because mail box is inside the room
>     tasks:
>         - "open the door"
>         - "turn on the light"
>         - "get mails from mailbox"
>         ...
>     tags: mailbox_inside_the_room
>
>    How to implements like this? Can any Help?
>
>
>
> --
> 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/cf8fb74d-da85-488f-ac20-f328ee9e5aa3%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/cf8fb74d-da85-488f-ac20-f328ee9e5aa3%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAOBFM95GnM0smevJefn1j2wJG3tT4NUrCpTSSa-v82_H8V%2B5QQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to