Error While nesting the with_item

Dear All,
I want to get output message of the log using ansible debug .
[Case-1]
If I know the no of results and I want too print then I can use below code
CODE[start]

  • name: Display all Endpoints Health_Check test results[--------]
    debug:
    msg:
  • " endpoint check - [{{ ansible_fqdn }}] - [status_code: {{ PCheck.results[0].status }}] - {{ PCheck.results[0].url }}"
  • " endpoint check - [{{ ansible_fqdn }}] - [status_code: {{ PCheck.results[1].status }}] - {{ PCheck.results[1].url }}"
  • " endpoint check - [{{ ansible_fqdn }}] - [status_code: {{ PCheck.results[2].status }}] - {{ PCheck.results[2].url }}"

[Case-2]
If I don’t know about the number of results ,because I’m taking data from a file then I don’t know the no of entry so output result will be a variable value
Then how the above code will look like ,please suggest
CODE[start]

  • name: Display all Endpoints Health_Check test results[--------]
    debug:
    msg:
  • " endpoint check - [{{ ansible_fqdn }}] - [status_code: {{ PCheck.results[0].status }}] - {{ PCheck.results[0].url }}"
  • " endpoint check - [{{ ansible_fqdn }}] - [status_code: {{ PCheck.results[0+1].status }}] - {{ PCheck.results[0+1].url }}"
  • " endpoint check - [{{ ansible_fqdn }}] - [status_code: {{ PCheck.results[0+2].status }}] - {{ PCheck.results[0+2].url }}"
    .
    .
    .
  • " endpoint check - [{{ ansible_fqdn }}] - [status_code: {{ PCheck.results[0+n].status }}] - {{ PCheck.results[0+n].url }}"

NOTE: here ‘n’ is the no of entries in file

Please suggest . I’m new in Ansible world.

Thanks & Regards
Ram

Investigate loop: and with_items:

  • name: Display all Endpoints Health_Check test results
    debug:
    msg: “endpoint check - [{{ ansible_fqdn }}] - [status_code: {{ item.status }}] - {{ item.url }}”
    with_items: {{ PCheck.results }}

​Untested - something like that, anyway. In the loop “item” is the current element of the list passed to with_items:.​

​Regards, K.

Thanks Karl Auer for fast reply.
It worked for me .

Thanks & Regards
Ram

Thanks Karl Auer for fast reply.
It worked for me.

Thanks & Regards
Ram