Created
May 4, 2019 09:43
-
-
Save dragolabs/a5491f4edcdc1326ce44d2e6fe4c0a38 to your computer and use it in GitHub Desktop.
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
# Set up AWS CLI, we don't use Amazon Linux so we need this | |
export AWS_REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}') | |
mkdir -p /root/.aws | |
echo -e "[default]\nregion=$AWS_REGION" | tee /root/.aws/config | |
# Get tags from the API | |
export FQDN=$(aws ec2 describe-tags --filters "Name=resource-id,Values=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)" "Name=key,Values=fqdn" --output=text | cut -f 5) | |
# Set hostname | |
if [ -n "$FQDN" ]; then | |
hostnamectl set-hostname --static $FQDN | |
echo 'preserve_hostname: true' | tee -a /etc/cloud/cloud.cfg | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment