Ansible 库存变量未定义

Ansible inventory variable undefined

我已经在我的清单文件中定义了一个变量,但是在播放条件下使用它时我得到错误变量未定义。

inventory.yml:

[nodes]
node1 ....
node1 ....

[cluster:children]
nodes

[cluster:vars]
somevar=False

testvar=value

playbook.yml:

- include: setup_whatever.yml
  when: "testvar == 'value'"

运行 它与

ansible-playbook playbook.yml -i inventory

这是我收到的错误消息

ERROR! The conditional check 'testvar == 'value'' failed. The error was: ERROR! error while evaluating conditional (testvar == 'value'): ERROR! 'testvar' is undefined

ansible 版本:2.0.0.2

将您的 Ansible 版本升级到现代版本。

  • Ansible 2.0.0.2(你的)
ERROR! The conditional check 'testvar == 'value'' failed. The error was:
ERROR! error while evaluating conditional (testvar == 'value'):
ERROR! 'testvar' is undefined
  • Ansible 2.1.3.0(也过时了!)
PLAY [nodes]  
\*******************************************************************

TASK [debug]  
\*******************************************************************  
ok: [node1] => {  
  "msg": "Hello world!"  
}