I tried, but the title variable does not keep when looping from second row 
and on.

    {% for item in csvfile.split("\n") %}
    {%   if loop.index == 1 %}
    {%     set title = item.split(',') %}
    {%   else %}
    {%     set list = item.split(",") %}
    {{ list[1]|trim() }}:
    {{ title[0] }}: {{ list[0]|trim() }}
    {{ title[1] }}: {{ list[1]|trim() }}
    {{ title[2] }}: {{ list[2]|trim() }}
    {{ title[3] }}: {{ list[3]|trim() }}
    {{ title[4] }}: {{ list[4]|trim() }}
    {{ title[5] }}: {{ list[5]|trim() }}
    {%   endif %}
    {% endfor %}

The playbook output for task

    TASK [Parse CSV To YAML] 
***********************************************************************************************************
    fatal: [localhost]: FAILED! => {"changed": false, "failed": true, 
"msg": "AnsibleUndefinedVariable: 'title' is undefined"}

    msg: AnsibleUndefinedVariable: 'title' is undefined

-- 
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/57fe0af8-e02c-4f19-86ab-8d8b6350524d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to