Created
May 19, 2016 09:11
-
-
Save oli-logicnow/a14d380a86f16779cc0068b0ca4edd95 to your computer and use it in GitHub Desktop.
UserData scripts for EC with Ansible (via Cloudformation)
This file contains 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
"UserData": "{{ launch_script | b64encode}}" |
This file contains 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
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. |
This file contains 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
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