寄存器变量索引结果的可见循环

问题描述 投票:0回答:1

Team,

我有一个任务,可以在组中的所有主机上运行命令。

现在,对于每台主机,当输出不包含特定字符串时,我需要执行一次fail__。我如何从所有主机的角色任务中实现这一目标,因为。下面只能在[0]上执行,但是如何在所有索引上循环并在每个主机输出中检查字符串?

      - name: "Assure fscache proc stats"
        command: cat "{{ proc_stats }}"
        register: stats
        delegate_to: "{{ item }}"
        with_items: "{{ groups['kube-gpu-node'] }}"
        failed_when: '"FS-Cache" not in stats.stdout'
      - debug:
          var: stats.results[0].stdout_lines
22:42:19  TASK [services-pre-install-checks : debug] ******************************
22:42:19  Thursday 07 November 2019  06:42:19 +0000 (0:00:03.675)       0:00:06.795 ***** 
22:42:19  [0;32mok: [localhost] => {[0m
22:42:19  [0;32m    "stats.results[0].stdout_lines": [[0m
22:42:19  [0;32m        "FS-Cache statistics(ver:1.0)", [0m
22:42:19  [0;32m        "Cookies: idx=613 dat=520 spc=0", [0m
22:42:19  [0;32m        "Objects: alc=3 nal=0 avl=3 ded=4", [0m
22:42:19  [0;32m        "ChkAux : non=0 ok=1 upd=0 obs=0", [0m
22:42:19  [0;32m        "Pages  : mrk=1 unc=1", [0m
22:42:19  [0;32m        "Acquire: n=1133 nul=0 noc=0 ok=1133 nbf=0 oom=0", [0m
22:42:19  [0;32m        "Lookups: n=3 neg=2 pos=1 crt=2 tmo=0", [0m
22:42:19  [0;32m        "Invals : n=0 run=0", [0m
22:42:19  [0;32m        "Updates: n=0 nul=0 run=0", [0m
22:42:19  [0;32m        "Relinqs: n=1133 nul=0 wcr=0 rtr=0", [0m
22:42:19  [0;32m        "AttrChg: n=0 ok=0 nbf=0 oom=0 run=0", [0m
22:42:19  [0;32m        "Allocs : n=0 ok=0 wt=0 nbf=0 int=0", [0m
22:42:19  [0;32m        "Allocs : ops=0 owt=0 abt=0", [0m
22:42:19  [0;32m        "Retrvls: n=520 ok=0 wt=1 nod=1 nbf=519 int=0 oom=0", [0m
22:42:19  [0;32m        "Retrvls: ops=1 owt=1 abt=0", [0m
22:42:19  [0;32m        "Stores : n=1 ok=1 agn=0 nbf=0 oom=0 wrxd=0 sol=0", [0m
22:42:19  [0;32m        "Stores : ops=1 run=2 pgs=1 rxd=1 irxd=0 olm=0 ipp=0", [0m
22:42:19  [0;32m        "VmScan : nos=0 gon=0 bsy=0 can=0 wt=0", [0m
22:42:19  [0;32m        "Ops    : pend=1 run=2 enq=2 can=0 rej=0", [0m
22:42:19  [0;32m        "Ops    : ini=2 dfr=0 rel=2 gc=0", [0m
22:42:19  [0;32m        "CacheOp: alo=0 luo=0 luc=0 gro=0", [0m
22:42:19  [0;32m        "CacheOp: inv=0 upo=0 dro=0 pto=0 atc=0 syn=0", [0m
22:42:19  [0;32m        "CacheOp: rap=0 ras=0 alp=0 als=0 wrp=0 ucp=0 dsp=0", [0m
22:42:19  [0;32m        "CacheEv: nsp=0 stl=0 rtr=0 cul=0"[0m
22:42:19  [0;32m    ][0m
22:42:19  [0;32m}[0m
ansible ansible-2.x ansible-inventory
1个回答
0
投票

想通了。但是有一个问题,我得到了很大的输出以及需要的消息。

  - name: Make sure FS-cache is present in loop on all cpu nodes
    assert:
      that:
        - item.stdout is search('FS-Cache')
      fail_msg: "FS-cache is absent"
      success_msg: "FS-cache is present"
    loop: "{{ stats.results }}"
© www.soinside.com 2019 - 2024. All rights reserved.