Why Nerve for Ansible
Ansible playbooks that run from cron, CI, or AWX can fail silently. A changed SSH key, a package mirror outage, or a task timeout — and your infrastructure drifts. Nerve sends a push the moment a run exits non-zero.
Shell wrapper (simplest)
#!/bin/bash
set -euo pipefail
export NERVE_DSN="nerve://TOKEN:[email protected]"
if ansible-playbook -i inventory.yml site.yml 2>&1 | tee /tmp/ansible-output.log; then
echo "Ansible OK: site.yml" | nerve send
else
echo "ANSIBLE FAILED: site.yml" | nerve send --severity critical
tail -20 /tmp/ansible-output.log | nerve send --severity alert
fi
Ansible handler (in-playbook)
Use a rescue block to catch failures inside the playbook itself.
---
- hosts: webservers
tasks:
- block:
- name: Deploy application
ansible.builtin.shell: /opt/deploy.sh
- name: Restart service
ansible.builtin.systemd:
name: my-app
state: restarted
rescue:
- name: Notify Nerve on failure
ansible.builtin.shell: |
echo "Ansible FAILED on {{ inventory_hostname }}: {{ ansible_failed_task.name }}" \
| nerve send --severity critical
environment:
NERVE_DSN: "{{ nerve_dsn }}"
delegate_to: localhost
Callback plugin approach
For broad coverage, use Ansible's callback system to notify on any play failure.
# ansible.cfg
[defaults]
callback_whitelist = nerve_notify
# In your callback plugin or wrapper:
# Check PLAY_RECAP for unreachable/failed hosts
ansible-playbook site.yml 2>&1 | tee /tmp/ansible.log
FAILED=$(grep -c "failed=" /tmp/ansible.log | grep -v "failed=0" || true)
if [ -n "$FAILED" ]; then
grep "failed=" /tmp/ansible.log | nerve send --severity critical
fi
Scheduled runs (cron)
# /etc/cron.d/ansible-nightly
30 2 * * * ansible /usr/local/bin/ansible-with-nerve.sh
GitHub Actions + Ansible
- name: Run Ansible
id: ansible
run: ansible-playbook -i inventory.yml site.yml
continue-on-error: true
- name: Notify on failure
if: steps.ansible.outcome == 'failure'
env:
NERVE_DSN: ${{ secrets.NERVE_DSN }}
run: echo "Ansible FAILED: ${{ github.repository }}" | nerve send --severity critical
Quick start
go install github.com/nerve-ink/nerve-cli/cmd/nerve@latest
export NERVE_DSN="nerve://TOKEN:[email protected]"
echo "Ansible FAILED: site.yml (3 hosts unreachable)" | nerve send --severity critical
FAQ
How do I get notified when an Ansible playbook fails?
Wrap your ansible-playbook command in a script that checks the exit code, or use a rescue block inside the playbook to call nerve send.
Does Nerve work with Ansible Tower / AWX?
Yes. Add a notification step in your workflow template or use a webhook bridge.
Can I get alerts from scheduled runs?
Yes. Wrap the command with exit code checking and pipe failures to nerve send.