Skip to content

Commit 63a183e

Browse files
author
Drone CI
committed
license added. refs: #92124
0 parents  commit 63a183e

16 files changed

+1202
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.log
2+
*.pyc
3+
**/__pycache__/
4+
.env
5+
.secrets
6+
payload.json

.yamllint

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extends: default
2+
3+
rules:
4+
braces:
5+
max-spaces-inside: 1
6+
level: error
7+
brackets:
8+
max-spaces-inside: 1
9+
level: error
10+
line-length: disable
11+
truthy: disable

LICENSE.md

+641
Large diffs are not rendered by default.

README.md

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# webhook
2+
3+
[![Build Status](https://drone.osshelp.ru/api/badges/ansible/webhook/status.svg)](https://drone.osshelp.ru/ansible/webhook)
4+
5+
Ansible role for [webhook](https://github.com/adnanh/webhook) installation and configuration.
6+
7+
## Usage (example)
8+
9+
```yaml
10+
- hosts: all
11+
roles:
12+
- { role: webhook,
13+
webhook: {
14+
hotreload: true,
15+
listen: '0.0.0.0',
16+
port: 8080,
17+
prefix: 'webhook',
18+
verbose: false,
19+
hooks: [ 'deployment' ],
20+
headers: [ 'X-Custom-Header=some-value' ]
21+
}
22+
}
23+
```
24+
25+
## Available parameters
26+
27+
### Main
28+
29+
Short description here.
30+
31+
| Param | Description |
32+
| -------- | -------- |
33+
| user | User to create for webhook-server. |
34+
| extra_groups | Extra groups to add created user to. |
35+
| download_url | Url to get binary from. |
36+
| checksum_url | Url to get checksums from. |
37+
| download_dir | Absolute path to temporal dir for binary placement before moving to more suitable dir. |
38+
| binary_dir | Absolute path to directory where binary will be placed. |
39+
| scripts_dir | Absolute path to directory where scripts will be placed. |
40+
| conf_dir | Absolute path to directory with webhook-server configuration files. |
41+
| logs_dir | Absolute path to directory that will be used for webhook-server logs storage. |
42+
| templates_dir | Absolute path to directory that will be used for initial-setup script and templates placement. |
43+
| webhook_hooks_source_dir | Relative path to hooks (j2-templates of jsons) in current repository |
44+
| webhook_scripts_source_dir | Relative path to scripts templates in current repository |
45+
| default_setup | Whether to install [deploy-functions](https://gitea.osshelp.ru/ansible/deploy-functions) and additional stuff for initial setup via deployment. |
46+
| default_sudoers | Whether to generate sudoers.d config |
47+
| webhook_sudo_scripts | List of script names in scripts_dir for enabling sudo access to |
48+
49+
### Webhook-server params
50+
51+
You can control all of the params via overriding webhook array (see defaults/main.yml)
52+
53+
## FAQ
54+
55+
### ERROR: Found unknown escape character
56+
57+
If there is an error like this in logs:
58+
59+
> [webhook] couldn't load hooks from file! error converting YAML to JSON: yaml: line 63: found unknown escape character
60+
61+
Then you should use double character ‘\’ in your regexps. For example:
62+
63+
```yaml
64+
"regex": "^\\w+(\\d+)?(-\\w+)?-(prod)$",
65+
```
66+
67+
## Useful links
68+
69+
- [Official documentation](https://github.com/adnanh/webhook/tree/master/docs)
70+
- [Our article](https://oss.help/kb3989)
71+
72+
## TODO
73+
74+
- add logrotate config for files in logs_dir
75+
76+
## License
77+
78+
GPL3
79+
80+
## Author
81+
82+
OSSHelp Team, see <https://oss.help>

defaults/main.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
user: webhook
3+
extra_groups: []
4+
download_url: "https://oss.help/builds/pub/webhook/2.6.10/webhook"
5+
checksum_url: "https://oss.help/builds/pub/webhook/2.6.10/SHA256SUMS"
6+
download_dir: /tmp
7+
scripts_dir: /usr/local/bin
8+
binary_dir: /usr/local/sbin
9+
conf_dir: /etc/webhook
10+
logs_dir: /var/log/webhook
11+
templates_dir: /usr/local/osshelp/webhook
12+
webhook_hooks_source_dir: hooks
13+
webhook_scripts_source_dir: scripts
14+
15+
default_setup: false
16+
default_sudoers: true
17+
18+
webhook:
19+
hotreload: true
20+
listen: '0.0.0.0'
21+
port: '9000'
22+
prefix: 'webhook'
23+
verbose: true
24+
hooks: []
25+
headers: []
26+
27+
templates: []
28+
29+
webhook_sudo_scripts: [ lxhelper ]

handlers/main.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- name: reload webhook unit
3+
systemd:
4+
daemon_reload: yes
5+
6+
- name: restart webhook service
7+
service:
8+
name: webhook
9+
state: restarted

meta/main.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
galaxy_info:
3+
author: OSSHelp team
4+
description: install webhook
5+
company: OSSHelp
6+
license: GPLv3
7+
min_ansible_version: 1.2
8+
platforms:
9+
- name: Ubuntu
10+
versions:
11+
- xenial
12+
bionic
13+
galaxy_tags:
14+
- webhook

requirements.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
3+
- name: deploy-functions
4+
src: https://oss.help/ansible/pub/roles/d/deploy-functions-stable.tar.gz
5+
6+
- name: lxc-reboot
7+
src: https://oss.help/ansible/pub/roles/l/1/lxc-reboot-stable.tar.gz

tasks/main.yml

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
---
2+
# tasks file for webhook
3+
4+
- name: create group
5+
group:
6+
name: "{{ user }}"
7+
system: yes
8+
state: present
9+
10+
- name: create user
11+
user:
12+
name: "{{ user }}"
13+
group: "{{ user }}"
14+
groups: "{{ extra_groups }}"
15+
shell: "/bin/bash"
16+
system: yes
17+
comment: "Webhook user"
18+
state: present
19+
20+
- name: create binary dir if necesary
21+
file:
22+
path: "{{ binary_dir }}"
23+
state: directory
24+
25+
- name: create logs dir if necesary
26+
file:
27+
path: "{{ logs_dir }}"
28+
state: directory
29+
owner: "root"
30+
group: "{{ user }}"
31+
mode: 0770
32+
33+
- name: download binary
34+
get_url:
35+
url: "{{ download_url }}"
36+
checksum: "sha256:{{ checksum_url }}"
37+
dest: "{{ binary_dir }}/webhook"
38+
owner: "root"
39+
group: "root"
40+
mode: 0755
41+
when: not ansible_check_mode
42+
notify: restart webhook service
43+
44+
- name: create conf dir if necessary
45+
file:
46+
path: "{{ conf_dir }}"
47+
state: directory
48+
owner: "root"
49+
group: "{{ user }}"
50+
mode: 0750
51+
52+
- name: copy demo webhook
53+
template:
54+
src: webhook-demo.j2
55+
dest: "{{ conf_dir }}/demo.json"
56+
owner: root
57+
group: "{{ user }}"
58+
mode: 0640
59+
when: not webhook.hooks
60+
notify: restart webhook service
61+
62+
- name: 'copy webhook'
63+
template:
64+
src: '{{ webhook_hooks_source_dir }}/{{ item }}.j2'
65+
dest: "{{ conf_dir }}/{{ item | basename }}.json"
66+
owner: root
67+
group: "{{ user }}"
68+
mode: 0640
69+
when: webhook.hooks is defined and webhook.hooks | length > 0
70+
with_items: "{{ webhook.hooks }}"
71+
notify: restart webhook service
72+
73+
- name: 'copy scripts'
74+
template:
75+
src: '{{ webhook_scripts_source_dir }}/webhook-{{ item }}.j2'
76+
dest: "{{ scripts_dir }}/webhook-{{ item | basename }}"
77+
owner: root
78+
group: "{{ user }}"
79+
mode: 0750
80+
when: webhook.scripts is defined and webhook.scripts | length > 0
81+
with_items: "{{ webhook.scripts }}"
82+
notify: restart webhook service
83+
84+
- name: include deploy-functions
85+
include_role:
86+
name: deploy-functions
87+
when: default_setup and deploy_functions_installed is not defined
88+
89+
- name: create tpl directory
90+
file:
91+
path: "{{ templates_dir }}"
92+
state: directory
93+
owner: "root"
94+
group: "{{ user }}"
95+
mode: 0750
96+
when: default_setup
97+
98+
- name: place initial-setup script
99+
template:
100+
src: initial-setup.j2
101+
dest: "{{ templates_dir }}/initial-setup"
102+
owner: "root"
103+
group: "{{ user }}"
104+
mode: 0750
105+
when: default_setup
106+
107+
- name: 'copy templates'
108+
copy:
109+
src: 'templates/{{ item }}'
110+
dest: "{{ templates_dir }}/{{ item | basename }}"
111+
owner: root
112+
group: "{{ user }}"
113+
mode: 0750
114+
when: default_setup and templates
115+
with_items: "{{ templates }}"
116+
117+
- name: copy systemd unit file
118+
template:
119+
src: webhook-systemd-unit.j2
120+
dest: "/etc/systemd/system/webhook.service"
121+
owner: root
122+
group: root
123+
mode: 0644
124+
notify:
125+
- reload webhook unit
126+
- restart webhook service
127+
128+
- name: enable service
129+
service:
130+
name: webhook
131+
state: started
132+
enabled: yes
133+
134+
- name: install sudoers config
135+
template:
136+
src: sudoers.j2
137+
dest: "/etc/sudoers.d/{{ user }}"
138+
owner: root
139+
group: root
140+
mode: 0440
141+
when: default_sudoers
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
[
2+
{
3+
"id": "lxhelper-deployment",
4+
"response-message": "Starting LXHelper deployment ...",
5+
"execute-command": "{{ scripts_dir | default('/usr/local/bin', true) }}/webhook-lxhelper-deployment",
6+
"command-working-directory": "/tmp",
7+
"pass-arguments-to-command": [
8+
{
9+
"source": "payload",
10+
"name": "params.manifest"
11+
},
12+
{
13+
"source": "payload",
14+
"name": "params.transport"
15+
},
16+
{
17+
"source": "payload",
18+
"name": "params.target"
19+
},
20+
{
21+
"source": "payload",
22+
"name": "params.profile"
23+
}
24+
],
25+
"include-command-output-in-response": true,
26+
"include-command-output-in-response-on-error": true,
27+
"response-message": "Redeploy started!",
28+
"trigger-rule-mismatch-http-response-code": 400,
29+
"trigger-rule": {
30+
"and": [
31+
{
32+
"match": {
33+
"type": "value",
34+
"value": "{{ lxhelper_deployment['token'] | default('VeryUniqueStingHere',true) }}",
35+
"parameter": {
36+
"source": "payload",
37+
"name": "params.token"
38+
}
39+
}
40+
},
41+
{
42+
"match": {
43+
"type": "regex",
44+
"regex": "^(http(s?):\\/\\/|\\/)[\\w+\\.\\-\\/\\@\\:]+\\w+\\.yml$",
45+
"parameter": {
46+
"source": "payload",
47+
"name": "params.manifest"
48+
}
49+
}
50+
},
51+
{
52+
"match": {
53+
"type": "regex",
54+
"regex": "^(http|s3)$",
55+
"parameter": {
56+
"source": "payload",
57+
"name": "params.transport"
58+
}
59+
}
60+
},
61+
{
62+
"match": {
63+
"type": "regex",
64+
"regex": "{{ lxhelper_deployment['target_regex'] | default('^demo$',true) }}",
65+
"parameter": {
66+
"source": "payload",
67+
"name": "params.target"
68+
}
69+
}
70+
},
71+
{
72+
"match": {
73+
"type": "regex",
74+
"regex": "^([\\w\\d-]+|)$",
75+
"parameter": {
76+
"source": "payload",
77+
"name": "params.profile"
78+
}
79+
}
80+
}
81+
]
82+
}
83+
}
84+
]

0 commit comments

Comments
 (0)