Working with dicts

572 views
Skip to first unread message

Premanand Chandrasekaran

unread,
Mar 31, 2014, 6:25:51 PM3/31/14
to ansible...@googlegroups.com
Hello,

I am an ansible newbie and I am trying to understand how to work with dicts.

The following playbook produces a syntax error, and we're not sure why:

ansible-playbook --version
ansible-playbook 1.5.3

ansible-playbook -i ~/.ansible-hosts dict.yml --syntax-check

ERROR: parse error: playbooks must be formatted as a YAML list, got <type 'dict'>

And here is the playbook (used from the ansible documentation) at http://docs.ansible.com/playbooks_loops.html#looping-over-hashes:

---
users:
  alice:
    name: Alice Appleworth
    telephone: 123-456-7890
  bob:
    name: Bob Bananarama
    telephone: 987-654-3210

tasks:
  - name: Print phone records
    debug: msg="User {{ item.key }} is {{ item.value.name }} ({{ item.value.telephone }})"
    with_dict: users


Any help with this is highly appreciated.

Thanks!

Serge van Ginderachter

unread,
Apr 1, 2014, 10:25:49 AM4/1/14
to ansible...@googlegroups.com
On 1 April 2014 00:25, Premanand Chandrasekaran <prema...@gmail.com> wrote:
ERROR: parse error: playbooks must be formatted as a YAML list, got <type 'dict'>

And here is the playbook (used from the ansible documentation) at http://docs.ansible.com/playbooks_loops.html#looping-over-hashes:

​This is not a playbook, but two distinct snippets, the first from ​a vars file, the second is just a tasks list.
Better have a look here http://docs.ansible.com/playbooks_intro.html to understand how a playbook is structured.

Premanand Chandrasekaran

unread,
Apr 1, 2014, 9:51:47 PM4/1/14
to ansible...@googlegroups.com
Thanks for the pointer. I was missing the vars section. The following works as expected:

---

- hosts: all
  vars:

    users:
      alice:
        name: Alice Appleworth
        telephone: 123-456-7890
      bob:
        name: Bob Bananarama
        telephone: 987-654-3210
  remote_user: root

  tasks:
    - name: Print phone records
      debug: msg="User {{ item.key }} is {{ item.value.name }} ({{ item.value.telephone }})"
      with_dict: users

Reply all
Reply to author
Forward
0 new messages