From 54a63ca069d228a03dd711451d89ab315f7ea869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sun, 11 Feb 2024 14:50:21 +0100 Subject: [PATCH 1/4] Add uptime kuma as a service we can deploy to a different host for monitoring. --- roles/docker/files/vhost/uptime_kuma | 4 +++ roles/docker/tasks/pre_deploy/uptime_kuma.yml | 9 ++++++ .../compose-files/uptime_kuma.yml.j2 | 23 +++++++++++++ roles/ubuntu_base/tasks/base.yml | 2 +- roles/ubuntu_base/tasks/main.yml | 3 +- uptime.data.coop.yml | 32 +++++++++++++++++++ 6 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 roles/docker/files/vhost/uptime_kuma create mode 100644 roles/docker/tasks/pre_deploy/uptime_kuma.yml create mode 100644 roles/docker/templates/compose-files/uptime_kuma.yml.j2 create mode 100644 uptime.data.coop.yml diff --git a/roles/docker/files/vhost/uptime_kuma b/roles/docker/files/vhost/uptime_kuma new file mode 100644 index 0000000..2cff0be --- /dev/null +++ b/roles/docker/files/vhost/uptime_kuma @@ -0,0 +1,4 @@ +proxy_set_header Upgrade $http_upgrade; +proxy_set_header Connection "upgrade"; +proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +proxy_set_header Host $host; \ No newline at end of file diff --git a/roles/docker/tasks/pre_deploy/uptime_kuma.yml b/roles/docker/tasks/pre_deploy/uptime_kuma.yml new file mode 100644 index 0000000..f153e0e --- /dev/null +++ b/roles/docker/tasks/pre_deploy/uptime_kuma.yml @@ -0,0 +1,9 @@ +- name: Upload vhost config for uptime domain + copy: + src: vhost/uptime_kuma + dest: "{{ services.nginx_proxy.volume_folder }}/vhost/{{ services.uptime_kuma.domain }}_location" + +- name: Upload vhost config for status domain + copy: + src: vhost/uptime_kuma + dest: "{{ services.nginx_proxy.volume_folder }}/vhost/{{ services.uptime_kuma.status_domain }}_location" diff --git a/roles/docker/templates/compose-files/uptime_kuma.yml.j2 b/roles/docker/templates/compose-files/uptime_kuma.yml.j2 new file mode 100644 index 0000000..3d737b8 --- /dev/null +++ b/roles/docker/templates/compose-files/uptime_kuma.yml.j2 @@ -0,0 +1,23 @@ +# Simple docker-compose.yml +# You can change your port or volume location + +version: '3.3' + +services: + uptime-kuma: + image: "louislam/uptime-kuma:{{ services.uptime_kuma.version }}" + restart: always + container_name: uptime-kuma + networks: + - external_services + volumes: + - "./uptime-kuma-data:/app/data" + environment: + VIRTUAL_HOST: "{{ services.uptime_kuma.domain }},{{ services.uptime_kuma.status_domain }}" + LETSENCRYPT_HOST: "{{ services.uptime_kuma.domain }},{{ services.uptime_kuma.status_domain }}" + LETSENCRYPT_EMAIL: "{{ letsencrypt_email }}" + + +networks: + external_services: + external: true \ No newline at end of file diff --git a/roles/ubuntu_base/tasks/base.yml b/roles/ubuntu_base/tasks/base.yml index f53f924..733270d 100644 --- a/roles/ubuntu_base/tasks/base.yml +++ b/roles/ubuntu_base/tasks/base.yml @@ -14,4 +14,4 @@ - name: Install Dell OpenManage apt: name: srvadmin-all - when: not vagrant + when: not vagrant and not skip_dell_apt_repo diff --git a/roles/ubuntu_base/tasks/main.yml b/roles/ubuntu_base/tasks/main.yml index e6a1f15..cc40345 100644 --- a/roles/ubuntu_base/tasks/main.yml +++ b/roles/ubuntu_base/tasks/main.yml @@ -2,10 +2,11 @@ --- - import_tasks: ssh-port.yml tags: [change-ssh-port] + when: not do_not_change_ssh_port - import_tasks: dell-apt-repo.yml tags: [setup-dell-apt-repo] - when: not vagrant + when: not skip_dell_apt_repo and not vagrant - import_tasks: upgrade.yml tags: [do-full-system-upgrade] diff --git a/uptime.data.coop.yml b/uptime.data.coop.yml new file mode 100644 index 0000000..2eee6ae --- /dev/null +++ b/uptime.data.coop.yml @@ -0,0 +1,32 @@ +# vim: ft=yaml.ansible +--- +- hosts: all + gather_facts: true + become: true + vars: + base_domain: "{{ 'datacoop.devel' if vagrant else 'data.coop' }}" + letsencrypt_enabled: true + letsencrypt_email: "admin@{{ base_domain }}" + services: + nginx_proxy: + volume_folder: "{{ volume_root_folder }}/nginx" + pre_deploy_tasks: true + version: "1.3-alpine" + acme_companion_version: "2.2" + uptime_kuma: + domain: "uptime.{{ base_domain }}" + status_domain: "status.{{ base_domain }}" + volume_folder: "{{ volume_root_folder }}/uptime_kuma" + pre_deploy_tasks: true + version: "latest" + do_not_change_ssh_port: true + skip_dell_apt_repo: true + vagrant: false + + tasks: + - import_role: + name: ubuntu_base + tags: + - base_only + - import_role: + name: docker -- 2.43.4 From 7aae344da0515d1fd0c574dbf22db3adc23a3136 Mon Sep 17 00:00:00 2001 From: Sam Al-Sapti Date: Sun, 18 Feb 2024 17:18:54 +0100 Subject: [PATCH 2/4] Don't specify service settings twice --- playbook.yml | 3 +++ roles/docker/defaults/main.yml | 13 +++++++++++-- roles/docker/tasks/services.yml | 10 +++++++--- uptime.data.coop.yml | 15 +++------------ 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/playbook.yml b/playbook.yml index de51a46..df74f98 100644 --- a/playbook.yml +++ b/playbook.yml @@ -15,6 +15,9 @@ smtp_host: "postfix" smtp_port: "587" + services_exclude: + - uptime_kuma + tasks: - import_role: name: ubuntu_base diff --git a/roles/docker/defaults/main.yml b/roles/docker/defaults/main.yml index 457b302..a3128a0 100644 --- a/roles/docker/defaults/main.yml +++ b/roles/docker/defaults/main.yml @@ -4,7 +4,6 @@ volume_root_folder: "/docker-volumes" volume_website_folder: "{{ volume_root_folder }}/websites" services: - ### Internal services ### postfix: domain: "smtp.{{ base_domain }}" @@ -62,7 +61,6 @@ services: version: "2" ### External services ### - nextcloud: domain: "cloud.{{ base_domain }}" volume_folder: "{{ volume_root_folder }}/nextcloud" @@ -208,3 +206,14 @@ services: watchtower: volume_folder: "{{ volume_root_folder }}/watchtower" version: "1.5.3" + + ### Uptime monitoring ### + uptime_kuma: + domain: "uptime.{{ base_domain }}" + status_domain: "status.{{ base_domain }}" + volume_folder: "{{ volume_root_folder }}/uptime_kuma" + pre_deploy_tasks: true + version: "latest" + +services_exclude: [] +services_include: "{{ services | dict2items | map(attribute='key') | list | difference(services_exclude) }}" diff --git a/roles/docker/tasks/services.yml b/roles/docker/tasks/services.yml index 676335c..2c7276f 100644 --- a/roles/docker/tasks/services.yml +++ b/roles/docker/tasks/services.yml @@ -8,8 +8,10 @@ include_tasks: file: block.yml vars: - service: "{{ item }}" - loop: "{{ services | dict2items(key_name='name', value_name='vars') }}" + service: + name: "{{ item }}" + vars: "{{ services[item] }}" + loop: "{{ services_include }}" when: single_service is not defined and (item.vars.disabled_in_vagrant is not defined or not (item.vars.disabled_in_vagrant and vagrant)) @@ -18,7 +20,9 @@ include_tasks: file: block.yml vars: - service: "{{ {single_service: services[single_service]} | dict2items(key_name='name', value_name='vars') | join }}" + service: + name: "{{ single_service }}" + vars: "{{ services[single_service] }}" when: single_service is defined and single_service in services and (services[single_service].disabled_in_vagrant is not defined or not (services[single_service].disabled_in_vagrant and vagrant)) diff --git a/uptime.data.coop.yml b/uptime.data.coop.yml index 2eee6ae..e54e21c 100644 --- a/uptime.data.coop.yml +++ b/uptime.data.coop.yml @@ -7,18 +7,9 @@ base_domain: "{{ 'datacoop.devel' if vagrant else 'data.coop' }}" letsencrypt_enabled: true letsencrypt_email: "admin@{{ base_domain }}" - services: - nginx_proxy: - volume_folder: "{{ volume_root_folder }}/nginx" - pre_deploy_tasks: true - version: "1.3-alpine" - acme_companion_version: "2.2" - uptime_kuma: - domain: "uptime.{{ base_domain }}" - status_domain: "status.{{ base_domain }}" - volume_folder: "{{ volume_root_folder }}/uptime_kuma" - pre_deploy_tasks: true - version: "latest" + services_include: + - nginx_proxy + - uptime_kuma do_not_change_ssh_port: true skip_dell_apt_repo: true vagrant: false -- 2.43.4 From d05a504e619467a5f5824d3eb7cc416bc99a1ff4 Mon Sep 17 00:00:00 2001 From: Sam Al-Sapti Date: Sun, 18 Feb 2024 17:27:52 +0100 Subject: [PATCH 3/4] Move vars around --- uptime.data.coop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uptime.data.coop.yml b/uptime.data.coop.yml index e54e21c..993f3e9 100644 --- a/uptime.data.coop.yml +++ b/uptime.data.coop.yml @@ -4,6 +4,7 @@ gather_facts: true become: true vars: + vagrant: false base_domain: "{{ 'datacoop.devel' if vagrant else 'data.coop' }}" letsencrypt_enabled: true letsencrypt_email: "admin@{{ base_domain }}" @@ -12,7 +13,6 @@ - uptime_kuma do_not_change_ssh_port: true skip_dell_apt_repo: true - vagrant: false tasks: - import_role: -- 2.43.4 From f792bf3dd16b38114cfed30eac262ebcf62b21bf Mon Sep 17 00:00:00 2001 From: Sam Al-Sapti Date: Thu, 29 Feb 2024 20:45:59 +0100 Subject: [PATCH 4/4] Fixes and add Watchtower to Uptime Kuma instance --- datacoop_hosts | 6 ++++-- playbook.yml | 2 +- roles/docker/templates/compose-files/uptime_kuma.yml.j2 | 4 +--- uptime.data.coop.yml | 3 ++- vagrant_host | 1 + 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/datacoop_hosts b/datacoop_hosts index 4fe371b..5b8c106 100644 --- a/datacoop_hosts +++ b/datacoop_hosts @@ -1,3 +1,5 @@ -###################################### -### All hosts +[production] hevonen.servers.data.coop ansible_port=19022 ansible_python_interpreter=/usr/bin/python3 + +[monitoring] +uptime.data.coop ansible_python_interpreter=/usr/bin/python3 \ No newline at end of file diff --git a/playbook.yml b/playbook.yml index df74f98..71b78eb 100644 --- a/playbook.yml +++ b/playbook.yml @@ -1,6 +1,6 @@ # vim: ft=yaml.ansible --- -- hosts: all +- hosts: production gather_facts: true become: true vars: diff --git a/roles/docker/templates/compose-files/uptime_kuma.yml.j2 b/roles/docker/templates/compose-files/uptime_kuma.yml.j2 index 3d737b8..0096d6f 100644 --- a/roles/docker/templates/compose-files/uptime_kuma.yml.j2 +++ b/roles/docker/templates/compose-files/uptime_kuma.yml.j2 @@ -1,6 +1,4 @@ -# Simple docker-compose.yml -# You can change your port or volume location - +# vim: ft=yaml.docker-compose version: '3.3' services: diff --git a/uptime.data.coop.yml b/uptime.data.coop.yml index 993f3e9..714d469 100644 --- a/uptime.data.coop.yml +++ b/uptime.data.coop.yml @@ -1,6 +1,6 @@ # vim: ft=yaml.ansible --- -- hosts: all +- hosts: monitoring gather_facts: true become: true vars: @@ -11,6 +11,7 @@ services_include: - nginx_proxy - uptime_kuma + - watchtower do_not_change_ssh_port: true skip_dell_apt_repo: true diff --git a/vagrant_host b/vagrant_host index e247254..c49d9be 100644 --- a/vagrant_host +++ b/vagrant_host @@ -1 +1,2 @@ +[production] localhost ansible_port=19022 -- 2.43.4