Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

role/deploy_flask_app - change required parameter key pair with path to ssh key file #109

Merged
merged 51 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
725e7ad
Fix integration test issue
abikouo Dec 19, 2023
35bc474
adding issue number
abikouo Dec 19, 2023
d15c275
Retrieve RDS instance info
abikouo Dec 19, 2023
83bdced
minor updates
abikouo Dec 19, 2023
7719bb8
setting file permission
abikouo Dec 20, 2023
30228f8
Fix issue with delete.yaml
abikouo Dec 20, 2023
9d11e47
try to ping the workers
abikouo Dec 20, 2023
4e5b860
try to ping the workers
abikouo Dec 20, 2023
fff9401
commit with aws alias
abikouo Dec 20, 2023
f6d536f
add credentials
abikouo Dec 20, 2023
fed9b8e
add path to ssh private key
abikouo Dec 20, 2023
0b40c4e
skip load balancer for now
abikouo Dec 20, 2023
eb7c6f3
update subnet value when creating load balancer
abikouo Dec 20, 2023
0e09fe5
fix inventory template issue
abikouo Dec 20, 2023
2552c00
fix inventory
abikouo Dec 20, 2023
1228fac
fix inventory
abikouo Dec 20, 2023
3d8f72c
full integration
abikouo Dec 21, 2023
12a48c1
install host packages via user_data when creating instances
abikouo Dec 21, 2023
7a16851
add IAM role to install package into bastion
abikouo Dec 21, 2023
584a227
minor updates
abikouo Dec 22, 2023
8af0f2c
update playbooks
abikouo Dec 22, 2023
94c1457
minor updates
abikouo Jan 8, 2024
91f82fb
Replace ansible.builtin.shell by ansible.builtin.command
abikouo Jan 8, 2024
4ad3c54
fix: playbook webapp - delete resources
abikouo Jan 8, 2024
37805f4
Remove dependency with aws_setup_credentials
abikouo Jan 9, 2024
b45004c
Remove unused playbook
abikouo Jan 9, 2024
0957321
add retries when trying to connect to ec2 instances
abikouo Jan 9, 2024
136d136
minor updates
abikouo Jan 9, 2024
8731e94
Remove all conditional checks
abikouo Jan 9, 2024
68588a1
update wait_timeout while creating load balancer
abikouo Jan 10, 2024
e7056b1
temporary commit
abikouo Jan 10, 2024
6dac13b
using roles
abikouo Jan 17, 2024
b38b83e
add missing paremeters
abikouo Jan 17, 2024
bd0a907
Update RDS result
abikouo Jan 18, 2024
b760acc
Revert update of tests/integration/targets/setup_rsa_keys
abikouo Jan 18, 2024
b32f8fc
Support storage of key pair into S3 bucket - Needed for running on AW…
abikouo Jan 18, 2024
b1e01ad
Fix ansible-lint
abikouo Jan 18, 2024
dd2eec0
Conditionnal delete for sshkey_file
abikouo Jan 19, 2024
985b23c
Remove confusing variable deploy_flask_app_region
abikouo Jan 19, 2024
3f13bc5
fix linters
abikouo Jan 19, 2024
eba57a0
minor update for code review
abikouo Jan 26, 2024
49187b8
Update 20231219-deploy_flask_app-update-arguments-spec.yml
abikouo Jan 31, 2024
0c620fc
minor code review updates
abikouo Jan 31, 2024
d6ea987
add missing deletion steps
abikouo Jan 31, 2024
4c4e498
Wait for the RDS instance to be available
abikouo Jan 31, 2024
a9813d0
RDS result update
abikouo Jan 31, 2024
f89c274
delete additional key pairs
abikouo Feb 1, 2024
dbb3c18
Fixing issue with webapp_ha_aurora playbook
abikouo Feb 6, 2024
ca71f7e
conditional delete for global cluster
abikouo Feb 6, 2024
960b9eb
fix minor issue
abikouo Feb 6, 2024
4de99e5
Update playbooks/webapp/vars/main.yaml
abikouo Feb 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
breaking_changes:
- >-
roles/deploy_flask_app - Add parameter ``deploy_flask_app_bastion_ssh_private_key`` to define
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).
- >-
roles/deploy_flask_app - The following parameters no longer required have been removed
``deploy_flask_app_bastion_host_required_packages``, ``deploy_flask_app_local_registry_port``,
``deploy_flask_app_local_registry_pwd``, ``deploy_flask_app_local_registry_user``,
``deploy_flask_app_git_repository`` (https://github.com/redhat-cop/cloud.aws_ops/issues/103).
14 changes: 0 additions & 14 deletions playbooks/webapp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,6 @@ To delete the webapp:
* **deploy_flask_app_bastion_host_name** (str): Name for the EC2 instance. Default: `"{{ resource_prefix }}-bastion"`
* **bastion_host_type** (str): Instance type for the EC2 instance. Default: `t2.xlarge`
* **deploy_flask_app_bastion_host_username** (str): Username for the bastion host SSH user. Default: `fedora`
* **deploy_flask_app_bastion_host_required_packages** (list, elements str): Packages to be installed on the bastion host. Default:
```yaml
- python3
- python-virtualenv
- sshpass
- git
- podman
- httpd-tools
- ansible
```

### Networking

Expand Down Expand Up @@ -142,12 +132,8 @@ To delete the webapp:

### Webapp

* **deploy_flask_app_git_repository** (str): Git repository for the webapp. Default: `https://github.com/abikouo/webapp_pyflask_demo.git`
* **deploy_flask_app_number_of_workers** (int): Number of worker instances to create. Default: `2`
* **deploy_flask_app_workers_instance_type** (str): EC2 instance type for workers. Default: `t2.xlarge`
* **deploy_flask_app_local_registry_user** (str): Username for local Podman registry. Default: `ansible`
* **deploy_flask_app_local_registry_pwd** (str): Password for local Podman registry. Default: `testing123`
* **deploy_flask_app_local_registry_port** (int): Port for the local Podman registery. Default: `"{{ app_listening_port }}"`
* **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:
```yaml
app_dir: /app/pyapp
Expand Down
13 changes: 13 additions & 0 deletions playbooks/webapp/files/ec2-trust-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
70 changes: 0 additions & 70 deletions playbooks/webapp/files/run_app.yaml

This file was deleted.

25 changes: 16 additions & 9 deletions playbooks/webapp/migrate_webapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,23 @@
rds_snapshot_arn: "{{ result.db_snapshot_arn }}"
region: "{{ dest_region }}"

- name: Deploy app
- name: Create workers and deploy application
when: operation == "create"
ansible.builtin.import_role:
name: cloud.aws_ops.deploy_flask_app
vars:
deploy_flask_app_private_subnet_id: "{{ private_subnet.subnet.id }}"
deploy_flask_app_vpc_id: "{{ vpc.vpc.id }}"
deploy_flask_app_vm_info: "{{ vm_result }}"
deploy_flask_app_rds_info: "{{ rds_result }}"
deploy_flask_app_region: "{{ dest_region }}"
module_defaults:
group/aws:
aws_access_key: "{{ aws_access_key | default(omit) }}"
aws_secret_key: "{{ aws_secret_key | default(omit) }}"
security_token: "{{ security_token | default(omit) }}"
region: "{{ dest_region }}"
block:
- name: Deploy app
ansible.builtin.import_role:
name: cloud.aws_ops.deploy_flask_app
vars:
deploy_flask_app_private_subnet_id: "{{ private_subnet.subnet.id }}"
deploy_flask_app_vpc_id: "{{ vpc.vpc.id }}"
deploy_flask_app_vm_info: "{{ vm_result }}"
deploy_flask_app_rds_info: "{{ rds_result }}"

- name: Delete RDS snapshots from different regions
amazon.aws.rds_instance_snapshot:
Expand Down
2 changes: 2 additions & 0 deletions playbooks/webapp/tasks/add_route53_records.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
failover: "PRIMARY"
health_check: "{{ healthchk_primary_result.health_check.id }}"
alias_hosted_zone_id: "{{ primary_lb.elb.hosted_zone_id }}"
overwrite: true
register: alias_record_primary_result

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

- name: Pause for 30 secs for the alias records to be active
Expand Down
43 changes: 24 additions & 19 deletions playbooks/webapp/tasks/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,45 +202,50 @@
db_instance_identifier: "{{ rds_identifier }}"
register: rds_result

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

- name: Create key pair to connect to the VM
- name: Create key pair to connect to the workers
amazon.aws.ec2_key:
name: "{{ deploy_flask_app_sshkey_pair_name }}"
register: rsa_key
register: keypair_result

- name: Save private key into file
- name: Save private key into a file
ansible.builtin.copy:
content: "{{ rsa_key.key.private_key }}"
dest: "{{ sshkey_file }}"
mode: 0400
when: rsa_key is changed

- name: Check if the vm exists
amazon.aws.ec2_instance_info:
filters:
instance-type: "{{ bastion_host_type }}"
key-name: "{{ deploy_flask_app_sshkey_pair_name }}"
vpc-id: "{{ vpc.vpc.id }}"
instance-state-name: running
register: vm_result
content: "{{ keypair_result.key.private_key }}"
dest: "{{ deploy_flask_app_bastion_ssh_private_key_path }}"
mode: 0600
when: keypair_result is changed

- name: Ensure IAM instance role exists
amazon.aws.iam_role:
name: "{{ ec2_iam_role_name }}"
assume_role_policy_document: "{{ lookup('file', 'ec2-trust-policy.json') }}"
state: present
create_instance_profile: true
wait: true
register: role_output

- name: Create a virtual machine
when: vm_result.instances | length == 0
amazon.aws.ec2_instance:
name: "{{ deploy_flask_app_bastion_host_name }}"
instance_type: "{{ bastion_host_type }}"
image_id: "{{ images.images.0.image_id }}"
key_name: "{{ deploy_flask_app_sshkey_pair_name }}"
subnet_id: "{{ subnet.subnet.id }}"
ebs_optimized: true
instance_role: "{{ role_output.iam_role.role_name }}"
network:
assign_public_ip: true
groups:
- "{{ secgroup.group_id }}"
security_groups:
- "{{ secgroup.group_id }}"
user_data: |
#!/bin/bash
yum install -y python3 python-virtualenv sshpass netcat ansible
wait: true
state: started
register: vm_result
12 changes: 0 additions & 12 deletions playbooks/webapp/tasks/create_aurora_db_cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@
create_rds_global_cluster_replica_cluster_vpc_security_group_ids:
- "{{ rds_replica_sg.security_groups[0].group_id }}"

- name: Get primary instance info
amazon.aws.rds_instance_info:
db_instance_identifier: "{{ rds_primary_cluster_instance_name }}"
region: "{{ rds_primary_cluster_region }}"
register: primary_instance_info_result

- name: Get primary cluster info
amazon.aws.rds_cluster_info:
db_cluster_identifier: "{{ rds_primary_cluster_name }}"
Expand All @@ -62,12 +56,6 @@
region: "{{ rds_replica_cluster_region }}"
register: replica_cluster_info_result

- name: Get replica instance info
amazon.aws.rds_instance_info:
db_instance_identifier: "{{ rds_replica_cluster_instance_name }}"
region: "{{ rds_replica_cluster_region }}"
register: replica_instance_info_result

- name: Get global db info
amazon.aws.rds_global_cluster_info:
global_cluster_identifier: "{{ rds_global_cluster_name }}"
Expand Down
Loading
Loading