ansible : how to use the variable ${item} from with_items in notify?
Handlers are just 'flagged' for execution once whatever (itemized sub-)task requests it (had the changed: yes in its result). At that time handlers are just like a next regular tasks, and don't know about the itemized loop.
A possible solution is not with a handler but with an extratask + conditional
Something like
- hosts: all
gather_facts: false
tasks:
- action: shell echo {{item}}
with_items:
- 1
- 2
- 3
- 4
- 5
register: task
- debug: msg="{{item.item}}"
with_items: task.results
when: item.changed == True