0
在vars/all.yml
Ansible嘗試應用嵌套元素的情況,我不想
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: no
到main.yml
的條件,但它沒有效果。
什麼你想做的事,當你寫的'時:不item.delete | bool'? – techraf
我不想包含'backend.yml'(安裝項目)。只是跳過這個文件的包含。 –
什麼是'item'?循環定義在哪裏? – techraf