diff --git a/roles/ddns/defaults/main.yml b/roles/ddns/defaults/main.yml new file mode 100644 index 0000000..2c60a68 --- /dev/null +++ b/roles/ddns/defaults/main.yml @@ -0,0 +1,12 @@ +--- +# Domain for which the DDNS manages DDNS entries +ddns_domain: None + +# List of all subdomains on the said domain for which the IP should be set +ddns_subdomains: [] + +# ‹apikey› provided by Porkbun +ddns_porkbun_apikey: None + +# ‹secretapikey› provided by Porkbun +ddns_porkbun_secretapikey: None diff --git a/roles/ddns/files/ddns.service b/roles/ddns/files/ddns.service deleted file mode 100644 index 08602fa..0000000 --- a/roles/ddns/files/ddns.service +++ /dev/null @@ -1,7 +0,0 @@ -[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/ddns/files/ddns.timer b/roles/ddns/files/ddns.timer deleted file mode 100644 index 5272716..0000000 --- a/roles/ddns/files/ddns.timer +++ /dev/null @@ -1,10 +0,0 @@ -[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/ddns/tasks/main.yml b/roles/ddns/tasks/main.yml index 203ab76..088ee17 100644 --- a/roles/ddns/tasks/main.yml +++ b/roles/ddns/tasks/main.yml @@ -1,34 +1,23 @@ --- -- name: Install the config file +- name: Install the config file for DDNS ansible.builtin.template: - src: templates/inadyn.conf - dest: /etc/inadyn.conf + src: templates/ddns.ini + dest: /etc/ddns.ini 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 }} +- name: Install the DDNS quadlet + ansible.builtin.template: + src: templates/ddns.container + dest: /etc/containers/systemd/ddns.container mode: 0644 owner: root group: root - loop: - - ddns.service - - ddns.timer -- name: Enable the timer +- name: Enable the DDNS quadlet ansible.builtin.systemd_service: daemon_reload: true enabled: true - name: ddns.timer + name: ddns.service state: "started" diff --git a/roles/ddns/templates/ddns.container b/roles/ddns/templates/ddns.container new file mode 100644 index 0000000..4cb89b0 --- /dev/null +++ b/roles/ddns/templates/ddns.container @@ -0,0 +1,12 @@ +[Unit] +Description=DDNS Update + +[Container] +Image=docker.io/mietzen/porkbun-ddns:latest +EnvironmentFile=/etc/ddns.ini + +[Service] +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/roles/ddns/templates/ddns.ini b/roles/ddns/templates/ddns.ini new file mode 100644 index 0000000..ad73d03 --- /dev/null +++ b/roles/ddns/templates/ddns.ini @@ -0,0 +1,4 @@ +DOMAIN={{ ddns_domain }} +SUBDOMAINS={{ ','.join(ddns_subdomains) }} +APIKEY={{ ddns_porkbun_apikey }} +SECRETAPIKEY={{ ddns_porkbun_secretapikey }} diff --git a/roles/ddns/templates/inadyn.conf b/roles/ddns/templates/inadyn.conf deleted file mode 100644 index 52bfa62..0000000 --- a/roles/ddns/templates/inadyn.conf +++ /dev/null @@ -1,15 +0,0 @@ -period = 300 -allow-ipv6 = true - -provider cloudflare.com:1 { - username = {{ cloudflare_zone }} - password = {{ cloudflare_token }} - hostname = {{ host_fqdn }} -} - -provider cloudflare.com:2 { - username = {{ cloudflare_zone }} - password = {{ cloudflare_token }} - hostname = {{ host_fqdn }} - wildcard = true -}