我遇到了最愚蠢的問題。 我無法弄清楚如何在Ansible 2.2任務文件中測試布爾值。使用真正的錯誤與Ansible當子句
在vars/main.yml
,我有:
destroy: false
在劇本,我有:
roles:
- {'role': 'vmdeploy','destroy': true}
在任務文件中,我有以下幾點:
- include: "create.yml"
when: "{{ destroy|bool }} == 'false'"
我已經嘗試過以下各種組合:
when: "{{ destroy|bool }} == false"
when: "{{ destroy|bool }} == 'false'"
when: "{{ destroy|bool == false}}"
when: "{{ destroy == false}}"
when: "{{ destroy == 'false'}}"
when: destroy|bool == false
when: destroy|bool == 'false'
when: not destroy|bool
在上述所有情況下,我仍然得到:
statically included: .../vmdeploy/tasks/create.yml
調試輸出:
- debug:
msg: "{{ destroy }}"
---
ok: [atlcicd009] => {
"msg": true
}
期望的結果是,它會跳過包括。