# is there any order by clause for hosts to execute task in  certain order

**URL:** <https://forum.ansible.com/t/is-there-any-order-by-clause-for-hosts-to-execute-task-in-certain-order/38217>\
**Category:** Ansible Project\
**Created:** [July 12, 2023, 2:54pm UTC](https://forum.ansible.com/t/is-there-any-order-by-clause-for-hosts-to-execute-task-in-certain-order/38217 "2023-07-12T14:54:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [July 12, 2023, 2:54pm UTC](https://forum.ansible.com/t/is-there-any-order-by-clause-for-hosts-to-execute-task-in-certain-order/38217/1 "2023-07-12T14:54:10Z")

</div>

Hello Team,

We have a situation where we have to run same script on all 3 machines but in specific order like first it should be run on follower and then on leader.

now to achieve this i have to repeat same task again with different condition. Can it be achieve in one ???

- name: Kill running java processes and start newly configured systemd

throttle: 1

# ignore\_errors: yes

any\_errors\_fatal: true

shell: ‘/bin/bash /tmp/zkcheck.sh’

register: zkstart

failed\_when: zkstart.rc != 0

when: not zkmode.stdout\_lines is search(‘leader’)

- name: As all followers are up now repeat kill running java cp and start for leader

any\_errors\_fatal: true

shell: ‘/bin/bash /tmp/zkcheck.sh’

register: zkstart

failed\_when: zkstart.rc != 0

when: zkmode.stdout\_lines is search(‘leader’)

---

<div class="post-metadata">

**Author:** ![mahespth](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mahespth/32/252_2.png) [@mahespth](https://forum.ansible.com/u/mahespth)\
**Post date:** [July 12, 2023, 3:42pm UTC](https://forum.ansible.com/t/is-there-any-order-by-clause-for-hosts-to-execute-task-in-certain-order/38217/2 "2023-07-12T15:42:25Z")

</div>

Hi,

This should help

[https://docs.ansible.com/ansible/latest/playbook\_guide/playbooks\_strategies.html#ordering-execution-based-on-inventory](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_strategies.html#ordering-execution-based-on-inventory)

Regards
