Sends notifications to Slack before & after deployments via Trellis. Forked from trellis-slack-webhook-notify-during-deploy.
- Trellis v1.0.0 or later
- Trellis CLI
- Ansible v2.6 or later
- Slack webhook token
Add the role to galaxy.yml + check for the latest version.
---
roles:
#...
- name: trellis-slack-deploy-notifications
src: https://github.com/smithfield-studio/trellis-slack-deploy-notifications.git
version: 1.1.0 # Check for latest version on GitHubEnsure you have Trellis CLI installed, then run:
trellis galaxy installAdd the start & success tasks to the deploy_before & deploy_after deploy hooks in roles/deploy/defaults/main.yml.
deploy_before:
- '{{ playbook_dir }}/vendor/roles/trellis-slack-deploy-notifications/tasks/deploy_start.yml'
#...
deploy_after:
- '{{ playbook_dir }}/vendor/roles/trellis-slack-deploy-notifications/tasks/deploy_success.yml'Add your Slack webhook token(s) (end of the webhook URL) and channel into group_vars/{environment}/vault.yml
vault_wordpress_sites:
example.com.au:
slack_deploy_token:
- xxx/xxx/xxxxx
- xxx/xxx/xxxxx
env: #...See setup-trellis-cli to get the workflow setup. Then add the CI_JOB_URL to env var to your deploy workflow to include a link back to the running GitHub Action in the start notification.
name: Deploy site
env:
CI_JOB_URL: ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}You can choose to customise the deploy messages globally or per project. If you set both, the project config will take precedence. For each task (deploy start or deploy success) you can customise two elements: text and colour.
To set globally, in group_vars/all/helpers.yml:
slack_notify:
deploy_start_text: "has started deploying 🌱"
deploy_start_colour: "normal" # see https://docs.ansible.com/ansible/latest/collections/community/general/slack_module.html#parameter-color for accepted colours.
deploy_success_text: "has successfully deployed 🌿"
deploy_success_colour: "good"To set per project, in group_vars/{environment}/wordpress_sites.yml
wordpress_sites:
example.com.au:
slack_notify:
deploy_start_text: "is kicking up code from"With both of the above examples set, the deploy start message would be taken from the project config:
Dale Grant is kicking up code from
masterto example.com.au staging
- Visit the "Your Apps" page on Slack
- Create an App (e.g. "Deployment alerts") and enable "Incoming Webhooks"
- Setup a Webhook for your desired Workspace
- Copy the token from the Webhook URL for use in Installation
Note: Each Webhook can only post to one channel since Slack changed their API. You will need to set up a webhook per channel you wish to notify.
