Skip to content

Instantly share code, notes, and snippets.

@oli-logicnow
Created May 19, 2016 09:11
Show Gist options
  • Save oli-logicnow/a14d380a86f16779cc0068b0ca4edd95 to your computer and use it in GitHub Desktop.
Save oli-logicnow/a14d380a86f16779cc0068b0ca4edd95 to your computer and use it in GitHub Desktop.
UserData scripts for EC with Ansible (via Cloudformation)
"UserData": "{{ launch_script | b64encode}}"
These are snippets from a piece of work where we're defining an AutoScaling group where the instanes are launched with a User Data script which downloads the build from S3 and installs it.
The install script is managed as a multi-line variable in the Ansible Playbook, which uses a Jinja2 Template to render a CloudFormation Template (for reasons), which is then pushed into CloudFormation
The technique of mult-line script as variable + base64encoding could be used for normal instances too.
launch_script: |
#!/bin/bash
export INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
export REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}')
# install stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment