From 57479eef36c54349164fb90b7205058c9aabe3da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Christian=20Gr=C3=BCnhage?= Date: Wed, 16 Dec 2020 11:02:59 +0100 Subject: [PATCH] feat(ttbot): add timetracking bot role --- CHANGELOG.md | 1 + roles/timetracking-bot/README.md | 21 +++++++++++ roles/timetracking-bot/defaults/main.yml | 27 +++++++++++++ roles/timetracking-bot/handlers/main.yml | 7 ++++ roles/timetracking-bot/meta/main.yml | 7 ++++ roles/timetracking-bot/tasks/main.yml | 48 ++++++++++++++++++++++++ roles/timetracking-bot/vars/main.yml | 15 ++++++++ 7 files changed, 126 insertions(+) create mode 100644 roles/timetracking-bot/README.md create mode 100644 roles/timetracking-bot/defaults/main.yml create mode 100644 roles/timetracking-bot/handlers/main.yml create mode 100644 roles/timetracking-bot/meta/main.yml create mode 100644 roles/timetracking-bot/tasks/main.yml create mode 100644 roles/timetracking-bot/vars/main.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ad3057..54e8d5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -380,6 +380,7 @@ Config( }, scope_headers: { "modules": "Modules", + "ttbot": "Timetracking Bot Role", "synapse": "Synapse Role", "element": "Element Role", "riot": "Riot Role" diff --git a/roles/timetracking-bot/README.md b/roles/timetracking-bot/README.md new file mode 100644 index 0000000..670ffb3 --- /dev/null +++ b/roles/timetracking-bot/README.md @@ -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 diff --git a/roles/timetracking-bot/defaults/main.yml b/roles/timetracking-bot/defaults/main.yml new file mode 100644 index 0000000..18fe9de --- /dev/null +++ b/roles/timetracking-bot/defaults/main.yml @@ -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: ~ diff --git a/roles/timetracking-bot/handlers/main.yml b/roles/timetracking-bot/handlers/main.yml new file mode 100644 index 0000000..4a8cc64 --- /dev/null +++ b/roles/timetracking-bot/handlers/main.yml @@ -0,0 +1,7 @@ +--- +# handlers file for timetracking-bot + - name: restart timetracking-bot + docker_container: + name: "timetracking-bot" + state: started + restart: yes diff --git a/roles/timetracking-bot/meta/main.yml b/roles/timetracking-bot/meta/main.yml new file mode 100644 index 0000000..cedc989 --- /dev/null +++ b/roles/timetracking-bot/meta/main.yml @@ -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: [] diff --git a/roles/timetracking-bot/tasks/main.yml b/roles/timetracking-bot/tasks/main.yml new file mode 100644 index 0000000..403d7ec --- /dev/null +++ b/roles/timetracking-bot/tasks/main.yml @@ -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 }}" diff --git a/roles/timetracking-bot/vars/main.yml b/roles/timetracking-bot/vars/main.yml new file mode 100644 index 0000000..0fced7e --- /dev/null +++ b/roles/timetracking-bot/vars/main.yml @@ -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) }}" +