ansible - 布尔值 true 或 false 的 Ansible 导入任务
问题描述
我想用布尔值创建一个部署任务/角色。默认情况下为 false 并使其为 true,部署完成。就像在 main.yml 中定义了一个变量
vars:
- c
- name: task 1
import_tasks: "a.yml"
when: c is defined
tags:
- a
- name: task 2
import_tasks: "b.yml"
when: c is defined
tags:
- b
解决方案
您可以执行以下操作;但是,正如以下评论之一所述,这可能会在某些情况下导致一些意外行为,并且不是实现您所要求的唯一方法:
- set_fact: c=false
when: c is undefined
- name: task 1
import_tasks: "a.yml"
when: c | bool
tags:
- a
- name: task 2
import_tasks: "b.yml"
when: c | bool
tags:
- b
推荐阅读
- javascript - 如何处理变量字符串中的撇号或引号?JavaScript
- reactjs - React context api - 与其他包共享数据
- spring-boot - 我可以使用 SpringBatch 传输 http 的文件(视频/txt)并在我的电脑上读取和写入吗?
- html - 尽管显式设置了 margin:0,但包含导航栏的标题的上方和左侧和右侧的边距
- python - 为什么我看到“ufunc '减法'不能使用类型为 dtype 的操作数('
我有两个熊猫数据框,都带有日期时间索引;样本输出:
l1_with_nonlimiting_trace_gas_df.index:
DatetimeIn
- ruby-on-rails - 在将请求从本地 NextJS 服务器发送到本地 Rails api 服务器时测试 CORS
- python - 如何在熊猫中按组获取具有最大限制的前 n 行
- mysql - Docker-compose 的通信链接失败
- java - SOLR 的执行器运行状况检查给出错误创建名称为“solrClient”的 bean
- django - Django 流文件永不结束请求