【发布时间】:2017-11-24 21:59:00
【问题描述】:
我在角色开始时有一个任务:
- name: check if pg_* variables are defined
fail: msg="variable {{item}} is undefined"
when: "{{item}} is undefined"
with_items:
- pg_dbname
- pg_host
- pg_port
- pg_username
- pg_password
但较新版本的 Ansible 会发出以下警告:
[警告]:when 语句不应包含 jinja2 模板分隔符,例如 {{ }} 或 {% %}。发现:{{item}} 未定义
删除 Jinja2 大括号 when: item is undefined 不起作用,因为最终评估基本上等同于:
"pg_dbname" is undefined` # False
"pg_host" is undefined` # False
.
.
"pg_password" is undefined` # False
这不是我想要的。
【问题讨论】: