我设置了一个最终具有此值的寄存器变量:
ok: [10.xx.xx.xx] => {
"yum_sec_upd.stdout_lines": [
"Loaded plugins: fastestmirror",
"Loading mirror speeds from cached hostfile",
" * base: mirrors.usinternet.com",
" * epel: mirror.steadfast.net",
" * extras: mirror.lax.hugeserver.com",
" * updates: centos.mirrors.tds.net",
"CESA_2017__0086 Important/Sec. kernel-3.10.0-514.6.1.el7.x86_64",
"CESA_2017__0086 Important/Sec. kernel-tools-3.10.0-514.6.1.el7.x86_64",
"CESA_2017__0086 Important/Sec. kernel-tools-libs-3.10.0-514.6.1.el7.x86_64",
"CESA_2017__0086 Important/Sec. python-perf-3.10.0-514.6.1.el7.x86_64",
"updateinfo list done"
]
}
如何检查字符串" Sec。"是否存在于yum_sec_upd.stdout_lines字符串数组中?我想这样做
- name: Send mail for security updates
mail: # mail parms here
when: "'Sec.' in yum_sec_upd.stdout_lines[]"
答案 0 :(得分:2)
如果您要注册命令的输出,只需使用stdout
而不是stdout_lines
:
- name: Send mail for security updates
mail: # mail parms here
when: 'Sec.' in yum_sec_upd.stdout
要检查列表是否包含子字符串,您可以使用例如:
when: yum_sec_upd.stdout_lines | select('search', 'Sec.') | list | length > 0