Commit 68e1fef0 by Brian Beggs

Ansible playbook to launch an instance for the release-pipeline work.

parent 2fea6a16
# This playbook will launch an ec2 instance in a VPC.
# This instance will have an autogenerated key.
#
# required variables for this playbook:
# - ec2_subnet_id - Subnet to bring up the ec2 instance
# - base_ami_id - The base base AMI-ID
# - ec2_vpc_subnet_id - The Subnet ID to bring up the instance
# - ec2_security_group_id - The security group ID to use
#
# Other Variables:
# - ec2_region - The region the server should be brought up in
# - ec2_instance_type - The instance type to use
# - ebs_volume_size - Size in GB for the root volume
# - ec2_timeout - Time in seconds to wait for an ec2 instance become available
# - ec2_assign_public_ip - (yes/no) should the instance have a public IP address?
#
# This playbook generates a directory with 2 artifact files:
# - launch_template.yml - A yaml file with information such as the instance ID and internal IP address of the instance launched
# - key.pem - The private key file for the newly generated keypair
#
# Example command line to run this playbook:
# ansible-playbook -i "localhost," -c local -e @overrides.yml launch_instance.yml
#
- hosts: all
vars:
artifact_path: /tmp/ansible-runtime
ec2_region: us-east-1
ec2_instance_type: t2.medium
ebs_volume_size: 8
ec2_timeout: 500
ec2_assign_public_ip: no
gather_facts: False
connection: local
tasks:
- name: Generate UUID for keypair
command: cat /proc/sys/kernel/random/uuid
register: unique_key_name
- name: Generate ec2 keypair to use for this instance
ec2_key:
name: "{{ unique_key_name.stdout }}"
region: "{{ ec2_region }}"
register: ssh_key_register
- name: Ensure artifact directory exists
file:
path: "{{ artifact_path }}/{{ unique_key_name.stdout }}/"
state: directory
force: yes
- name: Launch EC2 instance
ec2:
instance_tags: {"Name" : "gocd automation run -- {{ unique_key_name.stdout }}"}
region: "{{ ec2_region }}"
key_name: "{{ unique_key_name.stdout }}"
instance_type: "{{ ec2_instance_type }}"
image: "{{ base_ami_id }}"
wait: yes
group_id: "{{ ec2_security_group_id }}"
count: 1
vpc_subnet_id: "{{ ec2_vpc_subnet_id }}"
assign_public_ip: "{{ ec2_assign_public_ip }}"
volumes:
- device_name: /dev/xvda
volume_type: standard
volume_size: "{{ ebs_volume_size }}"
wait: yes
wait_timeout: "{{ ec2_timeout }}"
register: ec2_instance_register
- name: Wait for SSH to come up
wait_for:
host: "{{ ec2_instance_register.instances[0].private_ip }}"
port: 22
delay: 60
timeout: "{{ ec2_timeout }}"
state: started
- name: Generate artifact for jobs down stream
template:
src: templates/local/launch_template.yml.j2
dest: "{{ artifact_path }}/{{ unique_key_name.stdout }}/launch_info.yml"
mode: 0600
- name: Generate key material artifact for jobs down stream
template:
src: templates/local/key.pem.j2
dest: "{{ artifact_path }}/{{ unique_key_name.stdout }}/key.pem"
mode: 0600
../roles
\ No newline at end of file
{{ ssh_key_register.key.private_key }}
\ No newline at end of file
keypair_id: {{ unique_key_name.stdout }}
key_material_file: {{ artifact_path }}/{{ unique_key_name.stdout }}/key.pem
instance_id: {{ ec2_instance_register.instances[0].id }}
instance_ip: {{ ec2_instance_register.instances[0].private_ip }}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment