![](/img/trans.png)
[英]Ansible when condition always fails when a dictionary is there but it contains no elements
[英]ansible when condition fails
以下当条件失败并出现解析错误时。
- name: some task
debug:
msg: "{{ansible_host}}"
when: "({{somevariable}} == 'foo' and ABC_{{bar}}_xyz in group_names) or ({{somevariable}} == 'foo' and ABC_{{bar}}_efg in group_names)"
如果某个变量等于 foo 并且主机属于库存中的几个特定组,我基本上希望此任务运行
错误信息
fatal: [x.x.x.x]: FAILED! => {"msg": "The conditional check '({{somevariable}} == 'foo' and ABC_{{bar}}_xyz in group_names) or ({{somevariable}} == 'foo' and ABC_{{bar}}_efg in group_names)' failed. The error was: error while evaluating conditional (({{somevariable}} == 'foo' and ABC_{{bar}}_xyz in group_names) or ({{somevariable}} == 'foo' and ABC_{{bar}}_efg in group_names)): 'foo' is undefined\n\nThe error appears to be in '/playbooks/playbook.yml': line 23, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: some task\n ^ here\n"}
您不应将{{
}}
与when
条件一起使用。 请参阅此官方文档。 意味着,您的表达式应如下所示:
when: "(somevariable == 'foo' and 'ABC_' + bar + '_xyz' in group_names) or (somevariable == 'foo' and 'ABC_' + bar + '_efg' in group_names)"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.