feat(ttbot): add timetracking bot role

This commit is contained in:
Jan Christian Grünhage 2020-12-16 11:02:59 +01:00
parent 8f7924cb32
commit 57479eef36
7 changed files with 126 additions and 0 deletions

View file

@ -380,6 +380,7 @@ Config(
},
scope_headers: {
"modules": "Modules",
"ttbot": "Timetracking Bot Role",
"synapse": "Synapse Role",
"element": "Element Role",
"riot": "Riot Role"

View file

@ -0,0 +1,21 @@
# timetracking-bot
Deploys a dockerized
[timetracking-bot](https://gitlab.com/famedly/bots/timetracking) instance.
## Requirements
You need a postgres DB for it and docker needs to be installed. Matrix user must
also already exist.
## Role Variables
Look at `defaults/main.yml`.
## License
Proprietary, all rights reserved.
## Author Information
- Jan Christian Grünhage <jcgruenhage@famedly.com>

View file

@ -0,0 +1,27 @@
---
# defaults file for timetracking-bot
timetracking_bot_base_path: "/opt/matrix-timetracking"
timetracking_bot_config_path: "{{ timetracking_bot_base_path }}/config.yaml"
timetracking_bot_store_path: "{{ timetracking_bot_base_path }}/store"
timetracking_bot_pg_url: "postgres://{{ timetracking_bot_pg_user }}:{{ timetracking_bot_pg_pass }}@{{ timetracking_bot_pg_host }}/{{ timetracking_bot_pg_db }}"
timetracking_bot_pg_user: "matrix-timetracking"
timetracking_bot_pg_pass: ~
timetracking_bot_pg_host: ~
timetracking_bot_pg_db: "matrix-timetracking"
timetracking_bot_version: "0.1.4"
timetracking_bot_container_image_tag: ~
timetracking_bot_container_image: "registry.gitlab.com/famedly/bots/timetracking"
timetracking_bot_container_image_ref: '{{ timetracking_bot_container_image }}:{{ timetracking_bot_container_image_tag | default("v" + timetracking_bot_version, true) }}'
timetracking_bot_docker_ports: []
timetracking_bot_docker_env: {}
timetracking_bot_docker_labels: {}
timetracking_bot_homeserver_url: ~
timetracking_bot_mxid: ~
timetracking_bot_password: ~
timetracking_bot_admins: ~
timetracking_bot_allowed_users: ~

View file

@ -0,0 +1,7 @@
---
# handlers file for timetracking-bot
- name: restart timetracking-bot
docker_container:
name: "timetracking-bot"
state: started
restart: yes

View file

@ -0,0 +1,7 @@
galaxy_info:
author: Jan Christian Grünhage
description: deploys a dockerized matrix timetracking bot
company: Famedly GmbH
min_ansible_version: 2.9
galaxy_tags: []
dependencies: []

View file

@ -0,0 +1,48 @@
---
# tasks file for timetracking-bot
- name: create timetracking bot user
user:
name: matrix-timetracking
state: present
system: yes
register: timetracking_bot_user_res
- name: create application directories
file:
path: "{{ item }}"
mode: 0750
owner: "{{ timetracking_bot_user_res.uid }}"
group: "{{ timetracking_bot_user_res.group }}"
state: directory
loop:
- "{{ timetracking_bot_base_path }}"
- "{{ timetracking_bot_store_path }}"
- name: template config
copy:
content: |
{{ 'Managed by ansible' | comment('plain', prefix='#####', postfix='#####') }}
{{ timetracking_bot_config | to_nice_yaml }}
dest: "{{ timetracking_bot_config_path }}"
mode: 0640
owner: "{{ timetracking_bot_user_res.uid }}"
group: "{{ timetracking_bot_user_res.group }}"
notify:
- restart timetracking-bot
- name: start container
docker_container:
name: "timetracking-bot"
image: "{{ timetracking_bot_container_image_ref }}"
restart_policy: "unless-stopped"
user: "{{ timetracking_bot_user_res.uid }}:{{ timetracking_bot_user_res.group }}"
volumes:
- "{{ timetracking_bot_config_path }}:{{ timetracking_bot_config_path }}"
- "{{ timetracking_bot_store_path }}:{{ timetracking_bot_store_path }}"
env: "{{ timetracking_bot_docker_env }}"
ports: "{{ timetracking_bot_docker_ports }}"
labels: "{{ timetracking_bot_docker_labels_complete }}"
command:
- "/usr/local/bin/timetracker"
- "-c"
- "{{ timetracking_bot_config_path }}"

View file

@ -0,0 +1,15 @@
---
# vars file for timetracking-bot
timetracking_bot_config:
homeserver_url: "{{ timetracking_bot_homeserver_url }}"
mxid: "{{ timetracking_bot_mxid }}"
password: "{{ timetracking_bot_password }}"
store_path: "{{ timetracking_bot_store_path }}"
database_url: "{{ timetracking_bot_pg_url }}"
admins: "{{ timetracking_bot_admins }}"
allowed_users: "{{ timetracking_bot_allowed_users }}"
timetracking_bot_docker_labels_complete: "{{ timetracking_bot_docker_labels_base | combine(timetracking_bot_docker_labels) }}"
timetracking_bot_docker_labels_base:
version: "{{ timetracking_bot_container_image_tag | default(timetracking_bot_version, true) }}"