仅当变量包含特定字符串时才运行 Ansible 任务 [英] Run an Ansible task only when the variable contains a specific string

查看:21
本文介绍了仅当变量包含特定字符串时才运行 Ansible 任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个任务取决于 variable1 的值.我想检查值是否在 {{variable1}} 中,但出现错误:

I have multiple tasks depend from the value of variable1. I want to check if the value is in {{variable1}} but i got an error:

- name: do something when the value in variable1
  command: <command>
  when: "'value' in {{variable1}}"

我使用的是 ansible 2.0.2

I'm using ansible 2.0.2

推荐答案

如果 variable1 是一个字符串,并且您正在其中搜索一个子字符串,这应该有效:

If variable1 is a string, and you are searching for a substring in it, this should work:

when: '"value" in variable1'

如果 variable1 是数组或字典,in 将搜索 exact 字符串作为其项目之一.

if variable1 is an array or dict instead, in will search for the exact string as one of its items.

这篇关于仅当变量包含特定字符串时才运行 Ansible 任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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