我有这个
dry_run: "{{ lookup('env','DRY_RUN') | default(yes,true) }}"
我收到此错误
我正在使用类似
when: dry_run
fatal: [localhost]: FAILED! => {"failed": true, "msg": "The conditional check 'dry_run' failed. The error was: error while evaluating conditional (dry_run): 'yes' is undefined\n\nThe error appears to have been in
我什至尝试过
时间:dry_run | bool
以及
The error was: error while evaluating conditional (dry_run|bool): {{ lookup('env','DRY_RUN') | default(yes,true) }}: 'yes' is undefined\n\nThe error appears to have been in
最佳答案
使用 default(true)
而不是 default(yes)
(它是 Jinja2 模板,而不是 YAML,因此 yes
不是同义词with true
) 并设置一个事实,这样您就不会在条件中使用模板:
- set_fact:
dry_run: "{{ lookup('env','DRY_RUN') | default(true, true) }}"
- debug:
when: dry_run
关于ansible - Ansible 中的 when 条件出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44252192/