pwe
pwe

Reputation: 127

Can't use dictionaries in ansible

I try to use dictionaries in ansible.

My 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

And my vars/main.yml:

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

But when running ansible-playbook I get following error:

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

I followed the instructions on "Looping over Hashes" here: http://docs.ansible.com/ansible/playbooks_loops.html

I guess I don't have the right YAML-syntax, but I'm running out of ideas.

Upvotes: 0

Views: 1396

Answers (1)

Arbab Nazar
Arbab Nazar

Reputation: 23791

Just remove the - infront of repos after with_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

If you are using ansible 2.0+ then use it like this:

with_dict: "{{ repos }}"

Hope this will help you.

Upvotes: 2

Related Questions