# run task in a sorted manner

**URL:** <https://forum.ansible.com/t/run-task-in-a-sorted-manner/32243>\
**Category:** Ansible Project\
**Created:** [February 15, 2020, 7:57pm UTC](https://forum.ansible.com/t/run-task-in-a-sorted-manner/32243 "2020-02-15T19:57:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandkan](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@sandkan](https://forum.ansible.com/u/sandkan)\
**Post date:** [February 15, 2020, 7:57pm UTC](https://forum.ansible.com/t/run-task-in-a-sorted-manner/32243/1 "2020-02-15T19:57:32Z")

</div>

Playbook is running task on wrong node: I have two nodes and this task has to run on a specific one and not the other, as well as only running once.  
I have tried adding a sort() like this: {{ansible\_play\_batch | join(’ ') | sort()}}.  
I’m not even sure why I need to add spaces after ansible\_play\_batch.

This is the command I am trying to translate to ansible. It is wrongly running the command pn server “pcmk-2” instead of “pcmk-1”.  
Command: pcs cluster setup --name mycluster pcmk-1 pcmk-2

My Ansible:

- name: Setup message bus  
run\_once: true  
command: \>  
pcs cluster setup --name {{ cluster\_name | quote }}  
{{ ansible\_play\_batch | join(’ ') }}

---

<div class="post-metadata">

**Author:** ![Nicholas\_Irving](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@Nicholas\_Irving](https://forum.ansible.com/u/Nicholas_Irving)\
**Post date:** [February 16, 2020, 5:59am UTC](https://forum.ansible.com/t/run-task-in-a-sorted-manner/32243/2 "2020-02-16T05:59:37Z")

</div>

Try just using {{ ansible\_hostname }} it should give you the details you want.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [February 16, 2020, 7:17am UTC](https://forum.ansible.com/t/run-task-in-a-sorted-manner/32243/3 "2020-02-16T07:17:17Z")

</div>

You only posted a single task.  
Please post your entire playbook.

Also explain what your command should look like (it’s not clear what you posted is correct or not).

---

<div class="post-metadata">

**Author:** ![soumya\_dutta](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@soumya\_dutta](https://forum.ansible.com/u/soumya_dutta)\
**Post date:** [February 16, 2020, 12:35pm UTC](https://forum.ansible.com/t/run-task-in-a-sorted-manner/32243/4 "2020-02-16T12:35:16Z")

</div>

Add below parameters and try if that works for you.

delegate\_to: nodename/nodeip  
run\_once: true

Cheers,  
Soumya
