Create the list. Put the below declarations into *vars*
csv_query: '.[`Clusters`, key, value.node, value.state]'
csv: "{{ Clusters|dict2items|json_query(csv_query)|
map('flatten')|map('join', ',')|list }}"
gives
csv:
- Clusters,192.168.1.1,node1,up
- Clusters,192.168.1.2,node2,down
- Clusters,192.168.1.3,node3,up
Write the file
- copy:
dest: /tmp/Clusters.csv
content: "{{ csv|join('\n') }}"
gives
cat /tmp/Clusters.csv
Clusters,192.168.1.1,node1,up
Clusters,192.168.1.2,node2,down
Clusters,192.168.1.3,node3,up