小编pt1*_*pt1的帖子

在 Ansible 剧本中:在“when”子句中使用可能未定义的布尔值

Ansible 任务可以有when这样的子句:

- name: Conditional output
  debug:
    msg: This is a conditional output
  when: some_var
Run Code Online (Sandbox Code Playgroud)

为了防止some_var未定义,可以使用

- name: Conditional output
  debug:
    msg: This is a conditional output
  when: some_var is defined and some_var
Run Code Online (Sandbox Code Playgroud)

似乎还有这样的变体:

- name: Conditional output
  debug:
    msg: This is a conditional output
  when: some_var | d() | bool
Run Code Online (Sandbox Code Playgroud)

这些变体相同吗?它们的优点/缺点是什么?

ansible

6
推荐指数
1
解决办法
545
查看次数

标签 统计

ansible ×1