Skip to content

Commit b230c2b

Browse files
pinkeenkrisdante
authored andcommittedMay 11, 2021
Disable rolling instance update when maintenance mode is enabled
Speed up the ASG deploy by replacing all instances at once if DB migrations are needed. In this case we don't need rolling update since we enable maintenance mode anyway.
1 parent 047435e commit b230c2b

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed
 

‎group_vars/all.yml

+3
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,9 @@ aws_logs_log_magento_crash_reports: yes
542542
aws_autoscaling_triggers_list: []
543543
aws_autoscaling_lambda_functions_list: []
544544

545+
# See defaults in role `cs.aws-autoscaling`
546+
aws_autoscaling_rolling_instance_refresh_min_healthy_percent: 90
547+
545548
# ----------------------------------------
546549
# -------- MageOps Basic Config --------
547550
# ----------------------------------------

‎roles/cs.aws-autoscaling/defaults/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ aws_asg_instance_refresh_cli_args_base: [
5353
--color, "off",
5454
--no-paginate,
5555
]
56+

‎roles/cs.aws-autoscaling/tasks/refresh-instances.yml

+22-16
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
+ aws_asg_instance_refresh_cli_args_base
66
+ [ '--cli-input-json', aws_asg_instance_refresh_params | to_json ] }}
77
vars:
8-
aws_asg_instance_refresh_params:
9-
AutoScalingGroupName: "{{ autoscaling_asg_name }}"
10-
# Note: A futureproof setting - there is no other strategy as of yet.
11-
Strategy: Rolling
12-
Preferences:
13-
MinHealthyPercentage: "{{ autoscaling_rolling_instance_refresh_min_healthy_percent }}"
14-
InstanceWarmup: "{{ autoscaling_rolling_instance_refresh_extra_warmup_grace_period }}"
8+
# This is rendered in template string directly on purpose
9+
# as otherwise ansible will pass numbers as string causing API error.
10+
aws_asg_instance_refresh_params: >-
11+
{{
12+
{
13+
"AutoScalingGroupName": autoscaling_asg_name,
14+
"Strategy": "Rolling",
15+
"Preferences": {
16+
"MinHealthyPercentage": autoscaling_rolling_instance_refresh_min_healthy_percent | int,
17+
"InstanceWarmup": autoscaling_rolling_instance_refresh_extra_warmup_grace_period | int
18+
}
19+
}
20+
}}
1521
register: aws_asg_instance_refresh_command
1622

1723
- name: Compute instance refresh task info
@@ -20,7 +26,7 @@
2026
aws_asg_instance_refresh_estimated_duration: >-
2127
{{ ( ( autoscaling_healthcheck_grace_period | int
2228
+ autoscaling_rolling_instance_refresh_extra_warmup_grace_period | int )
23-
* autoscaling_asg_desired_capacity | int
29+
* autoscaling_asg_desired_capacity | int
2430
* ( autoscaling_rolling_instance_refresh_min_healthy_percent | int + 100 )
2531
/ 100 ) | round(1, 'ceil') }}
2632
@@ -54,7 +60,7 @@
5460
"- \(.PercentageComplete)% complete", "/ \(.InstancesToUpdate) left",
5561
( if .StatusReason then "(\(.StatusReason))" else "" end ) ] | join(" "))'; \
5662
done
57-
63+
5864
========================================================
5965
6066
- name: Wait for the rolling Instance Refresh to complete
@@ -67,16 +73,16 @@
6773
aws_asg_instance_describe_refresh_params:
6874
AutoScalingGroupName: "{{ autoscaling_asg_name }}"
6975
InstanceRefreshIds: [ "{{ aws_asg_instance_refresh_id }}" ]
70-
aws_asg_instance_describe_data: >-
71-
{{ ( aws_asg_describe_instance_refresh_command.stdout
72-
| default('{"Status": null, "PercentageComplete": -1}')
76+
aws_asg_instance_describe_data: >-
77+
{{ ( aws_asg_describe_instance_refresh_command.stdout
78+
| default('{"Status": null, "PercentageComplete": -1}')
7379
| from_json ).InstanceRefreshes | first }}
7480
register: aws_asg_describe_instance_refresh_command
7581
until: >-
76-
aws_asg_describe_instance_refresh_command is not failed
82+
aws_asg_describe_instance_refresh_command is not failed
7783
and aws_asg_instance_describe_data.PercentageComplete | default(0, true) | int == 100
7884
and aws_asg_instance_describe_data.Status == 'Successful'
7985
delay: "{{ aws_asg_instance_refresh_progress_check_interval }}"
80-
retries: >-
81-
{{ ( aws_asg_instance_refresh_progress_check_timeout | int
82-
/ aws_asg_instance_refresh_progress_check_interval | int ) | int }}
86+
retries: >-
87+
{{ ( aws_asg_instance_refresh_progress_check_timeout | int
88+
/ aws_asg_instance_refresh_progress_check_interval | int ) | int }}

‎site.step-60-autoscaling.yml

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
- hosts: localhost
3535
connection: local
3636
vars:
37+
# Disable rolling updates when enabling maintenance mode to speed
38+
# the refresh up...
39+
autoscaling_rolling_instance_refresh_min_healthy_percent: >-
40+
{{
41+
aws_ami_app_node_needs_db_migrations | default(true) | ternary(
42+
0,
43+
aws_autoscaling_rolling_instance_refresh_min_healthy_percent
44+
)
45+
}}
46+
3747
aws_app_node_security_group_ids: >-
3848
{{
3949
[

0 commit comments

Comments
 (0)