diff options
Diffstat (limited to 'roles/ddns.notyet/templates/update-dns.j2')
-rw-r--r-- | roles/ddns.notyet/templates/update-dns.j2 | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/roles/ddns.notyet/templates/update-dns.j2 b/roles/ddns.notyet/templates/update-dns.j2 new file mode 100644 index 0000000..4d68666 --- /dev/null +++ b/roles/ddns.notyet/templates/update-dns.j2 @@ -0,0 +1,24 @@ +#!/bin/sh +set -e + +api_email=jodersky@gmail.com +api_key={{ddns_api_key}} +zone_name={{ddns_zone}} +record_name={{ddns_record}} + +cf() { + curl \ + -sS \ + -H "X-Auth-Email: $api_email"\ + -H "X-Auth-Key: $api_key"\ + -H "Content-Type: application/json"\ + $@ +} + +external_ip=$(dig +short myip.opendns.com @resolver1.opendns.com) +zone_id=$(cf -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone_name" | jq -r '.result[0].id') +record_id=$(cf -X GET "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records?name=$record_name" | jq -r '.result[0].id') + +cf -X PUT "https://api.cloudflare.com/client/v4/zones/${zone_id}/dns_records/${record_id}" \ + --data {\"type\":\"A\",\"name\":\""$record_name"\",\"content\":\""$external_ip"\"} \ + || (echo "Error updating IP address." >&2 && exit 1) |