要搜索ansible shell任务的结果列表中的字符串,可以使用Ansible的过滤器来进行匹配和搜索。以下是一个示例代码:
---
- hosts: localhost
tasks:
- name: Run shell command
shell: "ls -l"
register: result
- name: Search string in result
debug:
msg: "{{ item }}"
loop: "{{ result.stdout_lines }}"
when: "'search_string' in item"
在上面的示例中,我们使用了shell
模块运行了一个命令,并将其结果保存在result
变量中。然后,我们使用debug
模块来循环遍历result.stdout_lines
,并使用when
条件来判断字符串是否存在于结果列表中。
你需要将shell
模块中的命令替换为你想要执行的命令,并将search_string
替换为你要搜索的字符串。
注意,在Ansible的结果列表中搜索字符串时,可能需要使用适当的正则表达式或字符串匹配技术来实现更复杂的搜索功能。