ansible - 如何在 Ansible 中跳过剩余任务并创建某些条件
问题描述
我想在下面创建以下条件。任何想法如何进行?我试过When Condition,set_facts,looping [],但我没有成功。任何帮助将不胜感激。
已生成的变量示例:
version_detected: "9.0.0.7"
version_available: "9.1.0.3"
"9.0.0.7",
"8.0.0.13"
创造条件
If "version_detected" is inside "version_available", then skip all remaining tasks and end playbook with a debug message.
If "version_detected" is not inside "version_available", then continue playbook for the next task.
下一个任务:
If "version_detected" contains "8.0", then download file www.site.com/fixpack80.gz to path
If "version_detected" contains "9.0", then download file www.site.com/fixpack90.gz to path
If "version_detected" contains "9.1", then download file www.site.com/fixpack91.gz to path
解决方案
when
假设这version_available
是一个列表,这仅在条件下是可以实现的。
例如:
vars:
version_detected: "9.0.0.7"
version_available: ["9.1.0.3", "9.0.0.7", "8.0.0.13"]
tasks:
- fail:
msg: Unsupported version
when: version_detected not in version_available
- debug:
msg: Do some task for version 8.0.x.x
when: '"8.0" in version_detected'
- debug:
msg: Do some task for version 9.0.x.x
when: '"9.0" in version_detected'
推荐阅读
- node.js - 用crypto-js解密节点js中laravel的加密值
- php - 面向项目的 PHP 身份验证和授权
- node.js - 在使用 create-react-app 创建项目时有什么方法可以使用 NPM 而不是 Yarn
- r - R 月度报告 - 浏览量数据 - 重复页面但不同的浏览量。有没有办法结合?
- docker - GitHub 页面测试构建失败,退出代码为 15
- asp.net-core - ASP.NET Core 3.1 不加载 URL 末尾没有“/”的页面
- asp.net-core - 实现 webdav 方法中的 Swagger 错误
- php - PHP编辑用户信息表单数据库
- python - 删除熊猫数据框的列值不连续出现的行
- spring-boot - kubernetes hazelcast 错误仅在一个命名空间中同步