如何在variables未定义的情况下运行任务?

我正在寻找一种方法来执行任务时,可变的variables不是寄存器/未定义,例如

-- name: some task command: sed -n '5p' "{{app.dirs.includes}}/BUILD.info" | awk '{print $2}' when: (! deployed_revision) AND ( !deployed_revision.stdout ) register: deployed_revision 

从安全文档 :如果没有设置所需的variables,可以使用Jinja2定义的testing跳过或失败。 例如:

 tasks: - shell: echo "I've got '{{ foo }}' and am not afraid to use it!" when: foo is defined - fail: msg="Bailing out. this play requires 'bar'" when: bar is not defined 

所以在你的情况下, when: deployed_revision is not defined应该工作