Update DuckDNS subdomain with dynamic IP

This commit is contained in:
Kris Lamoureux 2020-08-26 20:26:05 -04:00
parent 97d920d09d
commit 10a39235bb
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925
3 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,11 @@
- name: Install DuckDNS script
template:
src: duckdns.sh.j2
dest: /usr/local/bin/update-duckdns
mode: 0700
- name: Install DuckDNS cron
cron:
name: Update DuckDNS
minute: "*/5"
job: /usr/local/bin/update-duckdns

View File

@ -7,3 +7,7 @@
- import_tasks: network.yml - import_tasks: network.yml
tags: network tags: network
when: manage_network when: manage_network
- import_tasks: duckdns.yml
tags: duckdns
when: duckdns is defined

View File

@ -0,0 +1,20 @@
#!/bin/bash
domains="{{ duckdns.domains }}"
token="{{ duckdns.token }}"
{% if duckdns.logfile is undefined -%}
log="/var/log/duckdns.log"
{% else -%}
log="{{ duckdns.logfile }}"
{% endif %}
url="https://www.duckdns.org/update?domains=$domains&token=$token&ip="
time=$(date '+%Y%m%d-%H%M%S')
result=$(curl $url)
if [ "$result" = "OK" ]; then
echo "[$time] OK" >> $log
else
echo "[$time] ERROR: $result" >> $log
fi