Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ddoc
Created January 16, 2014 00:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddoc/8447483 to your computer and use it in GitHub Desktop.
Save ddoc/8447483 to your computer and use it in GitHub Desktop.
rdns creation script for foreman hooks https://github.com/theforeman/foreman_hooks. More information at: http://www.brian2.net/posts/foreman_hooks_aws_vpc/
#!/bin/bash
. /usr/share/foreman/config/hooks.d/lib/utils.sh
. $FOREMAN_HOME/config/hooks.d/lib/hook_functions.sh
set -x
IP=$(hook_data host.ip)
DNSNAME=$(hook_data host.name)
REVERSE=$(reverseIp ${IP})
rdns_create() {
echolog IP ${IP} calling nsupdate: dns3.server.name update add ${REVERSE}.in-addr.arpa. 86400 PTR $DNSNAME
cat << EOF | nsupdate -y 'VIEW******************'
server dns.server.name
update add ${REVERSE}.in-addr.arpa. 86400 PTR $DNSNAME
send
quit
EOF
}
rdns_destroy() {
echolog IP: $IP calling nsupdate: dns.server.name update delete ${REVERSE}.in-addr.arpa. PTR $DNSNAME
cat << EOF | nsupdate -y 'VIEW******************'
server dns.server.name
update delete ${REVERSE}.in-addr.arpa. PTR $DNSNAME
send
quit
EOF
}
case "$HOOK_EVENT" in
create)
rdns_create
;;
destroy)
rdns_destroy
;;
update)
echolog no action for update
;;
*)
echo "Usage: run_hooks {create|destroy|update}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment