Issue with loop index number.

Hi,

I have a situation where I have few servers and there are different artifacts or rpms are installed. I am getting all data for all servers in a clubbed list and based on that I am creating files for each server and the respective rpms data are posted to that file.

So suppose server 1 has 5 rpms and server 2 has 2 rpms and file I will create it should look like this.
File1:
artifact:
1:
artifact_name:
artifact_version:
2:
artifact_name:
artifact_version:
Similarly till 5 and similarly on the other file there will be two entries under artifact as 1 & 2.

But on using loop index for file1 i get 5 numbers but for file 2 instead of starting the number with 1 it starts with 6.

Help on this is really appreciated.

Regards,
Soumya

Can you show us your actual code

I can show a dummy thing:

So i am using blockinfile module.

blockinfile:
path: /tmp/item.ci_name/vars
block: |2
{{ ansible_loop.index}}:
artifact_name: {{ item.1.artifact_id}}
artifact_version: {{ item.1.artifact_version}}
insertafter: “artifact:”
with_subelements:

  • “{{ custom.results}}”
  • json.result.artifacts

Regards,
Soumya

Can someone help me with the below query?

Regards,
Soumya

Can somebody please help with the below query.

Regards,
Soumya