【发布时间】:2021-04-12 12:17:36
【问题描述】:
我在为角色添加 when 条件时遇到了 ansible 语法错误。
我正在为此剧本使用动态库存。
下面是动态库存输出的例子:
{
"_meta": {
"hostvars": {
"host1": {
"Id": "1234567890",
"enable_patching": "ENABLED"
},
"host2": {
"Id": "123654290",
"enable_patching": "DISABLED"
}
}
}
下面是 ansible 剧本:
---
# This playbook will execute the inventory for applications account
- hosts: nonprod
connection: local
gather_facts: false
serial: 1
vars:
tf_project: "nonprod"
roles:
- { role: patching, tags: [ 'patching' ], when: "{{ hostvars[inventory_hostname]['enable_patching'] }}" = 'ENABLED' }
我在运行 ansible playbook 时遇到错误
The offending line appears to be:
- { role: patching, tags: [ 'patching' ], when: "{{ hostvars[inventory_hostname]['enable_patching'] }}" = 'ENABLED' }
^ here
如何在剧本中使用主机变量?不想在角色中使用 when 条件。
【问题讨论】:
-
你的
when中的=不应该是==吗?
标签: ansible