Created
March 29, 2017 19:35
-
-
Save bigjimmynz/d8ec69f5aa6c82690e32a5641806428e to your computer and use it in GitHub Desktop.
Autoscaling Group
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
--- | |
- name: Find existing AMI if it exists | |
local_action: | |
module: command aws ec2 describe-images --owners self --filters Name=tag-value,Values={{deploy_env}}-{{service}} --query Images[0].ImageId --output text --region {{region}} | |
register: deletable_ami | |
ignore_errors: True | |
tags: | |
- build | |
- configure | |
- name: Delete AMI snapshot | |
local_action: | |
module: ec2_ami | |
region: "{{region}}" | |
image_id: "{{deletable_ami.stdout}}" | |
state: absent | |
ignore_errors: True | |
tags: | |
- build | |
- configure | |
- name: Create AMI snapshot | |
local_action: | |
module: ec2_ami | |
region: "{{region}}" | |
instance_id: "{{tid}}" | |
wait: yes | |
no_reboot: no | |
name: "{{ami_name}}" | |
state: present | |
register: ami | |
tags: | |
- build | |
- configure | |
- name: Tag the AMI Snapshot | |
local_action: | |
module: ec2_tag | |
resource: "{{ami.image_id}}" | |
region: "{{region}}" | |
state: present | |
tags: | |
Name: "{{deploy_env}}-{{service}}" | |
Environment: "{{deploy_env}}" | |
tags: | |
- build | |
- configure | |
- name: Get current date in UTC | |
local_action: | |
module: command date -u +%Y-%m-%d_%H_%M_%S_UTC | |
register: keydate | |
tags: | |
- build | |
- configure | |
- name: Create Launch Configuration for ASG | |
local_action: | |
module: ec2_lc | |
name: "{{deploy_env}}-{{service}}-{{keydate.stdout}}" | |
image_id: "{{ami.image_id}}" | |
key_name: "{{key_name}}" | |
security_groups: ["{{sg.group_id}}"] | |
instance_type: "{{instance_type}}" | |
instance_profile_name: "{{instance_profile_name | default(omit)}}" | |
assign_public_ip: "{{assign_public_ip}}" | |
user_data: "{{bash_script | default(omit)}}" | |
state: present | |
region: "{{region}}" | |
with_items: ec2.results | |
register: lc | |
tags: | |
- build | |
- configure | |
- name: Create Auto Scale Group for service | |
local_action: | |
module: ec2_asg | |
name: "{{deploy_env}}-{{service}}" | |
health_check_period: 300 | |
health_check_type: "{{asg_health_type | default(omit)}}" | |
launch_config_name: "{{deploy_env}}-{{service}}-{{keydate.stdout}}" | |
region: "{{region}}" | |
min_size: 1 | |
max_size: "{{max}}" | |
load_balancers: "{{elb_name | default(omit)}}" | |
desired_capacity: "{{ideal}}" | |
replace_all_instances: yes | |
replace_batch_size: 1 | |
wait_for_instances: True | |
vpc_zone_identifier: ["{{all_mgmt_subnets | join(', ')}}"] | |
tags: | |
- Name: "{{deploy_env}}-{{service}}-{{visibility}}" | |
- deploy_env: "{{deploy_env}}" | |
- service: "{{service}}" | |
- region: "{{region}}" | |
- service_region: "{{service}}-{{region}}" | |
register: asg_result | |
tags: | |
- build | |
- configure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment