# ignoring an empty list when using with\_flattened

**URL:** <https://forum.ansible.com/t/ignoring-an-empty-list-when-using-with-flattened/17617>\
**Category:** Ansible Project\
**Created:** [February 25, 2015, 3:39am UTC](https://forum.ansible.com/t/ignoring-an-empty-list-when-using-with-flattened/17617 "2015-02-25T03:39:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joel\_Parker](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@Joel\_Parker](https://forum.ansible.com/u/Joel_Parker)\
**Post date:** [February 25, 2015, 3:39am UTC](https://forum.ansible.com/t/ignoring-an-empty-list-when-using-with-flattened/17617/1 "2015-02-25T03:39:47Z")

</div>

I have the following in a role:

- name: Create readonly user groups  
group:  
name={{ item.name|default }}  
gid={{ item.gid|default }}  
with\_flattened:

- users\_ro

- host\_users\_ro  
ignore\_errors: yes

- name: Create readonly users  
user:  
name={{ item.name|default }}  
comment={{ item.fullname|default }}  
groups=users  
group={{ item.name|default }}  
shell=/bin/bash  
createhome=yes  
uid={{ item.uid|default }}  
password=“\*”  
update\_password=always  
with\_flattened:

- users\_ro

- host\_users\_ro

ignore\_errors: yes

I have use cases where I know that various combinations of the groups I’m looping through (users\_ro and host\_users\_ro, in this example) are empty/undefined. I’d prefer to not use the default filter for each of my variables I’m referencing here, but this, in combination with ignore\_errors, appears to be the only way I can get the play to continue if one of the lists is undefined.

If the list is undefined, I get an error, and if I use something like host\_users\_ro|default(omit), I get an error on ‘name’ not being defined instead.

Simply using ignore\_errors: yes without using the default filter results in a fatal error and ansible also does not continue.

I assume this is expected/by design. But is there no way to tell ansible to ignore when a list is undefined or empty? I’d much rather have ansible continue if a list isn’t defined, rather than having to define an empty list with an empty user, just so ansible can create an ‘empty’ user on the system.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 25, 2015, 2:33pm UTC](https://forum.ansible.com/t/ignoring-an-empty-list-when-using-with-flattened/17617/2 "2015-02-25T14:33:22Z")

</div>

You already know the way to do this: "mylist |default()", you can do  
this on the list, so you would not need to do that on each module  
argument.

Also, 'omit' is for removing module parameters, not for skipping an  
item in a loop, and, of course, it does not work well with required  
parameters.

---

<div class="post-metadata">

**Author:** ![Joel\_Parker](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@Joel\_Parker](https://forum.ansible.com/u/Joel_Parker)\
**Post date:** [February 25, 2015, 7:00pm UTC](https://forum.ansible.com/t/ignoring-an-empty-list-when-using-with-flattened/17617/3 "2015-02-25T19:00:30Z")

</div>

works perfectly… much thanks.

when working after a long day… it’s easy to get lost with the changes being made, once you start to get a little desperate 😉

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 25, 2015, 7:02pm UTC](https://forum.ansible.com/t/ignoring-an-empty-list-when-using-with-flattened/17617/4 "2015-02-25T19:02:31Z")

</div>

We all get tunnel vision, you already had the solution, just needed someone to turn your head to it 😉
