ignoring docker interface when getting interface list

I’m having a problem Docker interface problems while getting a list of interfaces. People on here helped me get the list of interfaces on a device (thank you) like this:

lineinfile:
dest: “data.txt”
line: “{{ item }}: {{ ansible_facts[item].ipv4.address }}”

insertafter: EOF
delegate_to: 127.0.0.1
with_items: “{{ ansible_interfaces }}”

The problem is when docker is running, it creates interfaces like this:

veth[UNIQUE ID]

and they don’t have IP addresses. How do I ignore the interface beginning with veth?
I’ve tried this:

when: "{{ item }} == “^vether”

and
when: "{{ item }} = “vether.?”

but neither works. How would I do this?

Instead of looping over all interfaces and applying a condition to each iteration, you can also filter the list to not include those names.
It will be cleaner for your output as well. So instead of:

with_items: “{{ ansible_interfaces }}”

You could do:

with_items: “{{ ansible_interfaces | reject(‘search’,‘^veth’) }}”

Dick

I didn’t have any idea you could do that sort of things - thank you. It worked perfectly.