Skip to content

Commit 05d1506

Browse files
Merge pull request #3 from teamcodeand/master
Move deploy webhooks to vault and allow different webhooks per site
2 parents e7eac57 + 359f5db commit 05d1506

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

README.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ deploy_after:
7272
- "{{ playbook_dir }}/vendor/roles/slack-notify/tasks/deploy_success.yml"
7373
```
7474
75-
Add your Slack webhook token (end of the webhook URL) and channel into `group_vars/all/main.yml`
75+
Add your Slack webhook token(s) (end of the webhook URL) and channel into `group_vars/{environment}/vault.yml`
7676

7777
```yaml
78-
# group_vars/all/main.yml
79-
slack_notifications:
80-
- name: Organisation1
81-
token: XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXX
82-
channel: "#site-status"
83-
- name: Organisation2
84-
token: XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXX
85-
channel: "#deployments"
78+
# group_vars/{environment}/vault.yml
79+
vault_wordpress_sites:
80+
example.com.au:
81+
slack_deploy_token:
82+
- XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXX
83+
- XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXX
84+
env:
85+
...
8686
```
8787

8888
## Usage
@@ -98,6 +98,8 @@ slack_notifications:
9898
3. Setup a Webhook for your desired Workspace
9999
4. Copy the Webhook URL for use in [Installation](#installation)
100100

101+
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.
102+
101103
## See Also
102104

103105
- [Incoming WebHooks for Slack](https://get.slack.help/hc/en-us/articles/115005265063-Incoming-webhooks-for-Slack)

tasks/deploy_start.yml

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
---
22
- name: Send initial deployment notification to Slack
33
slack:
4-
token: "{{ item.token }}"
5-
channel: "{{ item.channel }}"
4+
token: "{{ slack_deploy_token }}"
65
attachments:
76
- text: "*{{ lookup('pipe', 'git config user.name') }}* has started deploying {{ site }} to *<https://{{ project.site_hosts | map(attribute='canonical') | first }}|{{ env }}>*"
87
color: warning
9-
loop: "{{ slack_notifications }}"
8+
with_items: "{{ vault_wordpress_sites[site].slack_deploy_token }}"
9+
loop_control:
10+
loop_var: slack_deploy_token
1011
when:
11-
- slack_notifications is defined
12-
- slack_notifications | length > 0
12+
- vault_wordpress_sites[site].slack_deploy_token is defined
13+
- vault_wordpress_sites[site].slack_deploy_token | length > 0
1314
delegate_to: localhost
1415
ignore_errors: yes

tasks/deploy_success.yml

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515

1616
- name: Send successful deployment notification to Slack
1717
slack:
18-
token: "{{ item.token }}"
19-
channel: "{{ item.channel }}"
18+
token: "{{ slack_deploy_token }}"
2019
attachments:
2120
- text: "*{{ git_username }}* successfully deployed {{ site }} to *<{{ target_env_url }}>* {% if using_github %} [<{{ github_commit_url }}|deployed commit>] {% else %} [{{ git_clone.after }}] {% endif %}"
2221
color: good
23-
loop: "{{ slack_notifications }}"
22+
with_items: "{{ vault_wordpress_sites[site].slack_deploy_token }}"
23+
loop_control:
24+
loop_var: slack_deploy_token
2425
when:
25-
- slack_notifications is defined
26-
- slack_notifications | length > 0
26+
- vault_wordpress_sites[site].slack_deploy_token is defined
27+
- vault_wordpress_sites[site].slack_deploy_token | length > 0
2728
delegate_to: localhost
2829
ignore_errors: yes

0 commit comments

Comments
 (0)