run task in a sorted manner

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(’ ') }}

Try just using {{ ansible_hostname }} it should give you the details you want.

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).

Add below parameters and try if that works for you.

delegate_to: nodename/nodeip
run_once: true

Cheers,
Soumya