2016-04-25 95 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+中使用裸变量不推荐使用 –