# how to write custom message when specific item is not available in ansible\_facts (say disk sdb is not available )

**URL:** <https://forum.ansible.com/t/how-to-write-custom-message-when-specific-item-is-not-available-in-ansible-facts-say-disk-sdb-is-not-available/31737>\
**Category:** Ansible Project\
**Created:** [November 27, 2019, 3:56pm UTC](https://forum.ansible.com/t/how-to-write-custom-message-when-specific-item-is-not-available-in-ansible-facts-say-disk-sdb-is-not-available/31737 "2019-11-27T15:56:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![prat\_007](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@prat\_007](https://forum.ansible.com/u/prat_007)\
**Post date:** [November 27, 2019, 3:56pm UTC](https://forum.ansible.com/t/how-to-write-custom-message-when-specific-item-is-not-available-in-ansible-facts-say-disk-sdb-is-not-available/31737/1 "2019-11-27T15:56:23Z")

</div>

i am collecting some output from ansible\_facts and writing them to a file on remote server with the help of copy module (content and dest)

i need to write as NONE if some item is not available on server (say disk sdb is not present on server). How can i write NONE if disk sdb is not found

my playbook is as below

- copy:  
content: |  
Memory = {{ ansible\_memtotal\_mb }}

Size of disk sda = {{ ansible\_devices.sda.size }}  
dest: /tmp/test

but if disk sdb is not available on server how to check and write custom message like below  
Size of disk sdb = NONE

---

<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:** [November 27, 2019, 4:01pm UTC](https://forum.ansible.com/t/how-to-write-custom-message-when-specific-item-is-not-available-in-ansible-facts-say-disk-sdb-is-not-available/31737/2 "2019-11-27T16:01:42Z")

</div>

Use the default filter  
{{ ansible\_devices.sdd.size | default('NONE') }}

---

<div class="post-metadata">

**Author:** ![prat\_007](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@prat\_007](https://forum.ansible.com/u/prat_007)\
**Post date:** [November 27, 2019, 4:17pm UTC](https://forum.ansible.com/t/how-to-write-custom-message-when-specific-item-is-not-available-in-ansible-facts-say-disk-sdb-is-not-available/31737/3 "2019-11-27T16:17:04Z")

</div>

Hi Kai,

Thanks for your prompt reply. it worked.

Any reference to the ansible doc mentioning more about this default filter. i would like to more about it.

---

<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:** [November 27, 2019, 4:35pm UTC](https://forum.ansible.com/t/how-to-write-custom-message-when-specific-item-is-not-available-in-ansible-facts-say-disk-sdb-is-not-available/31737/4 "2019-11-27T16:35:49Z")

</div>

Searching for "ansible default filter" on your preferred search engine will give that for you.
