0

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?

2
  • Note: Normally I use the builtin ansible modules for everything, here we can see an exception.
    – peterh
    Commented Feb 29 at 13:10
  • I think you are thinking about something like that : Error handling. Where you can specify when it should fail, change or be fine. Commented Mar 7 at 5:51

1 Answer 1

1

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

Right, the documentation about Error handling in playbooks show how one Define failure or Define 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 was made for. The Examples show how to implement and use it then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.