# Exclude string from facts

**URL:** <https://forum.ansible.com/t/exclude-string-from-facts/27867>\
**Category:** Ansible Project\
**Created:** [June 25, 2018, 8:55pm UTC](https://forum.ansible.com/t/exclude-string-from-facts/27867 "2018-06-25T20:55:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [June 25, 2018, 8:55pm UTC](https://forum.ansible.com/t/exclude-string-from-facts/27867/1 "2018-06-25T20:55:18Z")

</div>

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”}

`

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [June 25, 2018, 8:56pm UTC](https://forum.ansible.com/t/exclude-string-from-facts/27867/2 "2018-06-25T20:56:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 25, 2018, 8:58pm UTC](https://forum.ansible.com/t/exclude-string-from-facts/27867/3 "2018-06-25T20:58:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 25, 2018, 8:59pm UTC](https://forum.ansible.com/t/exclude-string-from-facts/27867/4 "2018-06-25T20:59:14Z")

</div>

- name: Set custom facts  
&nbsp;&nbsp;set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;devices: "{{ ansible\_interfaces|difference([lo']) }}"

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [June 25, 2018, 9:04pm UTC](https://forum.ansible.com/t/exclude-string-from-facts/27867/5 "2018-06-25T21:04:13Z")

</div>

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