Skip to content

Instantly share code, notes, and snippets.

@z0mbix
Created July 3, 2015 23:39
Show Gist options
  • Save z0mbix/718e70eac2d6455111b7 to your computer and use it in GitHub Desktop.
Save z0mbix/718e70eac2d6455111b7 to your computer and use it in GitHub Desktop.
Bootstrap an EC2 instance with it's role, environment and name
#!/usr/bin/env bash
meta_url="http://169.254.169.254/latest/meta-data"
instance_id=$(curl -sf ${meta_url}/instance-id)
# Get role
aws ec2 describe-tags --filters \
"Name=resource-type,Values=instance" \
"Name=resource-id,Values=${instance_id}" \
"Name=key,Values=role" \
| jq -r .Tags[].Value > /etc/server-role
# Custom fact for puppet
cat /etc/server-role | sed "s/\(.*\)/role=\1/g" > /etc/facter/facts.d/role.txt
# Get environment
aws ec2 describe-tags --filters \
"Name=resource-type,Values=instance" \
"Name=resource-id,Values=${instance_id}" \
"Name=key,Values=environment" \
| jq -r .Tags[].Value > /etc/server-environment
# Get name
aws ec2 describe-tags --filters \
"Name=resource-type,Values=instance" \
"Name=resource-id,Values=${instance_id}" \
"Name=key,Values=Name" \
| jq -r .Tags[].Value > /etc/server-name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment