Skip to content

Instantly share code, notes, and snippets.

@atrepca
Last active August 29, 2015 14:12
Show Gist options
  • Save atrepca/b2551afeeb3fc3c59d58 to your computer and use it in GitHub Desktop.
Save atrepca/b2551afeeb3fc3c59d58 to your computer and use it in GitHub Desktop.
Create custom Puppet fact from AWS EC2 instance tags
#!/bin/bash
# Requirements:
# * aws-cli: https://github.com/aws/aws-cli
# * IAM roles or aws access key and secret in place
TAG_NAME="mytag"
INSTANCE_ID="$(/usr/bin/curl -s http://instance-data/latest/meta-data/instance-id)"
REGION="$(/usr/bin/curl -s http://instance-data/latest/meta-data/placement/availability-zone | /bin/sed -e 's/[a-z]$//')"
TAG_VALUE="$(/usr/local/bin/aws ec2 describe-tags --filters "Name=resource-id,Values=${INSTANCE_ID}" "Name=key,Values=${TAG_NAME}" --region ${REGION} --output=text | /usr/bin/cut -f5)"
echo "mytag_fact=${TAG_VALUE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment