本文介绍了检查列表中是否包含Ansible中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试检查提供的版本是否为有效的受支持版本.我已在变量中设置了可接受版本的列表,并且如果提供的版本不在列表中,则我想退出该任务.但是,我不确定该怎么做.
I'm trying to check if the version supplied is a valid supported version. I've set the list of acceptable versions in a variable, and I want to fail out of the task if the supplied version is not in the list. However, I'm unsure of how to do that.
#/role/vars/main.yml
---
acceptable_versions: [2, 3, 4]
和
#/role/tasks/main.yml
---
- fail:
msg: "unsupported version"
with_items: "{{acceptable_versions}}"
when: "{{item}} != {{version}}"
- name: continue with rest of tasks...
以上是我想要做的事情,但是我无法弄清楚是否有一种方法可以为故障模块构造列表包含"调用.
Above is sort of what I want to do, but I haven't been able to figure out if there's a one line way to construct a "list contains" call for the fail module.
推荐答案
在有条件的情况下不需要{{}}
.您要搜索的是:
You do not need {{}}
in when conditions. What you are searching for is:
- fail: msg="unsupported version"
when: version not in acceptable_versions
这篇关于检查列表中是否包含Ansible中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!