ItinerisLtd / trellis-slack-webhook-notify-during-deploy

Sends a deployment complete message to a Slack channel when Trellis deploys Bedrock.
MIT License
16 stars 6 forks source link

Deploy abort/fail notification #10

Open mike-sheppard opened 4 years ago

mike-sheppard commented 4 years ago

It'd be good to have a notification if the deployment fails/aborted by the user.

tangrufus commented 4 years ago

This is tricky with Trellis / Ansible. Ansible stops immediately when encounters errors.

Possible solution A - Use block + rescue

Not excatly what we need - This is an example how we trigger rollback if deployments break critical_urls

---
- import_playbook: deploy.yml

- hosts: web:&{{ env }}
  remote_user: "{{ web_user }}"
  gather_facts: false
  tasks:
    - block:
        - uri:
            url: "https://{{ wordpress_sites[site].site_hosts[0].canonical }}{{ item }}?cache-busting={{ ansible_date_time.epoch }}"
          loop: "{{ wordpress_sites[site].critical_urls }}"
          connection: local
      rescue:
        - include_role: 
            name: rollback
        - fail:
            msg: "Critical urls are not 200 okay. Site rolled back"

Possible solution B - Use handler

Maybe. Needs more digging.


More on https://docs.ansible.com/ansible/latest/user_guide/playbooks_error_handling.html#handlers-and-failure


Do you have any solution in mind?

mike-sheppard commented 4 years ago

I had a quick look into rescue after reading through this - https://www.petewilcock.com/ansible-slack-failure-handler/ but didn't get very far with the Trellis integration - it relies on all tasks being in the same block which doesn't look like we'll be able to do with the way Trellis' deploy playbook is currently organised? + rescue can't be used for the playbook (as far as I know)

Also, I might be wrong but the only way rescue could work with the current setup is adding it to each of the hooks/tasks which doesn't feel like a clean solution or easy to add and maintain with Trellis updates? Hoping I'm wrong!