Remove items from a variable with reject

Hello
I want to remove items from a variable using reject filter, I have something like this:

vars:
myvar:

  • item1
  • item2

List is the output of a command which contains contains item1, item2 , item3, item4, item5, I want to remove item1 and 2 ( from myvar ) from the list with the code below
but is not working, any idea what am I doing wrong of different way to accomplish this?

  • set_fact:
    list_of_items: “{{ list.stdout_lines | reject(‘search’, item ) | list }}”
    with_items: “{{ myvar }}”

Thanks
Regards

Use filter "difference". For example

    - set_fact:
        list_of_items: "{{ list.stdout_lines|difference(my_var) }}"

HTH,
  -vlado

That did the trick.!!!
Thank you so much!!!