-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.yml
More file actions
62 lines (52 loc) · 1.81 KB
/
stack.yml
File metadata and controls
62 lines (52 loc) · 1.81 KB
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
- set_fact:
execute_changeset: "{{ execute | default(false) }}"
template_paramters: "{{ paramters | default({}) }}"
termination_protection: "{{ protect | default('no') }}"
region: "{{ region | default(lookup('env', 'AWS_DEFAULT_REGION')) }}"
- name: check stack exists or not
cloudformation_info:
region: "{{ region }}"
stack_name: "{{ stack_name }}"
register: result
- set_fact:
cfn_stack_exists: "{{ result.cloudformation.keys() | length > 0 }}"
- debug: var=cfn_stack_exists
- name: create stack
cloudformation:
stack_name: "{{ stack_name }}"
state: present
region: "{{ region }}"
disable_rollback: false
termination_protection: "{{ termination_protection | default('no') }}"
template: "{{ cfn_template }}"
template_parameters: "{{ template_paramters }}"
capabilities:
- CAPABILITY_IAM
- CAPABILITY_NAMED_IAM
- CAPABILITY_AUTO_EXPAND
when: not cfn_stack_exists | bool
- name: create changeset
cloudformation:
stack_name: "{{ stack_name }}"
state: present
region: "{{ region }}"
disable_rollback: false
create_changeset: yes
template: "{{ cfn_template }}"
template_parameters: "{{ template_paramters }}"
register: result
when: cfn_stack_exists | bool
- set_fact:
change_set: "{{ result.warnings[0] | regex_search('(Ansible[^ ]*)') }}"
when: cfn_stack_exists | bool
- debug: var=change_set
when: cfn_stack_exists | bool
- name: apply changeset
command: >
aws cloudformation execute-change-set --region {{ region }}
--stack-name "{{ stack_name }}"
--change-set-name "{{ change_set }}"
register: result
when: (cfn_stack_exists | bool) and (change_set != "") and (execute_changeset | bool)
- debug: var=result
when: (cfn_stack_exists | bool) and (change_set != "") and (execute_changeset | bool)