# Lookup plugin returns failure

**URL:** <https://forum.ansible.com/t/lookup-plugin-returns-failure/24843>\
**Category:** Ansible Project\
**Created:** [June 28, 2017, 4:21pm UTC](https://forum.ansible.com/t/lookup-plugin-returns-failure/24843 "2017-06-28T16:21:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guy\_Matz1](https://avatars.discourse-cdn.com/v4/letter/g/b5e925/32.png) [@Guy\_Matz1](https://forum.ansible.com/u/Guy_Matz1)\
**Post date:** [June 28, 2017, 4:21pm UTC](https://forum.ansible.com/t/lookup-plugin-returns-failure/24843/1 "2017-06-28T16:21:47Z")

</div>

Peeps,  
Hey! I have an issue with the credstash plugin . . . if it can’t complete the lookup it simply vomits an AnsibleError, so it’s not possible to do something like:  
{{ lookup(‘credstash’, ‘blah’, ‘bling’) | default(‘Sane default here’) }}

Anyone know of a way around this? So that a failed lookup can have a default?

Thanks,  
Guy

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 28, 2017, 6:04pm UTC](https://forum.ansible.com/t/lookup-plugin-returns-failure/24843/2 "2017-06-28T18:04:19Z")

</div>

I think you you need to split in two, something like this

&nbsp;&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;some\_var: "{{ lookup('credstash', 'blah', 'bling') }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ignore\_errors: yes

&nbsp;&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;some\_var: Sane default here  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: some\_var not defined

Another way

&nbsp;&nbsp;&nbsp;- debug: msg="{{ lookup('credstash', 'blah', 'bling') }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: result  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ignore\_errors: yes

&nbsp;&nbsp;&nbsp;- debug: msg="Sane default here"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: result | failed

---

<div class="post-metadata">

**Author:** ![Guy\_Matz1](https://avatars.discourse-cdn.com/v4/letter/g/b5e925/32.png) [@Guy\_Matz1](https://forum.ansible.com/u/Guy_Matz1)\
**Post date:** [June 28, 2017, 9:04pm UTC](https://forum.ansible.com/t/lookup-plugin-returns-failure/24843/3 "2017-06-28T21:04:36Z")

</div>

YUCH!! Thanks! 🙂
