【发布时间】:2018-11-06 12:16:42
【问题描述】:
我想根据条件跳出 with_items 循环。参数的条件是命令的标准输出是否等于特定字符串。
显然下面的示例不起作用,但这是我想要做的一个想法。
例如:
- name: testing loop
shell: "echo {{ item }}"
with_items:
- "one"
- "two"
- "three"
register: shell_command # registering the shell command and it's attributes
when: shell_command.stdout == "two" # break once the stdout of the run shell command matches the string "two". So it will run twice and break on the second.
【问题讨论】:
-
欢迎来到 Stack Overflow!将来,您可能希望指定您的示例如何“不起作用”。您的问题很好,但我们收到很多问题的整个描述都是“它不起作用”,这往往会使审稿人对这些词产生偏见。
-
@Haem 明白了!谢谢
标签: ansible jinja2 ansible-2.x ansible-inventory ansible-template