2016-04-25 100 views
0

我嘗試在詞典中使用詞典。不能在詞典中使用詞典

tasks/main.yml

- name: Create Repository Folders 
    file: path=/srv/svn/{{ ansible_fqdn }}/{{ item.value.reponame }} state=directory mode=0755 owner=apache group=apache 
    with_dict: 
    - repos 

而且我vars/main.yml

--- 
repos: 
    repo1: 
    reponame: repository1 
    repogroup: group1 
    repo2: 
    reponame: repository2 
    repogroup: group2 
    repo3: 
    reponame: repository3 
    repogroup: group3 

但運行ansible-劇本時,我得到以下錯誤:

TASK [svn : Create Repository Folders] ***************************************** 
fatal: [sun.beach.lan]: FAILED! => {"failed": true, "msg": "with_dict expects a dict"} 

我跟着的「循環的說明哈希結束「:http://docs.ansible.com/ansible/playbooks_loops.html

我想我沒有正確的YAML語法,但我沒有想法。

回答

2

如果您正在使用ansible只需卸下-盈的reposwith_dict

- name: Create Repository Folders 
    file: path=/srv/svn/{{ ansible_fqdn }}/{{ item.value.reponame }} state=directory mode=0755 owner=apache group=apache 
    with_dict: 
    repos 

2.0+然後使用它是這樣的:

with_dict: "{{ repos }}" 

希望這會幫助你。

+0

謝謝...你能解釋爲什麼ansible 2.0+以這種方式工作嗎? – pwe

+0

在ansible 2.0+中使用裸變量不推薦使用 –