Skip to content

Instantly share code, notes, and snippets.

@sh4t
sh4t / cloudflare-update-record.sh
Created June 18, 2018 02:05 — forked from benkulbertis/cloudflare-update-record.sh
Cloudflare API v4 Dynamic DNS Update in Bash
#!/bin/bash
# CHANGE THESE
auth_email="user@example.com"
auth_key="c2547eb745079dac9320b638f5e225cf483cc5cfdda41" # found in cloudflare account settings
zone_name="example.com"
record_name="www.example.com"
# MAYBE CHANGE THESE
ip=$(curl -s http://ipv4.icanhazip.com)
require 'facter'
if Facter.value("ec2_instance_id") != nil
instance_id = Facter.value("ec2_instance_id")
region = Facter.value("ec2_placement_availability_zone")[0..-2]
tags = Facter::Util::Resolution.exec("ec2dtag --filter \"resource-id=#{instance_id}\" --region #{region} | cut -f 4-|awk 'BEGIN{FS=\" \";OFS=\"|\"} {$1=$1; print $0}'")
tags.scan(/(.*)\|+(.*)/) do |key, value|
fact = "ec2_tag_#{key}"
Facter.add(fact) { setcode { value } }
end