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

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

问题描述

我想根据条件摆脱with_items循环。出于参数考虑,该条件是命令的stdout是否等于特定字符串。

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天全站免登陆