From 326f04863930d17963432ae73d41cd85fb6cfc31 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Mon, 17 Feb 2025 11:04:40 +0100 Subject: [PATCH] Refactored and solved matomo variable bug --- .../tasks}/seed-database-to-backup.yml | 2 ++ roles/docker-matomo/README.md | 19 +++++-------------- roles/docker-matomo/vars/main.yml | 1 + .../tasks}/create-and-seed-database.yml | 2 +- roles/docker-mybb/tasks/main.yml | 4 ++-- roles/docker-mybb/tasks/setup-domain.yml | 13 +++++++++++++ roles/nginx-global/tasks/main.yml | 2 +- tasks/create-domain-conf.yml | 5 ----- tasks/create-proxy-with-domain-replace.yml | 8 -------- tasks/nginx-docker-proxy-domain.yml | 9 ++++++--- 10 files changed, 31 insertions(+), 34 deletions(-) rename {tasks => roles/backup-docker-to-local/tasks}/seed-database-to-backup.yml (93%) rename {tasks => roles/docker-matrix-compose/tasks}/create-and-seed-database.yml (75%) create mode 100644 roles/docker-mybb/tasks/setup-domain.yml delete mode 100644 tasks/create-domain-conf.yml delete mode 100644 tasks/create-proxy-with-domain-replace.yml diff --git a/tasks/seed-database-to-backup.yml b/roles/backup-docker-to-local/tasks/seed-database-to-backup.yml similarity index 93% rename from tasks/seed-database-to-backup.yml rename to roles/backup-docker-to-local/tasks/seed-database-to-backup.yml index 4c883909..d039d29b 100644 --- a/tasks/seed-database-to-backup.yml +++ b/roles/backup-docker-to-local/tasks/seed-database-to-backup.yml @@ -1,3 +1,5 @@ +# This file is also used by docker-matrix-compose + - name: Display all database variables debug: msg: | diff --git a/roles/docker-matomo/README.md b/roles/docker-matomo/README.md index 8e2df4d2..304d3186 100644 --- a/roles/docker-matomo/README.md +++ b/roles/docker-matomo/README.md @@ -1,6 +1,6 @@ # Docker Matomo Role -This Ansible role deploys a Matomo analytics platform instance using Docker. +This Ansible role deploys a [Matomo](https://matomo.org/) analytics platform instance using Docker. ## Requirements @@ -16,17 +16,8 @@ This Ansible role deploys a Matomo analytics platform instance using Docker. - `http_port`: The host port that Matomo will be accessible on. - `matomo_database_password`: Password for the Matomo database. -## Dependencies - -- `nginx-docker-reverse-proxy`: An Ansible role for configuring the reverse proxy. - -## Example Playbook - -```yaml -- hosts: servers - roles: - - { role: docker-matomo, domain: 'example.com', http_port: 8080 } -``` - ## AI Generated -This script was created with the help of ChatGPT. The full conversation is [here](https://chat.openai.com/share/49e0c7e4-a2af-4a04-adad-7a735bdd85c4) available. \ No newline at end of file +This script was created with the help of ChatGPT. The full conversation is [here](https://chat.openai.com/share/49e0c7e4-a2af-4a04-adad-7a735bdd85c4) available. + +## Author +- [Kevin Veen-Birkenbach](https://www.veen.world/) \ No newline at end of file diff --git a/roles/docker-matomo/vars/main.yml b/roles/docker-matomo/vars/main.yml index 7d4c521f..1c215b83 100644 --- a/roles/docker-matomo/vars/main.yml +++ b/roles/docker-matomo/vars/main.yml @@ -2,6 +2,7 @@ application_id: "matomo" database_type: "mariadb" database_password: "{{matomo_database_password}}" +domain: "{{domains.matomo}}" # Disable matomo tracking for matomo, because otherwise recursiv loading technics would be neccessary # global_matomo_tracking_enabled: false \ No newline at end of file diff --git a/tasks/create-and-seed-database.yml b/roles/docker-matrix-compose/tasks/create-and-seed-database.yml similarity index 75% rename from tasks/create-and-seed-database.yml rename to roles/docker-matrix-compose/tasks/create-and-seed-database.yml index 4a386b40..727b020c 100644 --- a/tasks/create-and-seed-database.yml +++ b/roles/docker-matrix-compose/tasks/create-and-seed-database.yml @@ -10,4 +10,4 @@ when: enable_central_database | bool - name: "include seed-database-to-backup.yml" - include_tasks: seed-database-to-backup.yml \ No newline at end of file + include_tasks: ""{{ playbook_dir }}/roles/backup-docker-to-local/tasks/seed-database-to-backup.yml" \ No newline at end of file diff --git a/roles/docker-mybb/tasks/main.yml b/roles/docker-mybb/tasks/main.yml index 3396bbf5..f1760e65 100644 --- a/roles/docker-mybb/tasks/main.yml +++ b/roles/docker-mybb/tasks/main.yml @@ -3,8 +3,8 @@ include_role: name: docker-central-database -- name: "include tasks create-proxy-with-domain-replace.yml" - include_tasks: create-proxy-with-domain-replace.yml +- name: "include tasks setup-domain.yml with {{domain}}" + include_tasks: setup-domain.yml loop: "{{ mybb_domains + [source_domain] }}" loop_control: loop_var: domain diff --git a/roles/docker-mybb/tasks/setup-domain.yml b/roles/docker-mybb/tasks/setup-domain.yml new file mode 100644 index 00000000..7604ee9b --- /dev/null +++ b/roles/docker-mybb/tasks/setup-domain.yml @@ -0,0 +1,13 @@ +# Recieves https certificate and setup proxy with domain replace + +- name: "include role receive certbot certificate" + include_role: + name: nginx-https-recieve-certificate + +- name: configure {{domain}}.conf + template: + src: "roles/nginx-docker-reverse-proxy/templates/domain.conf.j2" + dest: "{{nginx.directories.http.servers}}{{domain}}.conf" + notify: restart nginx + vars: + nginx_docker_reverse_proxy_extra_configuration: "sub_filter '{{source_domain}}' '{{domain}}';" diff --git a/roles/nginx-global/tasks/main.yml b/roles/nginx-global/tasks/main.yml index 09183451..ae1e74a1 100644 --- a/roles/nginx-global/tasks/main.yml +++ b/roles/nginx-global/tasks/main.yml @@ -1,7 +1,7 @@ - name: Activate Global Matomo tracking include_role: name: nginx-global-matomo - when: global_matomo_tracking_enabled | bool and domain is defined # @toto: Do I try run without is defined checking for domain + when: global_matomo_tracking_enabled | bool and domain is defined # @todo: Do I try run without is defined checking for domain - name: Activate Global CSS include_role: diff --git a/tasks/create-domain-conf.yml b/tasks/create-domain-conf.yml deleted file mode 100644 index ccea771b..00000000 --- a/tasks/create-domain-conf.yml +++ /dev/null @@ -1,5 +0,0 @@ -- name: configure {{domain}}.conf - template: - src: "roles/nginx-docker-reverse-proxy/templates/domain.conf.j2" - dest: "{{nginx.directories.http.servers}}{{domain}}.conf" - notify: restart nginx \ No newline at end of file diff --git a/tasks/create-proxy-with-domain-replace.yml b/tasks/create-proxy-with-domain-replace.yml deleted file mode 100644 index 8f629b6e..00000000 --- a/tasks/create-proxy-with-domain-replace.yml +++ /dev/null @@ -1,8 +0,0 @@ -- name: "include role receive certbot certificate" - include_role: - name: nginx-https-recieve-certificate - -- name: "include task create-domain-conf.yml" - include_tasks: create-domain-conf.yml - vars: - nginx_docker_reverse_proxy_extra_configuration: "sub_filter '{{source_domain}}' '{{domain}}';" diff --git a/tasks/nginx-docker-proxy-domain.yml b/tasks/nginx-docker-proxy-domain.yml index 3dcc0721..c43cd1ff 100644 --- a/tasks/nginx-docker-proxy-domain.yml +++ b/tasks/nginx-docker-proxy-domain.yml @@ -2,9 +2,12 @@ include_role: name: nginx-https-recieve-certificate -- name: "include task create-domain-conf.yml" - include_tasks: create-domain-conf.yml - +- name: "copy nginx domain configuration to {{nginx.directories.http.servers}}{{domain}}.conf" + template: + src: "roles/nginx-docker-reverse-proxy/templates/domain.conf.j2" + dest: "{{nginx.directories.http.servers}}{{domain}}.conf" + notify: restart nginx + - name: include the docker-oauth2-proxy role include_role: name: docker-oauth2-proxy