Dictionary Can';不要在英语中使用词典

Dictionary Can';不要在英语中使用词典,dictionary,yaml,ansible,Dictionary,Yaml,Ansible,我试着在ansible中使用字典 我的任务/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 --- repos: repo1: reponame: repos

我试着在ansible中使用字典

我的
任务/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
---
repos:
  repo1:
    reponame: repository1
    repogroup: group1
  repo2:
    reponame: repository2
    repogroup: group2
  repo3:
    reponame: repository3
    repogroup: group3
和my
vars/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
---
repos:
  repo1:
    reponame: repository1
    repogroup: group1
  repo2:
    reponame: repository2
    repogroup: group2
  repo3:
    reponame: repository3
    repogroup: group3
但在运行ansible playbook时,我得到以下错误:

TASK [svn : Create Repository Folders] *****************************************
fatal: [sun.beach.lan]: FAILED! => {"failed": true, "msg": "with_dict expects a dict"}
我按照“在散列上循环”的说明进行操作:


我想我没有正确的YAML语法,但我已经没有主意了。

只需删除
-
回购协议
前面的

- name: Create Repository Folders
  file: path=/srv/svn/{{ ansible_fqdn }}/{{ item.value.reponame }} state=directory mode=0755 owner=apache group=apache
  with_dict:
    repos
如果您使用的是ansible 2.0+,请如下使用:

with_dict: "{{ repos }}"

希望这能对您有所帮助。

只需使用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
如果您使用的是ansible 2.0+,请如下使用:

with_dict: "{{ repos }}"

希望这对您有所帮助。

谢谢。。。你能解释为什么ansible 2.0+是这样工作的吗?ansible 2.0+不推荐使用裸变量,谢谢。。。你能解释为什么ansible 2.0+是这样工作的吗?ansible 2.0不赞成使用裸变量+