2017-04-27 41 views
0

vars/all.ymlAnsible嘗試應用嵌套元素的情況,我不想

websites: 
    - 
     dest: test_project 
     db_password: 'xxxx' 
     delete: false 

而一個main.yml這有一個條件要求backend.yml

- debug: msg={{ websites | selectattr("dest", "equalto", project_name) | list }} 
    register: website 

ok: [xxx.com] => { 
    "changed": false, 
    "msg": [ 
     { 
      "db_password": "xxxx", 
      "delete": false, 
      "dest": "test_project", 

     } 
    ] 
} 

- include: backend.yml 
    when: not website.msg.delete|bool 
    #static: no #tried this too, but has no effect 

然後給定一個項目,backend.yml包含:

... 
- name: Grant ACL for write inside "wp-content" (default) 
    acl: 
    name: "{{ ansible_www_home }}/{{ item[0].dest }}/wp-content/" 
    entity: "{{ item[1] }}" 
    etype: group 
    permissions: rwx 
    state: present 
    with_nested: 
    - "{{ website.msg }}" 
    - ['www-data', 'test'] 
... 

錯誤是

The conditional check 'not item.delete|bool' failed. 
The error was: error while evaluating conditional (not item.delete|bool): 'list object' has no attribute 'delete' 

The error appears to have been in 'backend.yml': line 58, column 3, but may be elsewhere in the file depending on the exact syntax problem 

好像Ansible正在努力尋找delete性質的第二嵌套數組['www-data', 'test']這當然是不存在的。

我不明白爲什麼ansible會試圖將我的包含條件應用於此級別。如果item.delete不正確,我不想嘗試調用這個條件,我只想要包含該文件。backend.yml

你有關於如何解決它的想法?

PS:我試圖添加static: nomain.yml的條件,但它沒有效果。

+0

什麼你想做的事,當你寫的'時:不item.delete | bool'? – techraf

+0

我不想包含'backend.yml'(安裝項目)。只是跳過這個文件的包含。 –

+0

什麼是'item'?循環定義在哪裏? – techraf

回答

0

好了,所以,計算過,多愚蠢的錯誤進行了改造,解決辦法是:

- include: backend.yml 
    when: not website.msg.0.delete|bool 
    static: no