如何根据条件打破 with_items 循环 [英] How can I break the with_items loop based on a condition

查看:25
本文介绍了如何根据条件打破 with_items 循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据条件跳出 with_items 循环.参数的条件是命令的标准输出是否等于特定字符串.

I want to break out of the with_items loop based on a condition. That condition for arguments sake is if the stdout of a command is equal to a particular string.

显然下面的例子不起作用,但这是我想要做的一个想法.

Obviously the example below does not work but this is an idea of what I want to do.

例如:

- 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.

推荐答案

目前这似乎不可能,因为您可以看到 此处.存在未经测试的hack.

This seems not possible at the moment as you can see here. There exists an untested hack out there.

这篇关于如何根据条件打破 with_items 循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆