【发布时间】:2021-04-30 09:41:07
【问题描述】:
我正在尝试检查角色中变量的值,但我不知道变量名是什么,因为它是在角色之外设置的。
我尝试使用 yaml 锚来实现这一点:
- set_fact:
set_anchor: &job_status_data_key "{{ job_running_check_key }}"
[...]
- name: Set current state
set_fact:
loop_finished_successfully: true
when: *job_status_data_key != "Running"
job_running_check_key 开头的位置设置在角色之外,并包含我将要检查的变量名。
但 ansible 似乎不喜欢条件句中的指针
ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: Expecting value: line 1 column 1 (char 0)
Syntax Error while loading YAML.
did not find expected key
The error appears to be in 'path/to/role/task.yml': line 15, column 30, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
loop_finished_succesfully: true
when: *job_status_data_key != "Running"
^ here
可能有一个合适的语法来实现这一点,但我直到现在才弄清楚。
【问题讨论】:
标签: ansible yaml conditional-statements anchor