Exclude string from facts

I have the following fact, and I would like to create a new fact that excludes ‘lo’. What is the proper way to go about this?

`
“ansible_interfaces”: [
“lo”,
“enp0s3”,
“enp0s8”,
“enp0s9”
],

`

My latest failed attempt, but gives an idea as to what I am looking for

`

  • name: Set custom facts
    set_fact:
    devices: “{{ ansible_interfaces is not search(‘lo’) }}”

fatal: [rhel7]: FAILED! => {“msg”: “Unexpected templating type error occurred on ({{ ansible_interfaces is not search(‘lo’) }}): expected string or buffer”}

`

Side note… this list of interfaces will be dynamic, it may grow or shrink depending on the server.

search only works on strings, you provided a list.

Instead you will need to do something like:

ansible_interfaces|reject(‘search’, ‘lo’)|list

That will reject all items that match lo

- name: Set custom facts
  set_fact:
    devices: "{{ ansible_interfaces|difference([lo']) }}"

Awesome, thanks to the both of you. I tried both and they work for me.