<blockquote>
<p><strong><em>... it could be encoded most easily in the exit code of the script ...</em></strong></p>
</blockquote>
<p>Right, the documentation about <a href="https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html" rel="nofollow noreferrer">Error handling in playbooks</a> show how one <a href="https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html#defining-failure" rel="nofollow noreferrer">Define failure</a> or <a href="https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html#defining-changed" rel="nofollow noreferrer">Define <code>changed</code></a>. This will work for <code>script</code>, <code>shell</code>, <code>command</code>, as well Custom Modules.</p>
<blockquote>
<p><strong><em>... but any other scriptable option is to me okay.</em></strong></p>
</blockquote>
<p>That is what the <a href="https://docs.ansible.com/ansible/latest/collections/community/general/diy_callback.html" rel="nofollow noreferrer"><code>diy</code> callback – Customize the output</a> was made for. The <a href="https://docs.ansible.com/ansible/latest/collections/community/general/diy_callback.html#examples" rel="nofollow noreferrer">Examples</a> show how to implement and use it then.</p>

CC BY-SA 4.0
2024-03-11T11:51:20.330Z
2024-03-11T11:51:20.330Z
U880D
<p>There are various Ansible modules which can execute my own-written script (ansible.builtin.script, ansible.builtin.shell, ansible.builtin.command). However, I would like to determine the color of the task as usual:</p>
<ul>
<li>red if execution was not successful</li>
<li>yellow on successful execution resulted a modification of the system</li>
<li>and green if successed an no change was needed.</li>
</ul>
<p>I think, it could be encoded most easily in the exit code of the script, but any other scriptable option is to me okay.</p>
<p>Unfortunately, all the relevant modules I have found until now, simply completely ignore the result.</p>
<p>What to do?</p>

CC BY-SA 4.0
2024-02-29T13:10:14.427Z
Note: Normally I use the builtin ansible modules for everything, here we can see an exception.
peterh
CC BY-SA 4.0
2024-03-07T05:51:17.810Z
I think you are thinking about something like that : [Error handling](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html). Where you can specify when it should fail, change or be fine.
Marius_Couet
<ansible><shell-script>
How to determine the color of a shell script task in Ansible?
peterh
# How to determine the color of a shell script task in Ansible?

(Asked by: username_0 on 2024-02-29)

There are various Ansible modules which can execute my own-written script (ansible.builtin.script, ansible.builtin.shell, ansible.builtin.command). However, I would like to determine the color of the task as usual:

* red if execution was not successful
* yellow on successful execution resulted a modification of the system
* and green if successed an no change was needed.

I think, it could be encoded most easily in the exit code of the script, but any other scriptable option is to me okay.

Unfortunately, all the relevant modules I have found until now, simply completely ignore the result.

What to do?

**Tags:** ansible, shell-script

> **Comments:**
> **username_0**: Note: Normally I use the builtin ansible modules for everything, here we can see an exception.  
> **username_1**: I think you are thinking about something like that : [Error handling](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html). Where you can specify when it should fail, change or be fine.  

---

## 1 answers

### Answer by username_2 on 2024-03-11. Score: 1

> ***... it could be encoded most easily in the exit code of the script ...***

Right, the documentation about [Error handling in playbooks](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html) show how one [Define failure](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html#defining-failure) or [Define `changed`](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html#defining-changed). This will work for `script`, `shell`, `command`, as well Custom Modules.

> ***... but any other scriptable option is to me okay.***

That is what the [`diy` callback – Customize the output](https://docs.ansible.com/ansible/latest/collections/community/general/diy_callback.html) was made for. The [Examples](https://docs.ansible.com/ansible/latest/collections/community/general/diy_callback.html#examples) show how to implement and use it then.


---

