-
-
Save mloayzagahona/80a68dac40d82fe86ac87d4668e3e347 to your computer and use it in GitHub Desktop.
provision ec2 instance with ansible with user-data
This file contains hidden or 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
# link: http://allandenot.com/devops/2015/01/31/provisioning-ec2-hosts-with-ansible.html | |
--- | |
- name: Provision EC2 Box | |
local_action: | |
module: ec2 | |
key_name: "{{ ec2_keypair }}" | |
group_id: "{{ ec2_security_group }}" | |
instance_type: "{{ ec2_instance_type }}" | |
image: "{{ ec2_image }}" | |
vpc_subnet_id: "{{ ec2_subnet_ids|random }}" | |
region: "{{ ec2_region }}" | |
user_data: "{{ user_data }}" | |
instance_tags: '{"Name":"{{ec2_tag_Name}}","Type":"{{ec2_tag_Type}}","Environment":"{{ec2_tag_Environment}}"}' | |
assign_public_ip: yes | |
wait: true | |
count: 1 | |
volumes: | |
- device_name: /dev/sda1 | |
device_type: gp2 | |
volume_size: "{{ ec2_volume_size }}" | |
delete_on_termination: true | |
register: ec2 | |
# in vars file (e.g. webserver.yml) | |
user_data: "{{ lookup('file', 'user-data.sh') }}" | |
# create user-data.sh and add anything that you would want to run during provisioning | |
# example is given below | |
#!/bin/bash | |
apt-get update | |
apt-get install -y git wget | |
# Install Docker | |
wget -qO- get.docker.com | sh & | |
wait | |
service docker start | |
# Start Codespaces | |
cd /root | |
git clone https://github.com/codespaces-io/codespaces.git | |
curl -L "https://github.com/docker/compose/releases/download/1.11.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | |
chmod +x /usr/local/bin/docker-compose | |
cd /root/codespaces/cs-chef-ci | |
docker-compose up -d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment