# Using custom message when a task fails

**URL:** <https://forum.ansible.com/t/using-custom-message-when-a-task-fails/20690>\
**Category:** Ansible Project\
**Created:** [February 26, 2016, 4:30pm UTC](https://forum.ansible.com/t/using-custom-message-when-a-task-fails/20690 "2016-02-26T16:30:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![abraham\_johnson](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@abraham\_johnson](https://forum.ansible.com/u/abraham_johnson)\
**Post date:** [February 26, 2016, 4:30pm UTC](https://forum.ansible.com/t/using-custom-message-when-a-task-fails/20690/1 "2016-02-26T16:30:42Z")

</div>

Hello

I am using ansible version 1.8.2.  
I would like to know if its possible to add a custom message when a task fails.  
I understand that one way to do is

- name: Run Shell Command  
shell: ./script.sh  
register: results  
ignore\_errors: yes

- fails: msg=“Command was not executed successfully”  
when: results.rc != 0

But to reduce the lines of code failed\_when was introduced.

- name: Run Shell Command  
shell: ./script.sh  
register: results  
failed\_when: “results.rc != 0”

However when using failed\_when I loose the option to have a custom message. Is there a way to have custom when using failed\_when or better way to implement this.

Howevre I found that from Ansible 2.0 there is concept of Blocks that can be a solution to my problem. But I want to how it can be implemented in version \< 2.0

Thanks for your answers  
AJ

---

<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:** [February 26, 2016, 7:55pm UTC](https://forum.ansible.com/t/using-custom-message-when-a-task-fails/20690/2 "2016-02-26T19:55:25Z")

</div>

no, pretty much what you already noted are the only options.
