how to rewrite this the proper way?

Hello

here’s my playbook, I am looking for interface without IP:

found a solution myself

  • name: find interface without an ip
    set_fact:
    desired_interface_name: “{{ item }}”
    when:
    hostvars[inventory_hostname][‘ansible_’+item].ipv4|length == 0

ansible_{{ item }}.ipv4 is defined and (ansible_{{ item }}|length>0)

with_items:
“{{ ansible_interfaces }}”

it works. although it seems a bit counterintuitive…
why not the first way???