Skip to content

Instantly share code, notes, and snippets.

@NZSmartie
Created September 5, 2019 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NZSmartie/33ecd7ba811ccf97f6dc854bdd946c53 to your computer and use it in GitHub Desktop.
Save NZSmartie/33ecd7ba811ccf97f6dc854bdd946c53 to your computer and use it in GitHub Desktop.
ec2 inventory bootstrap for ansbile
#!/bin/bash
set -e
# Discover the current version of ansible
ANSILBE_VERSION=$(ansible --version | sed -rn 's/.*ansible ([0-9.]+).*/\1/p')
# If 'region = auto' is set in ec2.ini, then we need to export the region from the local aws configutation
export AWS_DEFAULT_REGION=$(aws configure get region)
# Download the ec2.py script that matches the ansible version
curl -Ss "https://raw.githubusercontent.com/ansible/ansible/v${ANSILBE_VERSION}/contrib/inventory/ec2.py" -o ec2.py
chmod a+x ec2.py
./ec2.py $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment