|
10 | 10 | aws_secret_key: "{{ aws_secret_key | default(omit) }}"
|
11 | 11 | security_token: "{{ security_token | default(omit) }}"
|
12 | 12 | region: "{{ region }}"
|
13 |
| - |
14 | 13 | block:
|
15 | 14 | - name: Get image ID to create an instance
|
16 | 15 | amazon.aws.ec2_ami_info:
|
|
23 | 22 |
|
24 | 23 | - name: List availability zones from aws region
|
25 | 24 | amazon.aws.aws_az_info:
|
26 |
| - filters: |
27 |
| - region-name: "{{ region }}" |
28 | 25 | register: zones
|
29 | 26 |
|
30 | 27 | - name: Set region_av_zones' variable
|
|
127 | 124 | to_port: 22
|
128 | 125 | - cidr_ip: 0.0.0.0/0
|
129 | 126 | proto: tcp
|
130 |
| - from_port: "{{ app_listening_port }}" |
131 |
| - to_port: "{{ app_listening_port }}" |
| 127 | + from_port: "{{ deploy_flask_app_listening_port }}" |
| 128 | + to_port: "{{ deploy_flask_app_listening_port }}" |
132 | 129 | rules_egress:
|
133 | 130 | - cidr_ip: 0.0.0.0/0
|
134 | 131 | proto: -1
|
|
153 | 150 | - name: Get RDS instance info
|
154 | 151 | amazon.aws.rds_instance_info:
|
155 | 152 | db_instance_identifier: "{{ rds_identifier }}"
|
156 |
| - register: rds_info |
| 153 | + register: rds_result |
157 | 154 |
|
158 | 155 | - name: Create RDS instance
|
159 |
| - when: rds_info.instances | length == 0 |
| 156 | + when: rds_result.instances | length == 0 |
160 | 157 | block:
|
161 | 158 | - name: Create RDS instance (PostGreSQL Database)
|
162 | 159 | amazon.aws.rds_instance:
|
|
169 | 166 | db_name: "{{ rds_instance_name }}"
|
170 | 167 | engine: "{{ rds_engine }}"
|
171 | 168 | engine_version: "{{ rds_engine_version }}"
|
172 |
| - master_user_password: "{{ rds_master_password }}" |
173 |
| - master_username: "{{ rds_master_user }}" |
| 169 | + master_user_password: "{{ deploy_flask_app_rds_master_password }}" |
| 170 | + master_username: "{{ deploy_flask_app_rds_master_username }}" |
174 | 171 | monitoring_interval: 0
|
175 | 172 | storage_type: standard
|
176 | 173 | skip_final_snapshot: true
|
|
189 | 186 | db_instance_identifier: "{{ rds_identifier }}"
|
190 | 187 | engine: "{{ rds_engine }}"
|
191 | 188 | engine_version: "{{ rds_engine_version }}"
|
192 |
| - master_user_password: "{{ rds_master_password }}" |
193 |
| - master_username: "{{ rds_master_user }}" |
| 189 | + master_user_password: "{{ deploy_flask_app_rds_master_password }}" |
| 190 | + master_username: "{{ deploy_flask_app_rds_master_username }}" |
194 | 191 | monitoring_interval: 0
|
195 | 192 | storage_type: standard
|
196 | 193 | skip_final_snapshot: true
|
|
204 | 201 | - name: Get RDS instance info
|
205 | 202 | amazon.aws.rds_instance_info:
|
206 | 203 | db_instance_identifier: "{{ rds_identifier }}"
|
207 |
| - register: rds_info |
| 204 | + register: rds_result |
208 | 205 |
|
209 | 206 | - name: Set 'sshkey_file' variable
|
210 | 207 | ansible.builtin.set_fact:
|
211 |
| - sshkey_file: ~/private-key-{{ sshkey_pair_name }}-{{ region | default(aws_region) }} |
| 208 | + sshkey_file: ~/private-key-{{ deploy_flask_app_sshkey_pair_name }}-{{ region | default(aws_region) }} |
212 | 209 |
|
213 | 210 | - name: Create key pair to connect to the VM
|
214 | 211 | amazon.aws.ec2_key:
|
215 |
| - name: "{{ sshkey_pair_name }}" |
| 212 | + name: "{{ deploy_flask_app_sshkey_pair_name }}" |
216 | 213 | register: rsa_key
|
217 | 214 |
|
218 | 215 | - name: Save private key into file
|
|
224 | 221 |
|
225 | 222 | - name: Create a virtual machine
|
226 | 223 | amazon.aws.ec2_instance:
|
227 |
| - name: "{{ bastion_host_name }}" |
| 224 | + name: "{{ deploy_flask_app_bastion_host_name }}" |
228 | 225 | instance_type: "{{ bastion_host_type }}"
|
229 | 226 | image_id: "{{ images.images.0.image_id }}"
|
230 |
| - key_name: "{{ sshkey_pair_name }}" |
| 227 | + key_name: "{{ deploy_flask_app_sshkey_pair_name }}" |
231 | 228 | subnet_id: "{{ subnet.subnet.id }}"
|
232 | 229 | network:
|
233 | 230 | assign_public_ip: true
|
|
237 | 234 | - "{{ secgroup.group_id }}"
|
238 | 235 | wait: true
|
239 | 236 | state: started
|
240 |
| - register: result |
241 |
| - |
242 |
| - - name: Add host to inventory |
243 |
| - ansible.builtin.add_host: |
244 |
| - hostname: bastion |
245 |
| - ansible_ssh_user: "{{ bastion_host_username }}" |
246 |
| - ansible_host: "{{ result.instances.0.public_ip_address }}" |
247 |
| - ansible_ssh_common_args: -o "UserKnownHostsFile=/dev/null" -o StrictHostKeyChecking=no -i {{ sshkey_file }} |
248 |
| - ansible_host_name: "{{ result.instances.0.public_dns_name | split('.') | first }}" |
249 |
| - host_config: |
250 |
| - public_subnet_id: "{{ subnet.subnet.id }}" |
251 |
| - private_subnet_id: "{{ private_subnet.subnet.id }}" |
252 |
| - image_id: "{{ images.images.0.image_id }}" |
253 |
| - group_id: "{{ secgroup.group_id }}" |
254 |
| - private_ip: "{{ result.instances.0.private_ip_address }}" |
255 |
| - vpc_id: "{{ vpc.vpc.id }}" |
256 |
| - rds_info: |
257 |
| - host: "{{ rds_info.instances.0.endpoint.address }}" |
258 |
| - name: "{{ rds_instance_name }}" |
259 |
| - master_user_password: "{{ rds_master_password }}" |
260 |
| - master_username: "{{ rds_master_user }}" |
| 237 | + register: vm_result |
0 commit comments