See if this helps. (In a real case you’d use ansible.builtin.template, but this example uses ansible.builtin.copy with content: to keep it all together.)
---
# Shiraz_Kamal_01.yml
- name: Looping over cluster nodes
hosts: localhost
gather_facts: false
vars:
aux: "SHR"
cluster_nodes:
- { node_name: "sudora123a", node_num: 1, inst_num: "123A" }
- { node_name: "sudora123b", node_num: 2, inst_num: "123B" }
tasks:
- name: I am trying to loop through each node_name and write out to different files.
ansible.builtin.copy:
dest: 'file{{ cn.node_num }}.out'
mode: '0644'
content: |
# file{{ cn.node_num }}.out
(SID_LIST =
(SID_NAME = {{ aux }}{{ cn.inst_num }})
)
)
loop: '{{ cluster_nodes }}'
loop_control:
loop_var: cn