Skip to content

Commit

Permalink
Add ansible-playbook wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
hellais committed Dec 7, 2024
1 parent 467b99c commit 0989052
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
12 changes: 12 additions & 0 deletions ansible/ansible-playbook
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -ue

## ansible-playbook is a wrapper script used to send a notification to slack
# whenever a new ansible deploy is triggered

ANSIBLE_SLACK_CMD=`printf "%q " "$0" "$@"`
ANSIBLE_SLACK_CMD="${ANSIBLE_SLACK_CMD% }" # strip trailing whitespace
export ANSIBLE_SLACK_CMD

ansible localhost --module-name include_role --args name=notify-slack
ansible-playbook "$@"
8 changes: 4 additions & 4 deletions ansible/inventory
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[all:children]
htz-fsn
ghs-ams
htz_fsn
ghs_ams

## Role tags

Expand All @@ -12,13 +12,13 @@ data3.htz-fsn.prod.ooni.nu

## Location tags

[htz-fsn]
[htz_fsn]
data.ooni.org
monitoring.ooni.org
notebook.ooni.org
data1.htz-fsn.prod.ooni.nu
data2.htz-fsn.prod.ooni.nu
data3.htz-fsn.prod.ooni.nu

[ghs-ams]
[ghs_ams]
openvpn-server1.ooni.io
8 changes: 8 additions & 0 deletions ansible/roles/notify-slack/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: "notify #ooni-bots at openobservatory.slack.com"
slack:
token: "{{ lookup('amazon.aws.aws_ssm', '/oonidevops/secrets/ansible_slack_token', profile='oonidevops_user_prod') }}"
channel: "#ooni-bots"
msg: "{{ lookup('template', 'notify-slack.j2') }}"
delegate_to: localhost
run_once: true
10 changes: 10 additions & 0 deletions ansible/roles/notify-slack/templates/notify-slack.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% set cleanness = 'dirty' if lookup('pipe', 'git status -s') else 'clean' %}
{% set head = lookup('pipe', 'git rev-parse HEAD') %}
{% set head7 = lookup('pipe', 'git rev-parse --short HEAD') %}
{% set branch = lookup('pipe', 'git describe --always --exact-match --all HEAD') | replace('heads/', '') %}
{% set user_slug = lookup('pipe', 'whoami') + '@' + lookup('pipe', 'hostname') %}
{% if lookup('file', '~/.ooni-sysadmin/user_slug', errors='ignore') %}
{% set user_slug = lookup('file', '~/.ooni-sysadmin/user_slug') %}
{% endif %}

{{ user_slug }} runs `{{ lookup('env', 'ANSIBLE_SLACK_CMD') }}` on top of {{ cleanness }} `<https://github.com/ooni/sysadmin/commit/{{ head }}|{{ head7 }}>` (`{{ branch }}`)

0 comments on commit 0989052

Please sign in to comment.