aboutsummaryrefslogtreecommitdiff
path: root/ansible/roles/linode-dns-update/templates
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2018-11-24 20:31:54 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2018-11-24 20:31:54 +0100
commitf985755b32cc3f3558604264823de32de557b288 (patch)
tree322a0d116a6be03a7f604f778e04e1c81f31bba2 /ansible/roles/linode-dns-update/templates
parentc25c490677bcba2c2e9fee90db10594bd43f6982 (diff)
downloadinfra-f985755b32cc3f3558604264823de32de557b288.tar.gz
infra-f985755b32cc3f3558604264823de32de557b288.tar.bz2
infra-f985755b32cc3f3558604264823de32de557b288.tar.xz
infra-f985755b32cc3f3558604264823de32de557b288.zip
o Adding Linode update code.
Diffstat (limited to 'ansible/roles/linode-dns-update/templates')
-rw-r--r--ansible/roles/linode-dns-update/templates/linode-dns-update.j245
1 files changed, 45 insertions, 0 deletions
diff --git a/ansible/roles/linode-dns-update/templates/linode-dns-update.j2 b/ansible/roles/linode-dns-update/templates/linode-dns-update.j2
new file mode 100644
index 0000000..97ab7c9
--- /dev/null
+++ b/ansible/roles/linode-dns-update/templates/linode-dns-update.j2
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+set -e
+
+# Hostname: {{ ansible_hostname }}
+URL="https://api.linode.com/"
+USERNAME="{{ linode_dns__api_username }}"
+KEY="{{ linode_dns__api_key }}"
+DOMAIN_ID="{{ linode_dns__domain_id }}"
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin:
+
+req() {
+ PARAMS=()
+ for p in "$@"
+ do
+ PARAMS+=(-F "$p")
+ done
+
+ curl \
+ -4 \
+ --user "$USERNAME:$KEY" -s \
+ "${PARAMS[@]}" \
+ "$URL" >/dev/null # | jq
+}
+
+domain_resource_update() {
+ req api_action=domain.resource.update DomainId="$1" ResourceId="$2" Type="$3" Target="$4"
+}
+
+{% if linode_dns__ipv4_resource is defined %}
+domain_resource_update "$DOMAIN_ID" "{{ linode_dns__ipv4_resource }}" "A" "[remote_addr]"
+{% endif %}
+
+{% if linode_dns__ipv6_resource is defined %}
+q=''
+#q='map(select(.ifname=="wlx00e01d0808b2"))'
+q='map(.addr_info) | flatten | map(select(.scope=="global" and .deprecated != true and .mngtmpaddr != true) | .local) | first'
+ip=$(ip -6 -json addr | jq -r -c "$q")
+
+if [[ ! -z $ip ]]
+then
+ domain_resource_update "$DOMAIN_ID" "{{ linode_dns__ipv6_resource }}" "AAAA" "$ip"
+fi
+{% endif %}