Skip to content

Instantly share code, notes, and snippets.

@s-hertel
Created March 20, 2017 18:20
Show Gist options
  • Save s-hertel/4783d0bdffe36675b8ebe603aee89fab to your computer and use it in GitHub Desktop.
Save s-hertel/4783d0bdffe36675b8ebe603aee89fab to your computer and use it in GitHub Desktop.
---
- hosts: localhost
connection: local
tasks:
- name: create a vpc
ec2_vpc_net:
name: ansible-test-vpc
cidr_block: 10.10.0.0/16
profile: "{{ profile }}"
region: us-east-1
register: vpc
- name: internet gateway for vpc
ec2_vpc_igw:
profile: "{{ profile }}"
region: us-east-1
vpc_id: "{{ vpc['vpc']['id'] }}"
state: present
- name: create a subnet with the vpc
ec2_vpc_subnet:
state: present
vpc_id: "{{ vpc['vpc']['id'] }}"
cidr: 10.10.0.0/16
region: us-east-1
resource_tags:
name: ansible-test-subnet
az: us-east-1a
profile: "{{ profile }}"
register: subnet
- name: create a security group with the vpc
ec2_group:
name: ansible-test-sg
description: a security group for ansible tests
vpc_id: "{{ vpc['vpc']['id'] }}"
region: us-east-1
rules:
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 0.0.0.0/0
profile: "{{ profile }}"
register: sg
- name: make launch config
ec2_lc:
name: ansible-test-lc
profile: "{{ profile }}"
region: us-east-1
image_id: ami-964a0efe
security_groups: "{{ sg['group_id'] }}"
instance_type: t2.micro
- name: launch load balancer
ec2_elb_lb:
name: ansible-test-lb
state: present
region: us-east-1
profile: "{{ profile }}"
security_group_ids:
- "{{ sg['group_id'] }}"
subnets: "{{ subnet['subnet']['id'] }}"
connection_draining_timeout: 60
listeners:
- protocol: http
load_balancer_port: 80
instance_port: 80
health_check:
ping_protocol: http
ping_port: 80
ping_path: "/index.html"
response_timeout: 20
interval: 40
unhealthy_threshold: 4
healthy_threshold: 2
- name: launch asg and wait for instances to be deemed healthy (ELB)
ec2_asg:
name: ansible-test-asg
availability_zones:
- us-east-1a
vpc_zone_identifier: "{{ subnet['subnet']['id'] }}"
profile: "{{ profile }}"
launch_config_name: ansible-test-lc
health_check_type: ELB
desired_capacity: 1
min_size: 1
max_size: 1
health_check_period: 120
load_balancers: ansible-test-lb
region: us-east-1
wait_for_instances: yes
wait_timeout: 2000
state: present
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment