Reputation: 2495
I would like to get a e-mail when the project failed. So I've created a task at the end of the file wich sends me an e-mail. The problem is now that when a task failed also the hole project failed and the e-mail task wouldn't triggered.
Can somebody help me?
(I'm using Ansible Tower)
Upvotes: 0
Views: 4908
Reputation: 60039
You should create a callback plugin where you can react on any situation like failed tasks.
Here is an example for a HipChat notification. It's not too hard to modify it to send email messages directly with a local or remote smtp.
Edit: Actually there is a mail callback plugin.
Upvotes: 2
Reputation: 355
ansible tower itself provide this feature you can create a notification template as described in https://docs.ansible.com/ansible-tower/3.0/html/userguide/notifications.html#id1
than from notification option of workflow template, you can select this template on failure or success
Upvotes: 1
Reputation: 335
What if you send the mail from shell depending on the return code of ansible-playbook
command ?
here's a sample shell script:
ANSIBLE_OUTPUT=$(ansible-playbook site.yml -K)
if [ $? != 0 ]; then
echo "playbook failed! OUTPUT: ${ANSIBLE_OUTPUT}" | mail -s "playbook results" your_email@your_email_domain
else
echo "playbook executed successfully!" | mail -s "playbook results" your_email@your_email_domain
fi
Upvotes: 1