# when ... is defined not woring as expected?

**URL:** <https://forum.ansible.com/t/when-is-defined-not-woring-as-expected/23235>\
**Category:** Ansible Project\
**Created:** [December 12, 2016, 2:18pm UTC](https://forum.ansible.com/t/when-is-defined-not-woring-as-expected/23235 "2016-12-12T14:18:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kai1](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@Kai1](https://forum.ansible.com/u/Kai1)\
**Post date:** [December 12, 2016, 2:18pm UTC](https://forum.ansible.com/t/when-is-defined-not-woring-as-expected/23235/1 "2016-12-12T14:18:28Z")

</div>

Hi there!

ansible-playbook (v. 2.2.0.0) throws an error message that I do not  
understand in my conext: "'pkg\_repo\_list' is undefined"

The task reads:

---

<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:** [December 12, 2016, 2:23pm UTC](https://forum.ansible.com/t/when-is-defined-not-woring-as-expected/23235/2 "2016-12-12T14:23:02Z")

</div>

when executes for each item in the loop and cannot short circuit the with\_ as documented here [http://docs.ansible.com/ansible/playbooks\_conditionals.html#loops-and-conditionals](http://docs.ansible.com/ansible/playbooks_conditionals.html#loops-and-conditionals)

---

<div class="post-metadata">

**Author:** ![Kai1](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@Kai1](https://forum.ansible.com/u/Kai1)\
**Post date:** [December 12, 2016, 2:53pm UTC](https://forum.ansible.com/t/when-is-defined-not-woring-as-expected/23235/3 "2016-12-12T14:53:09Z")

</div>

Hi Brian,

thanks a lot for the pointer / the solution. A double-default does the  
trick in this case 🙂

with\_items: "{{ (pkg\_repo\_list|default({})).repo\_keys | default() }}"

Cheers, Kai
