Given the string
s1: studId=ValueA,studName=valueB;studId=ValueC,studName=ValueD
unify the separators, e.g.
- set_fact:
s2: "{{ s1|regex_replace('[,;]', ';') }}"
gives
s2: studId=ValueA;studName=valueB;studId=ValueC;studName=ValueD
Split the items, iterate them by 2 items, and create the list of the dictionaries, e.g.
- set_fact:
l1: "{{ l1|d([]) + [dict(item|map('split', '='))] }}"
loop: "{{ s2.split(';')|batch(2) }}"
gives the expected structure of the data
l1:
- studId: ValueA
studName: valueB
- studId: ValueC
studName: ValueD
Now, the template
- debug:
msg: |
{% for item in l1 %}
student id={{ item.studId }}
student name={{ item.studName }}
{% endfor %}
gives the expected result
msg: |-
student id=ValueA
student name=valueB
student id=ValueC
student name=ValueD