-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollback-autoscaling-alb.yml
73 lines (59 loc) · 2.6 KB
/
rollback-autoscaling-alb.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
# ./playbook.sh rollback-autoscaling-alb.yml -e project=apollo -e role=app -e env=production
#
# Reverses changes made by `deploy-autoscaling-alb.yml` to effect rollback
# of a deployment.
- name: Identify auto scaling groups
hosts: localhost
connection: local
pre_tasks:
- name: Validate arguments
assert:
that:
- env is defined
- project is defined
- role is defined
msg: "Missing required arguments: env and/or project and/or role"
tasks:
- name: Identify the live stage group
ec2_asg_facts:
tags:
env: "{{ env }}"
project: "{{ project }}"
role: "{{ role }}"
stage: live
register: current_group
failed_when: "{{ current_group.results | length != 1 }}"
tags: find
- name: Identify the post stage group
ec2_asg_facts:
tags:
env: "{{ env }}"
project: "{{ project }}"
role: "{{ role }}"
stage: post
register: new_group
failed_when: "{{ new_group.results | length != 1 }}"
tags: find
- hosts: localhost
connection: local
tasks:
- name: Perform rollback from post to live, and live to pre
ec2_asg_cutover_target_groups:
current_group_name: "{{ current_group.results[0].auto_scaling_group_name }}"
new_group_name: "{{ new_group.results[0].auto_scaling_group_name }}"
rollback_on_failure: yes
tags: cutover
- name: Tag the live stage group
ec2_asg:
name: "{{ new_group.results[0].auto_scaling_group_name }}"
health_check_type: "{{ new_group.results[0].health_check_type }}" # required to prevent resetting to the default
tags: "{{ new_group.results[0].tags | format_asg_tags | symmetric_difference(new_group.results[0].tags | format_asg_tags | selectattr('stage', 'defined') | list) | union([{'stage': 'live', 'propagate_at_launch': False}, {'deploy_timestamp': date_time_numeric, 'propagate_at_launch': False}]) }}"
tags: tag
- name: Tag the pre stage group
ec2_asg:
name: "{{ current_group.results[0].auto_scaling_group_name }}"
health_check_type: "{{ current_group.results[0].health_check_type }}" # required to prevent resetting to the default
tags: "{{ current_group.results[0].tags | format_asg_tags | symmetric_difference(current_group.results[0].tags | format_asg_tags | selectattr('stage', 'defined') | list) | union([{'stage': 'pre', 'propagate_at_launch': False}, {'deploy_timestamp': date_time_numeric, 'propagate_at_launch': False}]) }}"
tags: tag
# vim: set ft=ansible ts=2 sts=2 sw=2 expandtab: