running a task with ‘when: users is defined’ works fine for hosts that have that variable. for hosts that dont, the play still runs, but gives a warning that in the future, an undefined variable will be a fatal error. is there another way of running tasks based on the existence of a given var?
You should generally provide your full task, so I’m going to take a guess here.
I am pretty sure the problem is that you are using with_items: users also. The problem is that when statements are evaluated afterwith_items, since the when statement is evaluated per item in the loop.