I need to generate few files based on jinja template ,
In the first run it is easy when I need to generate single file per user
Basic input:
user:
- { username: user1, action: get , file: 1.txt }
- { username: user2, action: get , file: 2.txt }
Jinja template:
User: {{ item.users }}
Permission: {{ item.action}}
File-access: {{ite.file}}
Playbook:
- name: generate files
template:
src: template.j2
dest: "{{ folder }}/{{
item.username }}"
with_items: "{{ user }}"
But now comes the twist, Single user can have multi files (see user1) and , I need to create for this user 2 files
File 1 – filename user1-1 , where file = to 1.txt
File 2 – filename user1-2 , where file = to new.file
Advance input:
user:
- { username: user1, action: get , file: [1.txt ,new.file] }
- { username: user2, action: get , file: 2.txt }
Any ideas ?
- name: test jinja rendering
hosts: localhost
gather_facts: no
vars:
users:
- username: user1
action: GET
files:
- file1
- username: user2
action: GET
files:
- file1
- file2
tasks:
- name: debug the data structure
ansible.builtin.debug:
msg:
- Item 0 is '{{ item.0 }}'
- Item 1 is '{{ item.1 }}'
loop: '{{ users | subelements("files") }}'
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f4ece24c-9706-4ccb-89bf-1ae8b18d9d34n%40googlegroups.com.