commit | author | age
|
2a18ae
|
1 |
- name: AWS Generate CloudFormation Template |
S |
2 |
template: |
|
3 |
src: "{{ANSIBLE_REPO_PATH}}/configs/{{ env_type }}/files/cloud_providers/{{cloud_provider}}_cloud_template.j2" |
|
4 |
dest: "{{ANSIBLE_REPO_PATH}}/workdir/{{ env_type }}.{{ guid }}.{{cloud_provider}}_cloud_template-orig" |
|
5 |
tags: |
|
6 |
- aws_infrastructure_deployment |
|
7 |
- gen_cf_template |
|
8 |
|
|
9 |
######################### Minimize template (avoid size limitation as much as possible) |
|
10 |
- name: minimize json |
|
11 |
shell: "jq -c . < {{ ANSIBLE_REPO_PATH }}/workdir/{{ env_type }}.{{ guid }}.{{cloud_provider}}_cloud_template-orig > ../workdir/{{ env_type }}.{{ guid }}.{{cloud_provider}}_cloud_template" |
|
12 |
register: jq_minify |
|
13 |
ignore_errors: true |
|
14 |
tags: |
|
15 |
- aws_infrastructure_deployment |
|
16 |
- gen_cf_template |
|
17 |
- minify_template |
|
18 |
|
|
19 |
- name: use original if jq failed |
|
20 |
command: "cp {{ ANSIBLE_REPO_PATH }}/workdir/{{ env_type }}.{{ guid }}.{{cloud_provider}}_cloud_template-orig ../workdir/{{ env_type }}.{{ guid }}.{{cloud_provider}}_cloud_template" |
|
21 |
when: jq_minify is failed |
|
22 |
tags: |
|
23 |
- aws_infrastructure_deployment |
|
24 |
- gen_cf_template |
|
25 |
- minify_template |
|
26 |
|
3e2a8d
|
27 |
|
GC |
28 |
|
|
29 |
######################### Copy CF Template to S3 if too big |
|
30 |
- name: Stat CloudFormation template |
|
31 |
stat: |
|
32 |
path: "{{ANSIBLE_REPO_PATH}}/workdir/{{ env_type }}.{{ guid }}.{{cloud_provider}}_cloud_template" |
|
33 |
register: stat_template |
|
34 |
tags: |
|
35 |
- aws_infrastructure_deployment |
|
36 |
- gen_cf_template |
|
37 |
|
|
38 |
- when: |
|
39 |
stat_template.stat.size > 51200 |
|
40 |
tags: |
|
41 |
- aws_infrastructure_deployment |
|
42 |
- gen_cf_template |
|
43 |
environment: |
|
44 |
AWS_ACCESS_KEY_ID: "{{aws_access_key_id}}" |
|
45 |
AWS_SECRET_ACCESS_KEY: "{{aws_secret_access_key}}" |
|
46 |
AWS_DEFAULT_REGION: "{{aws_region_final|d(aws_region)}}" |
|
47 |
block: |
33cac3
|
48 |
- name: Get user name |
GC |
49 |
command: aws iam get-user |
|
50 |
register: rget_user |
|
51 |
ignore_errors: yes |
|
52 |
|
|
53 |
# Bucket name must be globally unique. Use the userID to define the bucketname. |
|
54 |
# Otherwise when we use the code in another account it fails because the bucket |
|
55 |
# already exists. |
|
56 |
- set_fact: |
|
57 |
aws_account_user: "{{rget_user.stdout|from_json|json_query('User.UserId')}}" |
|
58 |
ignore_errors: yes |
|
59 |
|
3e2a8d
|
60 |
- name: Create bucket |
GC |
61 |
s3_bucket: |
33cac3
|
62 |
name: "cloudformation-templates-{{aws_account_user|default('user')}}" |
3e2a8d
|
63 |
- name: Copy Template to S3 |
GC |
64 |
aws_s3: |
|
65 |
bucket: redhat-gpe-cloudformation-templates |
|
66 |
object: "{{ env_type }}.{{ guid }}.{{cloud_provider}}_cloud_template" |
|
67 |
src: "{{ANSIBLE_REPO_PATH}}/workdir/{{ env_type }}.{{ guid }}.{{cloud_provider}}_cloud_template" |
|
68 |
mode: put |
|
69 |
|
2a18ae
|
70 |
######################### Validate CF Template |
S |
71 |
|
3e2a8d
|
72 |
- name: validate cloudformation template (local) |
2a18ae
|
73 |
environment: |
S |
74 |
AWS_ACCESS_KEY_ID: "{{aws_access_key_id}}" |
|
75 |
AWS_SECRET_ACCESS_KEY: "{{aws_secret_access_key}}" |
5c7a03
|
76 |
AWS_DEFAULT_REGION: "{{aws_region_final|d(aws_region)}}" |
GC |
77 |
command: >- |
|
78 |
aws cloudformation validate-template |
|
79 |
--region {{ aws_region_final | d(aws_region) | default(region) | default('us-east-1')}} |
|
80 |
--template-body file://../workdir/{{ env_type }}.{{ guid }}.{{cloud_provider}}_cloud_template |
2a18ae
|
81 |
changed_when: false |
692763
|
82 |
register: cloudformation_validation |
GC |
83 |
until: cloudformation_validation is succeeded |
|
84 |
delay: 20 |
2a18ae
|
85 |
tags: |
S |
86 |
- aws_infrastructure_deployment |
|
87 |
- validate_cf_template |
3e2a8d
|
88 |
when: stat_template.stat.size <= 51200 |
GC |
89 |
|
|
90 |
- name: validate cloudformation template (S3) |
|
91 |
environment: |
|
92 |
AWS_ACCESS_KEY_ID: "{{aws_access_key_id}}" |
|
93 |
AWS_SECRET_ACCESS_KEY: "{{aws_secret_access_key}}" |
|
94 |
AWS_DEFAULT_REGION: "{{aws_region_final|d(aws_region)}}" |
|
95 |
command: >- |
|
96 |
aws cloudformation validate-template |
|
97 |
--region {{ aws_region_final | d(aws_region) | default(region) | default('us-east-1')}} |
|
98 |
--template-url https://s3.amazonaws.com/redhat-gpe-cloudformation-templates/{{env_type}}.{{guid}}.{{cloud_provider}}_cloud_template |
|
99 |
changed_when: false |
|
100 |
register: cloudformation_validation |
|
101 |
until: cloudformation_validation is succeeded |
|
102 |
delay: 20 |
|
103 |
tags: |
|
104 |
- aws_infrastructure_deployment |
|
105 |
- validate_cf_template |
|
106 |
when: stat_template.stat.size > 51200 |
2a18ae
|
107 |
|
S |
108 |
######################### Launch CF Template |