commit 9b8494b33b9c8f3b3067e4e3efaf4d3a71a90a5b Author: phil Date: Wed Mar 1 10:56:33 2023 +0100 Initial diff --git a/README.md b/README.md new file mode 100644 index 0000000..f6d42a5 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +DIUN - Docker Image Update Notifier +=================================== + +This role installs [Duin](https://crazymax.dev/diun/). diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..f73646e --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,7 @@ +--- +diun_user: duin +diun_github_api_url: https://api.github.com/repos/crazy-max/diun/releases/latest +duin_home: /var/lib/duin +diun_binary_path: /usr/local/bin +duin_configuration_path: /etc/diun +duin_configuration_file: diun.yaml diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..9e6062d --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart diun + ansible.builtin.systemd: + name: diun + daemon_reload: true + state: restarted diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..bc0190e --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,10 @@ +galaxy_info: + author: Sense.Lab admin + description: Role to install Diun + company: Sense.Lab e.V. + license: GPLv3 + min_ansible_version: "2.11" + platforms: + - name: Debian + versions: + - bullseye diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..8169b3a --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,53 @@ +--- +- name: "Create user" + ansible.builtin.user: + name: "{{ diun_user }}" + shell: /bin/false + create_home: false + password_lock: true + system: true + group: "{{ diun_user }}" + +- name: "Get download URL" + ansible.builtin.shell: + cmd: curl -sL "{{ diun_github_api_url }}" | jq '.assets[] | select(.name|match("linux_amd64.tar.gz$")) | .browser_download_url'" + changed_when: false + register: download_url + +- name: "Unarchive binary" + ansible.builtin.unarchive: + src: download_url.stdout + dest: "{{ diun_binary_path }}" + include: + - diun + mode: 0755 + +- name: "Create directories" + ansible.builtin.file: + path: "{{ item }}" + owner: "{{ diun_user }}" + group: "{{ diun_user }}" + mode: 0750 + loop: + - "{{ diun_configuration_path }}" + - "{{ diun_home }}" + +- name: "Copy configuration file" + ansible.builtin.template: + src: "{{ diun_configuration_file }}" + dest: "{{ diun_configuration_path }}" + mode: 0644 + +- name: "Copy service file" + ansible.builtin.template: + src: diun.service + dest: /etc/systemd/system/ + mode: 0644 + notify: restart duin + +- name: "Enable service" + ansible.builtin.systemd: + name: diun + enabled: true + daemon_reload: true + state: started diff --git a/templates/diun.service b/templates/diun.service new file mode 100644 index 0000000..9e668f9 --- /dev/null +++ b/templates/diun.service @@ -0,0 +1,19 @@ +# Managed by Ansible + +[Unit] +Description=Diun +Documentation=https://crazymax.dev/diun/ +After=syslog.target +After=network.target + +[Service] +RestartSec=2s +Type=simple +User={{ diun_user }} +Group={{ diun_user }} +ExecStart={{ diun_binary_path }}/diun serve --config {{ duin_configuration_path }}/{{ duin_configuration_file }} --log-level info +Restart=always +Environment=DIUN_DB_PATH={{ diun_home }}/diun.db + +[Install] +WantedBy=multi-user.target diff --git a/templates/diun.yaml b/templates/diun.yaml new file mode 100644 index 0000000..ad6dfe1 --- /dev/null +++ b/templates/diun.yaml @@ -0,0 +1,18 @@ +# Managed by Ansible + +db: + path: {{ diun_home }}/diun.db + +{% if diun_watch is defined %} +{{ duin_watch }} +{% endif %} + +{% if diun_notif is defined %} +notif: + {{ duin_notif | indent(2, false) }} +{% endif %} + +{% if diun_providers is defined %} +providers: + {{ duin_providers | indent(2, false) }} +{% endif %}