how to write custom message when specific item is not available in ansible_facts (say disk sdb is not available )

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

Use the default filter
{{ ansible_devices.sdd.size | default('NONE') }}

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.

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