I'm trying to parse a csv using the template module:

host1,fqdn1,...
host2,fqdn2,...



{% for item in csvfile.split("\n") %}
{%   if loop.index != 0 %}
{%     set list = item.split(",") %}
[col1]
name: '{{ list[0] | trim() }}'
label: '{{ list[11] | trim() }}'
[options]
followup = yes
{%   endif %}
{% endfor %}



This works fine for creating a single file from the template, but I want to 
create seperate files, depending on the value of list[3], for example zone.

That way I'd get 2 files, zone1, zone2, and each file will have the rows 
that contain list[3] as zone1, and so on.

My current play is like this:

  vars:
    csvfile: "{{ lookup('file', 'ou.csv') }}"
  tasks:
    - name: "Parse csv"
      template:
        src: iterate.csv.j2
        dest: iterate.ini


What changes would I have to make to the template and play to incorporate 
this?

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/dd2dd4e5-c9a7-4407-88ad-d777eec74399%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to