ansible - 每个循环变量的ansible显示输出
问题描述
团队,我的以下任务在组中的所有节点上运行,我需要显示循环中使用的每个节点的输出。任何提示?
command: cat "{{ proc_stats }}"
register: stats
delegate_to: "{{ item }}"
with_items: "{{ groups['kube-gpu-node'] }}"
failed_when: stats.stdout is not search('FS-Cache')
- debug:
var: stats.results[item.item].stdout_lines
with_items: "{{ groups['kube-gpu-node'] }}"
输出:
TASK [team-services-pre-install-checks : Assure fscache proc stats] *****************************************************************************************************
Thursday 05 December 2019 01:40:18 +0000 (0:00:00.172) 0:00:09.990 *****
changed: [localhost -> test.dumy.net] => (item=dgx0159)
TASK [maglev-services-pre-install-checks : debug] *************************************************************************************************************************
Thursday 05 December 2019 01:40:18 +0000 (0:00:00.174) 0:00:10.165 *****
ok: [localhost] => (item=dgx0159) => {
"ansible_loop_var": "item",
"item": "dgx0159",
"stats.results[item.item].stdout_lines": "VARIABLE IS NOT DEFINED!"
}
当我只使用结果中的索引为一个节点进行调试时,我得到了这个,但我想要所有节点,而不仅仅是一个如何?
- debug:
var: stats.results[0].stdout_lines
TASK [team-services-pre-install-checks : debug] *************************************************************************************************************************
Thursday 05 December 2019 01:44:58 +0000 (0:00:00.181) 0:00:11.573 *****
ok: [localhost] => (item=node1) => {
"ansible_loop_var": "item",
"item": "dgx0159",
"stats.results[0].stdout_lines": [
"FS-Cache statistics(ver:1.0)",
"Cookies: idx=55 dat=42 spc=0",
"Objects: alc=85 nal=0 avl=85 ded=86",
"ChkAux : non=0 ok=33 upd=0 obs=0",
"Pages : mrk=52929 unc=52929",
"Acquire: n=97 nul=0 noc=0 ok=97 nbf=0 oom=0",
"Lookups: n=85 neg=19 pos=66 crt=19 tmo=0",
"Invals : n=0 run=0",
"Updates: n=0 nul=0 run=0",
"Relinqs: n=97 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=312 ok=226 wt=20 nod=86 nbf=0 int=0 oom=0",
"Retrvls: ops=312 owt=8 abt=0",
"Stores : n=13229 ok=13229 agn=0 nbf=0 oom=0 wrxd=0 sol=0",
"Stores : ops=82 run=13311 pgs=13229 rxd=13229 irxd=0 olm=0 ipp=0",
"VmScan : nos=0 gon=0 bsy=0 can=0 wt=0",
"Ops : pend=8 run=394 enq=13311 can=0 rej=0",
"Ops : ini=13541 dfr=1 rel=13541 gc=1",
"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"
]
}
解决方案
您已经有一个列表status.results
,因此您可以对其进行迭代:
- debug:
var: item.stdout_lines
with_items: stats.results
或者从第一个任务中查看项目:
- debug:
msg: "result for {{ item.item }} is {{ item.stdout_lines }}"
with_items: stats.results
推荐阅读
- html - 获取文本部分到 xpath 中的特定标签
- excel - 使用 VBA 将超链接字段写入循环内的另一个工作表范围
- postgresql - 通过 @NamedStoredProcedureQuery 使用 Spring 数据 JPA 调用 postgres 函数时出错
- c++ - clang 格式 AlignAfterOpenBracket 列表参数
- flutter - 为什么我的 DropdownButtonFormField 不显示项目?
- java - 我想通过在 java 中显示多个 BankaccountNames 来显示员工姓名
- amazon-web-services - Amazon Redshift:查询在空闲期后永远不会完成运行
- keras - 二进制文本分类:为什么 LSTM 无法拟合,而 Dense net 拟合正常?
- oracle - 安装 Oracle ODAC 12.2.0.1 崩溃并在 W10 中完成
- flutter - Flutter Table Calendar (v.3.0.2) : 根据日期显示来自 REST API 的所有数据