在Ansible中,如何检查值是否位于数组中的某个元素中?
我设置了一个最终具有此值的寄存器变量:在Ansible中,如何检查值是否位于数组中的某个元素中?,ansible,Ansible,我设置了一个最终具有此值的寄存器变量: 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.stea
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"
]
}
如何检查字符串的yum_Sec_upd.stdout_lines数组中是否存在字符串“Sec.”?我想这样做
- name: Send mail for security updates
mail: # mail parms here
when: "'Sec.' in yum_sec_upd.stdout_lines[]"
如果要注册命令的输出,只需使用
stdout
而不是stdout\u行
:
- 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
我还没有测试过这一点,但ansible使用python,这一点或其中的一些排列是否可行<代码>何时:yum_Sec_upd.stdout_行中的“Sec.”在l中代表l?遗憾的是,这不起作用。不过,我会记住这一点,这就是我现在使用的Python。我以为我会很聪明。