【发布时间】:2019-07-05 08:26:40
【问题描述】:
我用 ansible 运行了一个 powershell 脚本并返回 stdout,如下所示。我想排除“名称”和“---”如何通过使用 regex_search 来实现?或任何其他可以达到相同目的的方法。任何想法将不胜感激:-)
"output.stdout_lines": [
"",
"name ",
"---- ",
"Microsoft Visual C++ 2017 x86 Additional Runtime - 14.12.25810 ",
"Microsoft Visual C++ 2017 x64 Additional Runtime - 14.12.25810 ",
"Microsoft Visual C++ 2017 x86 Minimum Runtime - 14.12.25810 ",
"Microsoft Visual C++ 2017 x64 Minimum Runtime - 14.12.25810 ",
"",
""
]
【问题讨论】:
-
为什么不从 powershell 命令中删除标头?试试
Get-WmiObject -Class Win32_Product | Select Name -ExpandProperty Name -
如果还想在 Ansible 中做,
when: '"name" not in output.stdout' and when: '"----" not in output.stdout' and when: '"" not in output.stdout' -
谢谢它的工作。这是另一种解决方法。