Ansible iterate a dictionary with lists and templates

55 views
Skip to first unread message

swen.b

unread,
May 13, 2016, 11:31:43 AM5/13/16
to Ansible Project
Hi,

my goal is to use multiple dictionaries within a template. I want one file per username with all projects in it of this user.
My playbook looks like:

- name: create files template: src=vhost.conf.j2 dest=/tmp/{{ item.0.username }}.conf with_subelements: - "{{ users }}" - projects vars: users: - username: jon password: 123456 sftp: True projects: - projectname: Projekt1 documentroot: root1 - projectname: Projekt2 documentroot: root2 - username: jane password: 123456 projects: - projectname: Projekt3 documentroot: root3 - projectname: Projekt4 documentroot: root4

How does a working {% for %} loop needs to look like in the template file? Let's say I want to insert all projectnames of each username in a per username file?
Thanks for helping me out!

swen.b

unread,
May 13, 2016, 11:38:02 AM5/13/16
to Ansible Project
Here is the playbook more readable:
Reply all
Reply to author
Forward
0 new messages