From 4d8439865734cdfe2e9ae22039c420ad24f55005 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Wed, 10 Jul 2024 16:45:45 +0200 Subject: [PATCH] feat(server/ddns): implement DDNS support using inadyn Signed-off-by: Matej Focko --- roles/server/ddns/files/ddns.service | 7 +++++ roles/server/ddns/files/ddns.timer | 10 ++++++++ roles/server/ddns/tasks/main.yml | 34 +++++++++++++++++++++++++ roles/server/ddns/templates/inadyn.conf | 15 +++++++++++ 4 files changed, 66 insertions(+) create mode 100644 roles/server/ddns/files/ddns.service create mode 100644 roles/server/ddns/files/ddns.timer create mode 100644 roles/server/ddns/tasks/main.yml create mode 100644 roles/server/ddns/templates/inadyn.conf diff --git a/roles/server/ddns/files/ddns.service b/roles/server/ddns/files/ddns.service new file mode 100644 index 0000000..08602fa --- /dev/null +++ b/roles/server/ddns/files/ddns.service @@ -0,0 +1,7 @@ +[Unit] +Description=Run inadyn in a container to update DNS +After=network.target + +[Service] +Type=oneshot +ExecStart=podman run --rm -v "/etc/inadyn.conf:/etc/inadyn.conf" -v "/var/cache/inadyn:/var/cache/inadyn" docker.io/troglobit/inadyn:latest -1 --cache-dir=/var/cache/inadyn diff --git a/roles/server/ddns/files/ddns.timer b/roles/server/ddns/files/ddns.timer new file mode 100644 index 0000000..5272716 --- /dev/null +++ b/roles/server/ddns/files/ddns.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Run inadyn every 15 minutes + +[Timer] +OnCalendar=*:00,15,30,45:00 +RandomizedDelaySec=1h +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/roles/server/ddns/tasks/main.yml b/roles/server/ddns/tasks/main.yml new file mode 100644 index 0000000..203ab76 --- /dev/null +++ b/roles/server/ddns/tasks/main.yml @@ -0,0 +1,34 @@ +--- +- name: Install the config file + ansible.builtin.template: + src: templates/inadyn.conf + dest: /etc/inadyn.conf + mode: 0600 + owner: root + group: root + +- name: Create the cache directory + ansible.builtin.file: + path: /var/cache/inadyn + state: directory + mode: 0700 + owner: root + group: root + +- name: Install the unit files + ansible.builtin.copy: + src: files/{{ item }} + dest: /etc/systemd/system/{{ item }} + mode: 0644 + owner: root + group: root + loop: + - ddns.service + - ddns.timer + +- name: Enable the timer + ansible.builtin.systemd_service: + daemon_reload: true + enabled: true + name: ddns.timer + state: "started" diff --git a/roles/server/ddns/templates/inadyn.conf b/roles/server/ddns/templates/inadyn.conf new file mode 100644 index 0000000..3258a89 --- /dev/null +++ b/roles/server/ddns/templates/inadyn.conf @@ -0,0 +1,15 @@ +period = 300 +allow-ipv6 = true + +provider cloudflare.com:1 { + username = mfocko.xyz + password = {{ cloudflare_token }} + hostname = mountainside.mfocko.xyz +} + +provider cloudflare.com:2 { + username = mfocko.xyz + password = {{ cloudflare_token }} + hostname = mountainside.mfocko.xyz + wildcard = true +}