# Handling "file not found" for the slurp module

**URL:** <https://forum.ansible.com/t/handling-file-not-found-for-the-slurp-module/37146>\
**Category:** Ansible Project\
**Created:** [September 27, 2022, 3:10am UTC](https://forum.ansible.com/t/handling-file-not-found-for-the-slurp-module/37146 "2022-09-27T03:10:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shabir\_Abdul\_Samdh](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@Shabir\_Abdul\_Samdh](https://forum.ansible.com/u/Shabir_Abdul_Samdh)\
**Post date:** [September 27, 2022, 3:10am UTC](https://forum.ansible.com/t/handling-file-not-found-for-the-slurp-module/37146/1 "2022-09-27T03:10:04Z")

</div>

Hello All,

I am trying to read a file from a remote host and do some checks on its content using the [slurp module](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/slurp_module.html). However I want these checks to run only if the file exists. If the file is not found I want to skip some of the following tasks.

However, it seems like the slurp module fails when the file I am looking for is not found. Is there a way to handle the case of a file not being there gracefully when using slurp?

Thank you very much  
Best regards

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [September 27, 2022, 3:45am UTC](https://forum.ansible.com/t/handling-file-not-found-for-the-slurp-module/37146/2 "2022-09-27T03:45:20Z")

</div>

Add a stat task first and use the result to conditionally run the slurp task

---

<div class="post-metadata">

**Author:** ![Shabir\_Abdul\_Samdh](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@Shabir\_Abdul\_Samdh](https://forum.ansible.com/u/Shabir_Abdul_Samdh)\
**Post date:** [September 27, 2022, 1:56pm UTC](https://forum.ansible.com/t/handling-file-not-found-for-the-slurp-module/37146/3 "2022-09-27T13:56:25Z")

</div>

Yup! That works. Thank you.
