Update DuckDNS subdomain with dynamic IP
This commit is contained in:
parent
97d920d09d
commit
10a39235bb
11
roles/base/tasks/duckdns.yml
Normal file
11
roles/base/tasks/duckdns.yml
Normal 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
|
@ -7,3 +7,7 @@
|
||||
- import_tasks: network.yml
|
||||
tags: network
|
||||
when: manage_network
|
||||
|
||||
- import_tasks: duckdns.yml
|
||||
tags: duckdns
|
||||
when: duckdns is defined
|
||||
|
20
roles/base/templates/duckdns.sh.j2
Normal file
20
roles/base/templates/duckdns.sh.j2
Normal 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
|
Loading…
Reference in New Issue
Block a user