Skip to content

Commit 7a63084

Browse files
authored
Merge pull request #109 from abikouo/fix_int_target_test_deploy_flask_app
role/deploy_flask_app - change required parameter key pair with path to ssh key file
2 parents fcab549 + 4de99e5 commit 7a63084

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+781
-979
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
breaking_changes:
3+
- >-
4+
roles/deploy_flask_app - Add parameter ``deploy_flask_app_bastion_ssh_private_key`` to define
5+
the path to the ssh private key file to use to connect to the bastion host (https://github.com/redhat-cop/cloud.aws_ops/issues/109).
6+
- >-
7+
roles/deploy_flask_app - The following parameters no longer required have been removed
8+
``deploy_flask_app_bastion_host_required_packages``, ``deploy_flask_app_local_registry_port``,
9+
``deploy_flask_app_local_registry_pwd``, ``deploy_flask_app_local_registry_user``,
10+
``deploy_flask_app_git_repository`` (https://github.com/redhat-cop/cloud.aws_ops/issues/103).

playbooks/webapp/README.md

-14
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,6 @@ To delete the webapp:
101101
* **deploy_flask_app_bastion_host_name** (str): Name for the EC2 instance. Default: `"{{ resource_prefix }}-bastion"`
102102
* **bastion_host_type** (str): Instance type for the EC2 instance. Default: `t2.xlarge`
103103
* **deploy_flask_app_bastion_host_username** (str): Username for the bastion host SSH user. Default: `fedora`
104-
* **deploy_flask_app_bastion_host_required_packages** (list, elements str): Packages to be installed on the bastion host. Default:
105-
```yaml
106-
- python3
107-
- python-virtualenv
108-
- sshpass
109-
- git
110-
- podman
111-
- httpd-tools
112-
- ansible
113-
```
114104

115105
### Networking
116106

@@ -142,12 +132,8 @@ To delete the webapp:
142132

143133
### Webapp
144134

145-
* **deploy_flask_app_git_repository** (str): Git repository for the webapp. Default: `https://github.com/abikouo/webapp_pyflask_demo.git`
146135
* **deploy_flask_app_number_of_workers** (int): Number of worker instances to create. Default: `2`
147136
* **deploy_flask_app_workers_instance_type** (str): EC2 instance type for workers. Default: `t2.xlarge`
148-
* **deploy_flask_app_local_registry_user** (str): Username for local Podman registry. Default: `ansible`
149-
* **deploy_flask_app_local_registry_pwd** (str): Password for local Podman registry. Default: `testing123`
150-
* **deploy_flask_app_local_registry_port** (int): Port for the local Podman registery. Default: `"{{ app_listening_port }}"`
151137
* **deploy_flask_app_config** (dict, elements dict): Configuration values for the webapp, passed as corresponding env variables FLASK_APP, FLASK_ENV, ADMIN_USER, and ADMIN_PASSWORD when the app is deployed. Default:
152138
```yaml
153139
app_dir: /app/pyapp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"Version": "2008-10-17",
3+
"Statement": [
4+
{
5+
"Sid": "",
6+
"Effect": "Allow",
7+
"Principal": {
8+
"Service": "ec2.amazonaws.com"
9+
},
10+
"Action": "sts:AssumeRole"
11+
}
12+
]
13+
}

playbooks/webapp/files/run_app.yaml

-70
This file was deleted.

playbooks/webapp/migrate_webapp.yaml

+16-9
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,23 @@
5353
rds_snapshot_arn: "{{ result.db_snapshot_arn }}"
5454
region: "{{ dest_region }}"
5555

56-
- name: Deploy app
56+
- name: Create workers and deploy application
5757
when: operation == "create"
58-
ansible.builtin.import_role:
59-
name: cloud.aws_ops.deploy_flask_app
60-
vars:
61-
deploy_flask_app_private_subnet_id: "{{ private_subnet.subnet.id }}"
62-
deploy_flask_app_vpc_id: "{{ vpc.vpc.id }}"
63-
deploy_flask_app_vm_info: "{{ vm_result }}"
64-
deploy_flask_app_rds_info: "{{ rds_result }}"
65-
deploy_flask_app_region: "{{ dest_region }}"
58+
module_defaults:
59+
group/aws:
60+
aws_access_key: "{{ aws_access_key | default(omit) }}"
61+
aws_secret_key: "{{ aws_secret_key | default(omit) }}"
62+
security_token: "{{ security_token | default(omit) }}"
63+
region: "{{ dest_region }}"
64+
block:
65+
- name: Deploy app
66+
ansible.builtin.import_role:
67+
name: cloud.aws_ops.deploy_flask_app
68+
vars:
69+
deploy_flask_app_private_subnet_id: "{{ private_subnet.subnet.id }}"
70+
deploy_flask_app_vpc_id: "{{ vpc.vpc.id }}"
71+
deploy_flask_app_vm_info: "{{ vm_result }}"
72+
deploy_flask_app_rds_info: "{{ rds_result }}"
6673

6774
- name: Delete RDS snapshots from different regions
6875
amazon.aws.rds_instance_snapshot:

playbooks/webapp/tasks/add_route53_records.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
failover: "PRIMARY"
4444
health_check: "{{ healthchk_primary_result.health_check.id }}"
4545
alias_hosted_zone_id: "{{ primary_lb.elb.hosted_zone_id }}"
46+
overwrite: true
4647
register: alias_record_primary_result
4748

4849
- name: Add an alias record that points to an aws ELB in the replica region
@@ -57,6 +58,7 @@
5758
failover: "SECONDARY"
5859
health_check: "{{ healthchk_replica_result.health_check.id }}"
5960
alias_hosted_zone_id: "{{ replica_lb.elb.hosted_zone_id }}"
61+
overwrite: true
6062
register: alias_record_replica_result
6163

6264
- name: Pause for 30 secs for the alias records to be active

playbooks/webapp/tasks/create.yaml

+24-19
Original file line numberDiff line numberDiff line change
@@ -202,45 +202,50 @@
202202
db_instance_identifier: "{{ rds_identifier }}"
203203
register: rds_result
204204

205-
- name: Set 'sshkey_file' variable
205+
- name: Set variable for SSH private key file path
206206
ansible.builtin.set_fact:
207-
sshkey_file: ~/private-key-{{ deploy_flask_app_sshkey_pair_name }}-{{ region | default(aws_region) }}
207+
deploy_flask_app_bastion_ssh_private_key_path: "~/.{{ resource_prefix }}_id_rsa"
208+
when: deploy_flask_app_bastion_ssh_private_key_path is undefined
208209

209-
- name: Create key pair to connect to the VM
210+
- name: Create key pair to connect to the workers
210211
amazon.aws.ec2_key:
211212
name: "{{ deploy_flask_app_sshkey_pair_name }}"
212-
register: rsa_key
213+
register: keypair_result
213214

214-
- name: Save private key into file
215+
- name: Save private key into a file
215216
ansible.builtin.copy:
216-
content: "{{ rsa_key.key.private_key }}"
217-
dest: "{{ sshkey_file }}"
218-
mode: 0400
219-
when: rsa_key is changed
220-
221-
- name: Check if the vm exists
222-
amazon.aws.ec2_instance_info:
223-
filters:
224-
instance-type: "{{ bastion_host_type }}"
225-
key-name: "{{ deploy_flask_app_sshkey_pair_name }}"
226-
vpc-id: "{{ vpc.vpc.id }}"
227-
instance-state-name: running
228-
register: vm_result
217+
content: "{{ keypair_result.key.private_key }}"
218+
dest: "{{ deploy_flask_app_bastion_ssh_private_key_path }}"
219+
mode: 0600
220+
when: keypair_result is changed
221+
222+
- name: Ensure IAM instance role exists
223+
amazon.aws.iam_role:
224+
name: "{{ ec2_iam_role_name }}"
225+
assume_role_policy_document: "{{ lookup('file', 'ec2-trust-policy.json') }}"
226+
state: present
227+
create_instance_profile: true
228+
wait: true
229+
register: role_output
229230

230231
- name: Create a virtual machine
231-
when: vm_result.instances | length == 0
232232
amazon.aws.ec2_instance:
233233
name: "{{ deploy_flask_app_bastion_host_name }}"
234234
instance_type: "{{ bastion_host_type }}"
235235
image_id: "{{ images.images.0.image_id }}"
236236
key_name: "{{ deploy_flask_app_sshkey_pair_name }}"
237237
subnet_id: "{{ subnet.subnet.id }}"
238+
ebs_optimized: true
239+
instance_role: "{{ role_output.iam_role.role_name }}"
238240
network:
239241
assign_public_ip: true
240242
groups:
241243
- "{{ secgroup.group_id }}"
242244
security_groups:
243245
- "{{ secgroup.group_id }}"
246+
user_data: |
247+
#!/bin/bash
248+
yum install -y python3 python-virtualenv sshpass netcat ansible
244249
wait: true
245250
state: started
246251
register: vm_result

playbooks/webapp/tasks/create_aurora_db_cluster.yaml

-12
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@
4444
create_rds_global_cluster_replica_cluster_vpc_security_group_ids:
4545
- "{{ rds_replica_sg.security_groups[0].group_id }}"
4646

47-
- name: Get primary instance info
48-
amazon.aws.rds_instance_info:
49-
db_instance_identifier: "{{ rds_primary_cluster_instance_name }}"
50-
region: "{{ rds_primary_cluster_region }}"
51-
register: primary_instance_info_result
52-
5347
- name: Get primary cluster info
5448
amazon.aws.rds_cluster_info:
5549
db_cluster_identifier: "{{ rds_primary_cluster_name }}"
@@ -62,12 +56,6 @@
6256
region: "{{ rds_replica_cluster_region }}"
6357
register: replica_cluster_info_result
6458

65-
- name: Get replica instance info
66-
amazon.aws.rds_instance_info:
67-
db_instance_identifier: "{{ rds_replica_cluster_instance_name }}"
68-
region: "{{ rds_replica_cluster_region }}"
69-
register: replica_instance_info_result
70-
7159
- name: Get global db info
7260
amazon.aws.rds_global_cluster_info:
7361
global_cluster_identifier: "{{ rds_global_cluster_name }}"

0 commit comments

Comments
 (0)