How to filter hosts with 'nr.with_processors'

I am trying to use the Processors to print the result of every task and the subtasks of my main task. I am not understanding how I can use ‘nr.with_processors’ to filter on a particular type of hosts and also apply my custom processor for processing the results.

For e.g : I pass ‘role’ as an external variable. I could use the Filter function to filter out hosts by : devices = nr.filter(F(role=role))

However, the documentation says :

# similary to .filter, with_processors returns a copy of the nornir object but with’
# the processors assigned to it.

How can I use nr.with_processors to achieve the desired result.

Hello All,

I figured out what to do my self. I was a little confused at the beginning. However, I will post how I approached for anyone else who is also puzzled.

# Filter the hosts based on your criteria
devices = nr.filter(F(role=role))

# Add the Processor to the selected devices
nr_with_processors = devices.with_processors([PrintResult()])

# Run the task with the processors
nr_with_processors.run(name=‘main task’,task=execute)