Is this what you’re looking for:
Variables registered for a task that has
with_itemshave different format, they contain results for all items.
- hosts: localhost
tags: s21
gather_facts: no
vars:
images:
- foo
- bar
tasks:
- shell: "echo result-{{item}}"
register: "r"
with_items: "{{images}}"
- debug: var=r
- debug: msg="item.item={{item.item}}, item.stdout={{item.stdout}}, item.changed={{item.changed}}"
with_items: "{{r.results}}"
- debug: msg="Gets printed only if this item changed - {{item}}"
when: "{{item.changed == true}}"
with_items: "{{r.results}}"
Source: Register variables in with_items loop in Ansible playbook