From b75a45ea2432f5043035d04d46bb9fd332ebb385 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Tue, 5 Feb 2013 16:54:40 +0100 Subject: [PATCH] puppet/apply.sh: provide fallback for EC2 IP retrieval Debian's AMI[1] doesn't provide anything inside 'facter ec2_public_ipv4', so let's try the manual approach then before really falling back to 'ip addr ...' hackery to avoid retrieval of internal IP on Debian's AMI/EC2 system. [1] http://wiki.debian.org/Cloud/AmazonEC2Image --- puppet/apply.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/puppet/apply.sh b/puppet/apply.sh index d8ad415..3a1c2ee 100644 --- a/puppet/apply.sh +++ b/puppet/apply.sh @@ -73,6 +73,11 @@ fi # Amazon EC2 returns the internal IP by default, so ask about the public one IP=$(facter ec2_public_ipv4 2>/dev/null) # curl http://169.254.169.254/latest/meta-data/public-ipv4 +# 'facter ec2_public_ipv4' returns nothing on Debian's AMI :( +if [ -z "$IP" ] ; then + IP=$(curl --connect-timeout 3 http://169.254.169.254/latest/meta-data/public-ipv4 2>/dev/null) +fi +# not using EC2? fallback then if [ -z "$IP" ] ; then IP=$(ip addr show dev $(route -n | awk '/^0\.0\.0\.0/{print $NF}') | awk '/inet / {print $2}' | head -1 |sed "s;/.*;;") fi