Created
November 16, 2012 18:26
-
-
Save zircote/4089659 to your computer and use it in GitHub Desktop.
Route53 Hostname Injection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# @c Robert Allen [email protected] | |
# | |
# /usr/bin/ec2_name | |
if [ -f /etc/profile.d/aws-apitools-common.sh ]; then | |
. /etc/profile.d/aws-apitools-common.sh | |
export PATH=/opt/aws/bin:$PATH | |
fi | |
ec2-describe-tags -O $AWS_ACCESS_KEY_ID -W $AWS_SECRET_ACCESS_KEY \ | |
--filter "resource-id=${1}" \ | |
--filter "resource-type=instance" --filter "key=Name" | cut -f5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# @c Robert Allen [email protected] | |
# | |
# /usr/bin/r53inject.sh | |
source /etc/profile.d/aws-apitools-common.sh | |
source /root/.credentials.txt | |
EC2_INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id` | |
HOSTNAME=`ec2_name ${EC2_INSTANCE_ID}` | |
if [ ! "$HOSTNAME" ]; then | |
HOSTNAME=${EC2_INSTANCE_ID} | |
fi | |
echo $HOSTNAME | |
R53_ZONE="pci.aws.ifbyphone.com" | |
FQDN="${HOSTNAME}.${R53_ZONE}" | |
echo "interface "eth0" {" > /etc/dhcp/dhclient.conf | |
echo " supersede host-name \"${HOSTNAME}\";" >> /etc/dhcp/dhclient.conf | |
echo " supersede domain-name \"${R53_ZONE} ec2.internal\";" >> /etc/dhcp/dhclient.conf | |
echo "}" >> /etc/dhcp/dhclient.conf | |
echo "${FQDN}" > /etc/hostname | |
hostname --file /etc/hostname | |
_IPV4_TEST=`curl --write-out %{http_code} --silent --output /dev/null http://169.254.169.254/latest/meta-data/public-ipv4` | |
if [ ${_IPV4_TEST} -eq 200 ]; then | |
R53_VAL=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4` | |
else | |
R53_VAL=`curl -s http://169.254.169.254/latest/meta-data/local-ipv4` | |
fi | |
cli53 rrcreate -x 600 -r ${R53_ZONE} ${HOSTNAME} A ${R53_VAL} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment