【发布时间】:2019-01-17 17:05:28
【问题描述】:
我正在尝试编写一个从组 vars 文件中加载 vars 然后检查变量是否存在的 playbook
我的剧本是这样的:
---
- hosts: "{{ target }}"
roles:
- app
tasks:
- name: alert if variable does not exist
fail:
msg: "{{ item }} is not defined"
when: "{{ item }}" is not defined
with_items:
- country
- city
- street
...
我的库存文件包含
[app]
ansible-slave1
ansible-slave2
[db]
ansible-db
[multi:children]
app
db
我有 roles/app/vars/main.yml 包含
country: "France"
city: "Paris"
我期待的是输出“未定义街道”的剧本,但我有一个无法解决的语法问题
[vagrant@ansible-master vagrant]$ ansible-playbook --inventory-file=ansible_master_hosts test_variables.yml --extra-vars "target=ansible-slave1" --syntax-check
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/vagrant/test_variables.yml': line 10, column 24, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
msg: "{{ item }} is not defined"
when: "{{ item }}" is not defined
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
我会很高兴有任何提示。
谢谢
【问题讨论】:
标签: ansible