From f1f4c931fefb3418ddfa710d078923688997f169 Mon Sep 17 00:00:00 2001 From: Brandon Shipley Date: Mon, 15 Apr 2024 20:35:48 -0700 Subject: [PATCH] first commit - basic but should be working - need to add molecule tests --- .gitignore | 1 + LICENSE | 24 ++++++++++++++++ defaults/main.yml | 9 ++++++ meta/main.yml | 14 +++++++++ meta/requirements.yml | 2 ++ tasks/docker.yml | 23 +++++++++++++++ tasks/main.yml | 7 +++++ tasks/uptime-kuma.yml | 50 +++++++++++++++++++++++++++++++++ templates/docker-compose.yml.j2 | 14 +++++++++ 9 files changed, 144 insertions(+) create mode 100755 .gitignore create mode 100755 LICENSE create mode 100755 defaults/main.yml create mode 100644 meta/main.yml create mode 100644 meta/requirements.yml create mode 100644 tasks/docker.yml create mode 100644 tasks/main.yml create mode 100644 tasks/uptime-kuma.yml create mode 100644 templates/docker-compose.yml.j2 diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..fdddb29 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100755 index 0000000..e2e04a2 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,9 @@ +--- +# see https://github.com/louislam/uptime-kuma/wiki/%F0%9F%94%A7-How-to-Install#docker-tags-description +uptime_kuma_version: 1 +uptime_kuma_ssl: "true" +uptime_kuma_certbot: "true" +uptime_kuma_domain: "status.your-domain.tld" +uptime_kuma_ssl_cert_path: "/etc/nginx/uptime_kuma.crt" +uptime_kuma_ssl_cert_key: "/etc/nginx/uptime_kuma.key" +uptime_kuma_user: "ubuntu" diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..2033241 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,14 @@ +--- +galaxy_info: + author: "Brandon Shipley" + description: "Ansible role to install/run uptime-kuma via docker-compose" + company: "HiPoweredDev" + license: MIT + min_anisble_version: 2.9 + role_name: ansible-role-uptime-kuma + galaxy_tags: + - uptime + - status + - monitoring + - uptime-kuma + - hi-powered-dev diff --git a/meta/requirements.yml b/meta/requirements.yml new file mode 100644 index 0000000..b8bb938 --- /dev/null +++ b/meta/requirements.yml @@ -0,0 +1,2 @@ +- name: geerlingguy.pip +- name: geerlingguy.docker diff --git a/tasks/docker.yml b/tasks/docker.yml new file mode 100644 index 0000000..dfd944c --- /dev/null +++ b/tasks/docker.yml @@ -0,0 +1,23 @@ +--- +# install docker using geerlingguy docker role - this whole task file is under tag install-docker +- name: 'Use geerlingguy.docker role' + include_role: + name: geerlingguy.docker + +- name: 'Use geerlingguy.pip role to install docker via pip' + vars: + pip_install_packages: + - name: docker + - name: docker-compose + + include_role: + name: geerlingguy.pip + +- name: Add uptime_kuma_user to docker group + user: + name: "{{ uptime_kuma_user }}" + groups: docker + append: yes + +- name: reset ssh connection to allow user changes to affect 'current login user' + meta: reset_connection diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..58c9c77 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,7 @@ +--- +# tasks file for setting up an uptime-kuma instance + +- include: docker.yml + tags: install-docker + +- include: uptime-kuma.yml diff --git a/tasks/uptime-kuma.yml b/tasks/uptime-kuma.yml new file mode 100644 index 0000000..0ff50cb --- /dev/null +++ b/tasks/uptime-kuma.yml @@ -0,0 +1,50 @@ +--- + +- name: Creates directory structure for uptime_kuma data + file: + path: /home/{{ uptime_kuma_user }}/uptime_kuma/data + state: directory + owner: "{{ uptime_kuma_user }}" + group: "{{ uptime_kuma_user }}" + mode: 0775 + +- name: copy docker compose to server (from template) + template: + src: templates/docker-compose.yml.j2 + dest: /home/{{ uptime_kuma_user }}/uptime_kuma/docker-compose.yml + +- name: bring down uptime_kuma docker-compose + become_user: "{{ uptime_kuma_user }}" + docker_compose: + project_src: /home/{{ uptime_kuma_user }}/uptime_kuma/ + state: absent + remove_orphans: true + register: __remove_uptime_kuma + tags: + - bring-down + +- name: update permissions + become: true + file: + path: /home/{{ uptime_kuma_user }} + state: directory + recurse: yes + owner: "{{ uptime_kuma_user }}" + group: "{{ uptime_kuma_user }}" + mode: 0775 + +- name: docker compose up + become_user: "{{ uptime_kuma_user }}" + docker_compose: + project_src: /home/{{ uptime_kuma_user }}/uptime_kuma/ + state: present + register: __uptime_kuma + +- name: debug docker compose down + debug: + var: __remove_uptime_kuma + tags: bring-down + +- name: debug docker compose up debug + debug: + var: __uptime_kuma diff --git a/templates/docker-compose.yml.j2 b/templates/docker-compose.yml.j2 new file mode 100644 index 0000000..464f721 --- /dev/null +++ b/templates/docker-compose.yml.j2 @@ -0,0 +1,14 @@ +# Simple docker-compose.yml +# You can change your port or volume location + +version: '3.3' + +services: + uptime-kuma: + image: louislam/uptime-kuma:{{ uptime_kuma_version }} + container_name: uptime-kuma + volumes: + - ./data:/app/data + ports: + - 3001:3001 # : + restart: always