diff --git a/roles/diun/README.md b/roles/diun/README.md new file mode 100644 index 0000000..5f821f2 --- /dev/null +++ b/roles/diun/README.md @@ -0,0 +1,5 @@ +# diun + +Monitor the deployed swarm containers for updates. +Will notify you when it found any update for any container. +Can (currently) notify you either through mail or on matrix. diff --git a/roles/diun/defaults/main.yml b/roles/diun/defaults/main.yml new file mode 100644 index 0000000..2eb93de --- /dev/null +++ b/roles/diun/defaults/main.yml @@ -0,0 +1,26 @@ +--- +diun_version: 4 + +diun_upstream_file_dir: "{{ docker_stack_files_dir }}/{{ stack_name }}" + +diun_use_https: true + +# the subdomain link diun will be reachable under +subdomain_alias: diun + +diun_tz: Europe/Berlin +diun_log_level: info +diun_watch_swarm_by_default: true + +diun_notif_mail_host: localhost +diun_notif_mail_port: 25 +# diun_notif_mail_username: required for mail +# diun_notif_mail_password: required for mail +# diun_notif_mail_from: required for mail +# diun_notif_mail_to: required for mail + +diun_notif_matrix_url: "https://matrix.org" +#diun_notif_matrix_user: required for matrix +#diun_notif_matrix_password: required for matrix +#diun_notif_matrix_roomid: required for matrix + diff --git a/roles/diun/meta/main.yml b/roles/diun/meta/main.yml new file mode 100644 index 0000000..2c1b831 --- /dev/null +++ b/roles/diun/meta/main.yml @@ -0,0 +1,10 @@ +--- +galaxy_info: + author: Marty Oehme + description: Notify on any docker swarm container updates + license: GPL-3.0-only + min_ansible_version: "2.9" + galaxy_tags: [] + +dependencies: + - docker-swarm diff --git a/roles/diun/tasks/main.yml b/roles/diun/tasks/main.yml new file mode 100644 index 0000000..10456f4 --- /dev/null +++ b/roles/diun/tasks/main.yml @@ -0,0 +1,12 @@ +--- +## install diun container +- name: Deploy diun to swarm + community.general.docker_stack: + name: "{{ stack_name }}" + state: present + prune: yes + compose: + - "{{ stack_compose }}" + become: true + tags: + - docker-swarm diff --git a/roles/diun/templates/docker-stack.yml.j2 b/roles/diun/templates/docker-stack.yml.j2 new file mode 100644 index 0000000..71a07cb --- /dev/null +++ b/roles/diun/templates/docker-stack.yml.j2 @@ -0,0 +1,51 @@ +version: '3.4' + +services: + app: + image: crazymax/diun:latest + # healthcheck: + # test: ["CMD", "wget", "--spider", "-q", "127.0.0.1"] + # interval: 1m + # timeout: 10s + # retries: 3 + # start_period: 1m + command: serve + volumes: + - "data:/data" + - "/var/run/docker.sock:/var/run/docker.sock" + environment: + - "TZ={{ diun_tz }}" + - "LOG_LEVEL={{ diun_log_level }}" + - "LOG_JSON=false" + - "DIUN_WATCH_WORKERS=20" + - "DIUN_WATCH_SCHEDULE=0 */6 * * *" + - "DIUN_WATCH_JITTER=30s" + - "DIUN_PROVIDERS_SWARM=true" + - "DIUN_PROVIDERS_SWARM_WATCHBYDEFAULT={{ diun_watch_swarm_by_default }}" +{% if diun_notif_matrix_user is not undefined and not None and diun_notif_matrix_password is not undefined and not None and diun_notif_matrix_roomid is not undefined and not None %} + - "DIUN_NOTIF_MATRIX_HOMESERVERURL={{ diun_notif_matrix_url }}" + - "DIUN_NOTIF_MATRIX_USER={{ diun_notif_matrix_user }}" + - "DIUN_NOTIF_MATRIX_PASSWORD={{ diun_notif_matrix_password }}" + - "DIUN_NOTIF_MATRIX_ROOMID={{ diun_notif_matrix_roomid }}" +{% endif %} +{% if diun_notif_mail_username is not undefined and not None and diun_notif_mail_password is not undefined and not None and diun_notif_mail_from is not undefined and not None and diun_notif_mail_to is not undefined and not None %} + - "DIUN_NOTIF_MAIL_HOST={{ diun_notif_mail_host }}" + - "DIUN_NOTIF_MAIL_PORT={{ diun_notif_mail_port }}" + - "DIUN_NOTIF_MAIL_USERNAME={{ diun_notif_mail_username }}" + - "DIUN_NOTIF_MAIL_PASSWORD={{ diun_notif_mail_password }}" + - "DIUN_NOTIF_MAIL_FROM={{ diun_notif_mail_from }}" + - "DIUN_NOTIF_MAIL_TO={{ diun_notif_mail_to }}" +{% endif %} +# deploy: +# mode: replicated +# replicas: 1 +# placement: +# constraints: +# - node.role == manager + +volumes: + data: + +networks: + "{{ docker_swarm_public_network_name }}": + external: true diff --git a/roles/diun/vars/main.yml b/roles/diun/vars/main.yml new file mode 100644 index 0000000..91148a4 --- /dev/null +++ b/roles/diun/vars/main.yml @@ -0,0 +1,6 @@ +--- +stack_name: diun + +stack_image: "crazymax/diun" + +stack_compose: "{{ lookup('template', 'docker-stack.yml.j2') | from_yaml }}" diff --git a/site.yml b/site.yml index e5ccbf3..892a4e2 100644 --- a/site.yml +++ b/site.yml @@ -86,3 +86,9 @@ tags: - ntfy - never + + - name: Install diun + import_role: + role: diun + tags: + - diun