2016-04-26 45 views
9

我認爲這是產生錯誤的劇本的一部分。我應該如何重寫這部分?Ansible:[棄權警告]:不推薦使用裸變量

roles: 
- role: json-transform 
    json_transforms: '{{ clientValidation.json_transforms}}' 

它拋出以下警告:

[DEPRECATION WARNING]: Using bare variables is deprecated. Update your playbooks so that the environment value uses the full variable syntax ('{{json_transforms}}'). This feature will be removed in a 
future release. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg. 
+0

你正在使用什麼Ansible版本?這個語法對我來說看起來有點奇怪,通常我會用類似於''{{role:json-transform,json_transforms:'{{clientValidation.json_transforms}}'}'的方式去做,所以你可能想嘗試一下。 – ydaetskcoR

+0

我正在使用Ansible 2.0.1 我已經嘗試了您提到的內容,但無法正常工作。 – anuiq

+0

語法無關緊要 - @ydaetskcoR僅使用內聯詞典語法而不是擴展的yaml詞典語法。它們在解析的文檔中完全一樣。 – nitzmahone

回答

11

它看起來並不像有什麼不對您的頂部LEVEL-它可能是你的角色裏面的東西。棄用裸露變量通常出現在with_xxx循環中;例如:

- hosts: blar 
    vars: 
    items: 
    - one 
    - two 
    tasks: 
    - debug: msg="hi from {{ item }}" 
    with_items: items 

在這種情況下,它告訴你,with_items: items應該with_items: "{{ items }}"