我有多个任务取决于variable1的值。我要检查,如果值是{{变量1}},但我得到了一个错误:仅当变量包含特定字符串时才运行Ansible任务
- name: do something when the value in variable1
command: <command>
when: "'value' in {{variable1}}"
我使用ansible 2.0.2
我有多个任务取决于variable1的值。我要检查,如果值是{{变量1}},但我得到了一个错误:仅当变量包含特定字符串时才运行Ansible任务
- name: do something when the value in variable1
command: <command>
when: "'value' in {{variable1}}"
我使用ansible 2.0.2
如果variable1
是一个字符串,而你正在寻找在它的子串,这应该工作:
when: '"value" in variable1'
如果variable1
是一个数组或字典来代替,in
将搜索确切字符串作为其项目之一。
不应该是:when:''value'in variable1“ –
我用
failed_when: not(promtool_version.stdout.find('1.5.2') != -1)
意味着 - 失败,只有当先前注册的变量 “promtool_version” 不包含字符串 '1.5.2'。
上述答案的ansible 2.3.0.0为我工作,但下列情况:
when: variable1 | search("value")
+1我更喜欢这个答案。如果你想检查你也可以在'variable1'之前添加'not'变量1不包含'值'。when:not variable1 | search(“value”) –
回答以下对我的作品(当然,我用它在'断言:......是: ..'。你看到了什么错误? – jhutar