#!/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 and (.local|test("^fd")|not)) | .local) | first' ip=$(ip -6 -json addr | jq -r -c "$q") if [[ ! -z $ip ]] then echo "Setting IPv6 to $ip." domain_resource_update "$DOMAIN_ID" "{{ linode_dns__ipv6_resource }}" "AAAA" "$ip" fi {% endif %}