# with\_ and empty item lists and the copy module in particular

**URL:** <https://forum.ansible.com/t/with-and-empty-item-lists-and-the-copy-module-in-particular/16936>\
**Category:** Ansible Developer\
**Created:** [December 2, 2014, 10:43am UTC](https://forum.ansible.com/t/with-and-empty-item-lists-and-the-copy-module-in-particular/16936 "2014-12-02T10:43:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [December 2, 2014, 10:43am UTC](https://forum.ansible.com/t/with-and-empty-item-lists-and-the-copy-module-in-particular/16936/1 "2014-12-02T10:43:34Z")

</div>

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](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](https://github.com/ansible/ansible/pull/9689). I can always convert this to an issue if it helps.
