I found an odd behaviour with with_first_found, roles and the copy module that I document here
https://github.com/willthames/copy_with_null_items/commit/fd924a7045748cdb193f7cf27d5a03915c2a4458
(basically if no file is found in the list given, it copies the first file it finds from roles/files, which is unlikely what anyone wants).
I came up with a fix [1] for the copy module that addresses that behaviour (check for not source rather than source=None). However, it’s worth discussing whether that’s the best approach. I wonder if tasks with empty with_ lists should just be skipped with a suitable message. After all, it’s not just with_first_found - with_fileglob can also return an empty list, and it’s not out of the question to pass a variable to with_items that might be the empty list.
Looking at the docs for first_found.py, there is a skip parameter, but I would expect any module to either skip or fail when items are empty, not behave in a really weird way.
So to conclude, there’s definitely a bug, I’m just not sure actually what expected behaviour should be and where that expected behaviour should be enforced.
Will
[1] https://github.com/ansible/ansible/pull/9689. I can always convert this to an issue if it helps.