Last Updated: February 25, 2016
· dorfsmay

Using dictionaries with with_items

"withitems" takes a list of items, but in yaml nothing prevent an element in a list to be a dictionary (like the ansible tasks). Using a list of dictionaries with withitems can be convenient to keep a clean format in a playbook/task. For example:

- name: verify / create users
  user: name=${item.name} uid=${item.uid} comment="${item.comment}" group=${item.group} home=${item.home}
    - name: postgres
      uid: 200
      comment: postgresql user
      group: postgres
      home: /var/lib/postgresql
    - name: joe
      uid: 1001
      comment: Joe Coderwall
      group: users
      home: /home/joe
Say Thanks
Filed Under