Run Command On Each Host

Hi Team,

I want to run multiple commands in shell module, but i want to run 1st command on each hosts than move to next command on each host than third and so on, so that i can get output of same command together from all host at single place, tried with loop (with_item)
but no luck, need help

Thanks
jitender

Hello,

ansible by default runs a task on all hosts and then waits for result
from everyone before going to the next step. If your task has a loop,
there's no way to run the loop synchronously between all nodes,
because is a single task with multiple options.

You can split the commands in several shell tasks, instead one with a loop.

Luca

Thanks for the update, i’'ll try using multiple shell tasks, also can you please let me know how to make ansible not to print commands only print output of command

Hello,

try this for printing command output. I don't know if you can hide the
other parts of output:

https://stackoverflow.com/a/24834231

Hi how can i access array in shell module trying to access as below but not getting any output

tasks:

  • name: verify that it shows the new cluster ID for this company in active list and old cluster in inactive list
    shell:
    spaceorg=echo "{{ commaorg }}"|sed 's/,/ /g'|for i in ${spaceorg[@]} ; do echo $i ; /sc/bin/smmgr -s cid=$i -s getsminfo=company_ssn 2>/dev/null|grep $i|grep -v Changing ; done
    args:
    executable: /bin/bash

Hi how can i access array in shell module trying to access as below but not getting any output

tasks:

\- name:  verify that it shows the new cluster ID for this company in active list and old cluster in inactive list
  shell:
    spaceorg=\`echo "\{\{ commaorg \}\}"|sed 's/,/ /g'\`|for i in $\{spaceorg\[@\]\} ; do echo $i ; /sc/bin/smmgr \-s cid=$i \-s

getsminfo=company_ssn 2>/dev/null|grep $i|grep -v Changing ; done
args:
executable: /bin/bash

Do yourself a favour and use a shell script on the target host.

You can either create it with copy or template module.

Your task above is hard to read and escaping all the special characters is a difficult and superfluous venture.

Regards
          Racke

Dont want ansible to print command as below only need output , is it possible ?

changed: [zsn-ams2-clr-1b2]

cmd: spaceorg=echo "25528960,28115152,28863788"|sed 's/,/ /g'

bin/smmgr -s nameid=smid2name >> /sc/build/smid2namePostOUTPUT-32145.txt

for i in ${spaceorg[@]}; do echo $i && grep -w $i /sc/build/smid2namePostOUTPUT-32145.txt | wc -l; done

Anything Guys any option here with i can hide command execute on target hosts

Maybe you can register a variable that captures the "cmd" output and
look at yourvariable.output afterwards?