Ansible yaml重排导致错误

Ansible yaml重排导致错误,yaml,ansible,ansible-playbook,Yaml,Ansible,Ansible Playbook,my_tags事实分配正在第二个分配中工作。列出的第一个赋值会导致失败,但这只是一个简单的重新排列。是的,我在运行它时正确地注释了/取消了注释 代码如下: - name: Set optional tag when: machine_type.find('substr') != -1 set_fact: # vvv some quoting error? vvv my_tags: {{ my_tags | default('') }}, sbc_type:{{ direc

my_tags
事实分配正在第二个分配中工作。列出的第一个赋值会导致失败,但这只是一个简单的重新排列。是的,我在运行它时正确地注释了/取消了注释

代码如下:

- name: Set optional tag
  when: machine_type.find('substr') != -1
  set_fact:
    # vvv some quoting error? vvv
    my_tags: {{ my_tags | default('') }}, sbc_type:{{ direction }},
    # vvv works just fine vvv
    #my_tags: sbc_type:{{ direction }}, {{ my_tags | default('') }}
下面是错误:

    my_tags: {{ my_tags | default('') }}, sbc_type:{{ direction }},
                                        ^
We could be wrong, but this one looks like it might be an issue with
missing quotes.
当我将粘贴从终端复制到这里时,如果有任何线索的话,克拉(^)指向“方向”变量,但我没有看到使用任何选项卡

为什么重新排列会导致此错误?

中记录了此错误:

YAML语法要求,如果以{{foo}}开始一个值,则 引用整句话,因为它想确保你没有试图这样做 开始一本YAML字典

所以你应该这样写:

my_tags: "{{ my_tags | default('') }}, sbc_type:{{ direction }},"
尝试引用第一组或第二组或两组
{{}