ansible - Ansible 中的 when 条件出现错误

标签 ansible

我有这个

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

我什至尝试过

时间:dr​​y_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/

相关文章:

mysql - Ansible 和 MySQL 远程权限

Ansible 按对象字段的值在列表中查找对象

ansible - 从 playbook 编辑 AnsibleVault 文件

kubernetes - RBAC:具有多个命名空间的角色

ansible - 无法在 Ansible shell 模块中设置超时

Ansible strip 空白

即使启用了 sudo,对于无法写入/var/文件夹的用户,Ansible ping 也会失败

jinja2 - Ansible:获取一个组的所有IP地址

docker - 将Docker-compose转换为ansible剧本?

serialization - Ansible:无法为顺序执行设置变量