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}
with_items:
- 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
Written by Yves Dorfsman
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ansible
Authors
Misha Behersky
78.97K
tartansandal
73.31K
Related Tags
#ansible
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#