Ansible Role that can be used either for doing Rolling Deployment on the ASG or just updating some ASG parameters.
- Python >= 2.7
- boto3 == 1.8.2
- ansible == 2.5.8
It is recommended to use virtualenv and pip to install both boto3 and ansible.
Requirements mentioned above are based on these modules which are used in this role:
- debug - Print statements during execution
- fail - Fail with custom message
- ec2_ami_facts - Gather facts about ec2 AMIs
- ec2_asg - Create or delete AWS Autoscaling Groups
- ec2_asg_facts - Gather facts about ec2 Auto Scaling Groups (ASGs) in AWS
- ec2_lc - Create or delete AWS Autoscaling Launch Configurations
- ec2_lc_facts - Gather facts about AWS Autoscaling Launch Configurations
- set_fact - Set host facts from a task
- sts_assume_role - Assume a role using AWS Security Token Service and obtain temporary credentials
- name: asg_wait_timeout
description: How long in seconds to wait for instances to become viable when replaced.
value: 3600
- name: ebs_device_name
description: The name of the volume to mount.
value: /dev/sda1
- name: ebs_volume_size
description: The size of the volume in gigabytes.
value: 8
- name: ebs_volume_type
description: The type of volume.
value: gp2
- name: ebs_delete_on_termination
description: Whether the volume should be destroyed on instance termination.
value: true
- name: launch_configuration_name_suffix
description: Suffix that will be added to Launch Configurations which are going to be created and deleted by this role.
value: rolling
- name: aws_pda_role_arn
description: The Amazon Resource Name (ARN) of ProductDomainAdmin role that the caller is assuming.
- name: aws_mfa_serial
description: The identification number of the MFA device that is associated with the user who is making the AssumeRole call.
- name: aws_mfa_token
description: The value provided by the MFA device.
- name: aws_region
description: The AWS region to use.
- name: ami_id
description: The AMI unique identifier to be used for new Launch Configuration.
- name: asg_name
description: The name of the Autoscaling Group that you are going to modify.
- name: service_name
description: The name of the service.
- name: cluster_role
description: The role/function of the cluster.
- name: service_version
description: The version of the service. This will be added as part of the Launch Configuration name. You have to replace this value each time you release new software / use new AMI.
- name: service_environment
description: The environment of this service belongs to.
- name: instance_user_data
description: Several commands that you want to execute on the instance when the instance is launched. Read more: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
- name: asg_max_size
description: Maximum number of instances in group, if unspecified then the current group value will be used.
- name: asg_min_size
description: Minimum number of instances in group, if unspecified then the current group value will be used.
- name: asg_desired_capacity
description: Desired number of instances in group, if unspecified then the current group value will be used.
- name: asg_replace_batch_size
description: Number of instances you'd like to replace at a time, if unspecified then the default value is 1.
- name: asg_health_check_type
description: Controls how health checking is done, if unspecified then the current group value will be used.
- name: asg_health_check_grace_period
description: Length of time in seconds after a new EC2 instance comes into service that Auto Scaling starts checking its health, if unspecified then the current group value will be used.
- name: instance_type
description: The type of the istance to launch in ASG, if unspecified then the current group value will be used.
- The AWS EC2 ASG is already provisioned
---
- hosts: localhost
connection: local
vars:
# set common_java_opts in supervisor using the ami baking playbook!
app_memory_java_opts: >-
-Xms1g -Xmx1g -XX:PermSize=512m -XX:MaxPermSize=512m
instance_count: 1
roles:
- role: ansible-blue_green-lc-deploy
aws_pda_role_arn: arn:aws:iam::123456789012:role/ProductDomainAdmin
aws_mfa_serial: arn:aws:iam::123456789012:mfa/rafi.putra
aws_region: ap-southeast-1
service_name: tsiasg
cluster_role: app
service_version: 0.1.0
service_environment: production
ami_id: ami-0a1b2c3d4e5f67890
asg_name: tsiasg-app-7e44f6f512903a59
asg_min_size: "{{ instance_count }}"
asg_max_size: "{{ instance_count }}"
asg_desired_capacity: "{{ instance_count }}"
instance_user_data: |
#cloud-config
bootcmd:
- JAVA_OPTS="{{ app_memory_java_opts }}" TRAVELOKA_ENV="production" /etc/init.d/supervisor start
runcmd:
- /opt/init/init-instance /dummy/data/dd.key
MIT