# how to rewrite this  the proper way?

**URL:** <https://forum.ansible.com/t/how-to-rewrite-this-the-proper-way/35406>\
**Category:** Ansible Project\
**Created:** [June 25, 2021, 8:38am UTC](https://forum.ansible.com/t/how-to-rewrite-this-the-proper-way/35406 "2021-06-25T08:38:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregory\_Edigarov](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Gregory\_Edigarov](https://forum.ansible.com/u/Gregory_Edigarov)\
**Post date:** [June 25, 2021, 8:38am UTC](https://forum.ansible.com/t/how-to-rewrite-this-the-proper-way/35406/1 "2021-06-25T08:38:58Z")

</div>

Hello

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

---

<div class="post-metadata">

**Author:** ![Gregory\_Edigarov](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Gregory\_Edigarov](https://forum.ansible.com/u/Gregory_Edigarov)\
**Post date:** [June 25, 2021, 9:15am UTC](https://forum.ansible.com/t/how-to-rewrite-this-the-proper-way/35406/2 "2021-06-25T09:15:03Z")

</div>

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???
