2015-06-05 60 views
0

my_tags事實分配正在進行第二項任務。列出的第一項任務導致失敗,但這只是一個簡單的重新安排。是的,當我運行它時,我正確評論/取消了評論。Ansible yaml重新排列導致錯誤

下面的代碼:

- 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. 

當我從終端複製粘貼到這裏,克拉(^)是指向「方向'可變的,如果這是任何線索,但我沒有看到任何標籤被使用。

爲什麼重排會導致此錯誤?

+0

嘗試'」「'引用第1或2或兩個組的'{{}}' 。 – Mxx

回答

2

這是記錄在Hey Wait, A YAML gotcha

YAML syntax requires that if you start a value with {{ foo }} you quote the whole line, since it wants to be sure you aren’t trying to start a YAML dictionary.

所以,你應該這樣寫:

my_tags: "{{ my_tags | default('') }}, sbc_type:{{ direction }},"