0

Team, I have below output from my task. how can i print it nicely as it shows when i directly get it from linux terminal.

My task is below that runs ssh command on all hosts and lists output for each host separately but i want to pretty print it like sample output i listed below..

TASK

      - name: "List out PROC Stats Nodes"
        shell: ssh -F {{ ssh_cfg_path.stdout }} {{ item.node_name }}.{{ ssh_host }} "cat /proc/fs/fscache/stats"
        ignore_errors: no
        register: proc_stats
        failed_when: proc_stats.rc != 0
        with_items: "{{ gpu_nodes }}"

      - name: proc_stats results loop over all hosts output/result
        debug:
          msg: "{{ item.stdout }}"
        with_items: "{{ proc_stats.results }}"
        loop_control:
          label: "{{ item.item.node_name }}"

output:

 ok: [localhost] => (item=hostA) => {
      "msg": "FS-Cache statistics(ver:1.0)\nCookies: idx=600 dat=519 spc=0\nObjects: alc=0 nal=0 avl=0 ded=2\nChkAux : non=0 ok=0 upd=0 obs=0\nPages  : mrk=0 unc=0\nAcquire: n=1119 nul=0 noc=0 ok=1119 nbf=0 oom=0\nLookups: n=0 neg=0 pos=0 crt=0 tmo=0\nInvals : n=0 run=0\nUpdates: n=0 nul=0 run=0\nRelinqs: n=1119 nul=0 wcr=0 rtr=0\nAttrChg: n=0 ok=0 nbf=0 oom=0 run=0\nAllocs : n=0 ok=0 wt=0 nbf=0 int=0\nAllocs : ops=0 owt=0 abt=0\nRetrvls: n=519 ok=0 wt=0 nod=0 nbf=519 int=0 oom=0\nRetrvls: ops=0 owt=0 abt=0\nStores : n=0 ok=0 agn=0 nbf=0 oom=0 wrxd=0 sol=0\nStores : ops=0 run=0 pgs=0 rxd=0 irxd=0 olm=0 ipp=0\nVmScan : nos=0 gon=0 bsy=0 can=0 wt=0\nOps    : pend=0 run=0 enq=0 can=0 rej=0\nOps    : ini=0 dfr=0 rel=0 gc=0\nCacheOp: alo=0 luo=0 luc=0 gro=0\nCacheOp: inv=0 upo=0 dro=0 pto=0 atc=0 syn=0\nCacheOp: rap=0 ras=0 alp=0 als=0 wrp=0 ucp=0 dsp=0\nCacheEv: nsp=0 stl=0 rtr=0 cul=0"
  }

expected output:

cat /proc/fs/fscache/stats
FS-Cache statistics(ver:1.0)
Cookies: idx=600 dat=519 spc=0
Objects: alc=0 nal=0 avl=0 ded=2
ChkAux : non=0 ok=0 upd=0 obs=0
Pages  : mrk=0 unc=0
Acquire: n=1119 nul=0 noc=0 ok=1119 nbf=0 oom=0
Lookups: n=0 neg=0 pos=0 crt=0 tmo=0
Invals : n=0 run=0
Updates: n=0 nul=0 run=0
Relinqs: n=1119 nul=0 wcr=0 rtr=0
AttrChg: n=0 ok=0 nbf=0 oom=0 run=0
Allocs : n=0 ok=0 wt=0 nbf=0 int=0
Allocs : ops=0 owt=0 abt=0
Retrvls: n=519 ok=0 wt=0 nod=0 nbf=519 int=0 oom=0
Retrvls: ops=0 owt=0 abt=0
Stores : n=0 ok=0 agn=0 nbf=0 oom=0 wrxd=0 sol=0
Stores : ops=0 run=0 pgs=0 rxd=0 irxd=0 olm=0 ipp=0
VmScan : nos=0 gon=0 bsy=0 can=0 wt=0
Ops    : pend=0 run=0 enq=0 can=0 rej=0
Ops    : ini=0 dfr=0 rel=0 gc=0
CacheOp: alo=0 luo=0 luc=0 gro=0
CacheOp: inv=0 upo=0 dro=0 pto=0 atc=0 syn=0
CacheOp: rap=0 ras=0 alp=0 als=0 wrp=0 ucp=0 dsp=0
CacheEv: nsp=0 stl=0 rtr=0 cul=0
AhmFM
  • 1,552
  • 3
  • 23
  • 53

1 Answers1

1

Try split function.

 msg: "{{ item.stdout.split('\n') }}"

Just that there'll be an extra , at the end of every line.

Abhishek
  • 45
  • 1
  • 6