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 21 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/103).
abikouo marked this conversation as resolved.
Show resolved Hide resolved
- >-
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.

1 change: 1 addition & 0 deletions playbooks/webapp/migrate_webapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
ansible.builtin.import_role:
name: cloud.aws_ops.deploy_flask_app
vars:
deploy_flask_app_bastion_ssh_private_key: "{{ sshkey_file }}"
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 }}"
Expand Down
14 changes: 14 additions & 0 deletions playbooks/webapp/tasks/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@
instance-state-name: running
register: vm_result

- 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:
Expand All @@ -235,12 +244,17 @@
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
wait: true
state: started
register: vm_result
14 changes: 1 addition & 13 deletions playbooks/webapp/vars/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ operation: create

image_filter: Fedora-Cloud-Base-35-*gp2-0
public_secgroup_name: "{{ resource_prefix }}-sg"
ec2_iam_role_name: "{{ resource_prefix }}-role"
rds_subnet_group_name: "{{ resource_prefix }}-rds-sg"
rds_secgroup_name: "{{ resource_prefix }}-rds-sec"
rds_identifier: "{{ resource_prefix }}-rds-01"
Expand All @@ -30,29 +31,16 @@ rds_listening_port: 5432
deploy_flask_app_sshkey_pair_name: "{{ resource_prefix }}-key"
deploy_flask_app_bastion_host_name: "{{ resource_prefix }}-bastion"
deploy_flask_app_bastion_host_username: fedora
deploy_flask_app_bastion_host_required_packages:
- python3
- python-virtualenv
- sshpass
- git
- gcc
- podman
- httpd-tools
- ansible-core
deploy_flask_app_workers_instance_type: t2.xlarge
deploy_flask_app_workers_user_name: fedora
deploy_flask_app_number_of_workers: 2
deploy_flask_app_listening_port: 5000
deploy_flask_app_git_repository: https://github.com/abikouo/webapp_pyflask_demo.git
deploy_flask_app_config:
env: development
admin_user: admin
admin_password: admin
app_dir: /app/pyapp
deploy_flask_app_force_init: false
deploy_flask_app_local_registry_user: ansible
deploy_flask_app_local_registry_pwd: testing123
deploy_flask_app_local_registry_port: "{{ deploy_flask_app_listening_port }}"
deploy_flask_app_rds_master_password: L#5cH2mgy_
deploy_flask_app_rds_master_username: ansible

Expand Down
1 change: 1 addition & 0 deletions playbooks/webapp/webapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
ansible.builtin.include_role:
name: cloud.aws_ops.deploy_flask_app
vars:
deploy_flask_app_bastion_ssh_private_key: "{{ sshkey_file }}"
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 }}"
Expand Down
2 changes: 2 additions & 0 deletions playbooks/webapp/webapp_ha_aurora.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
ansible.builtin.include_role:
name: cloud.aws_ops.deploy_flask_app
vars:
deploy_flask_app_bastion_ssh_private_key: "{{ sshkey_file }}"
deploy_flask_app_private_subnet_id: "{{ primary_private_subnet.subnets[0].id }}"
deploy_flask_app_vpc_id: "{{ primary_vpc.vpcs[0].id }}"
deploy_flask_app_vm_info: "{{ primary_vm_result }}"
abikouo marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -96,6 +97,7 @@
ansible.builtin.include_role:
name: cloud.aws_ops.deploy_flask_app
vars:
deploy_flask_app_bastion_ssh_private_key: "{{ sshkey_file }}"
deploy_flask_app_private_subnet_id: "{{ replica_private_subnet.subnets[0].id }}"
deploy_flask_app_vpc_id: "{{ replica_vpc.vpcs[0].id }}"
deploy_flask_app_vm_info: "{{ replica_vm_result }}"
abikouo marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
10 changes: 3 additions & 7 deletions roles/deploy_flask_app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,27 @@ Role Variables
## variables to create new hosts and groups in inventory of in memory playbook.

* **deploy_flask_app_region** (str): Region where the app is to be deployed.
* **deploy_flask_app_bastion_host_username** (str): Username for the bastion host SSH user.
* **deploy_flask_app_private_subnet_id** (str): Private subnet id of the bastion host
* **deploy_flask_app_vpc_id** (str): vpc id for the host.
* **deploy_flask_app_rds_info** (dict): A dict of information for the backend RDS. This dict has the output of amazon.aws.rds_instance_info mode.
* **deploy_flask_app_rds_master_username** (str): Username for the RDS instance.
* **deploy_flask_app_rds_master_password** (str): password for the RDS instance.
* **deploy_flask_app_vm_info** (dict): A dict of information for the vm to use. This dict has the output of amazon.aws.ec2_instance_info module.
* **deploy_flask_app_sshkey_pair_name** (str): Name for the EC2 key pair.

## variables needed for the deployment

# Bastion host
* **deploy_flask_app_bastion_host_name** (str): Name for the EC2 instance.
* **deploy_flask_app_bastion_host_required_packages** (list): Packages to be installed on the bastion host.
* **deploy_flask_app_bastion_host_username** (str): Username for the bastion host SSH user.
* **deploy_flask_app_sshkey_pair_name** (str): Name for the EC2 key pair.
* **deploy_flask_app_bastion_ssh_private_key** (path): The path to the ssh private key file to use to connect to the bastion host.
* **deploy_flask_app_number_of_workers** (int): Number of instances to create.
* **deploy_flask_app_workers_instance_type** (str): RC2 instance type for workers.
* **deploy_flask_app_workers_user_name** (str): Username for the workers.

# App
* **deploy_flask_app_git_repository** (str): Git repository to be cloned for the webapp.
* **deploy_flask_app_listening_port** (int): Load balancer port.
* **deploy_flask_app_force_init** (bool): A boolean value True to force init the app and False to not force init.
* **deploy_flask_app_local_registry_port** (int): Port for the local Podman registry.
* **deploy_flask_app_local_registry_user** (str): Registry user name.
* **deploy_flask_app_local_registry_pwd** (str): Registry password.
* **deploy_flask_app_config** (dict): A dict of config parameterys for the app.
**env** (str): Flask env.
**admin_user** (str): App config's admin username.
Expand Down
3 changes: 3 additions & 0 deletions roles/deploy_flask_app/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
deploy_flask_app_workers_ssh_private_key: /tmp/id_rsa
deploy_flask_app_container_image: docker.io/aubinredhat/webapp:1.0.0
68 changes: 0 additions & 68 deletions roles/deploy_flask_app/files/run_app.yaml

This file was deleted.

24 changes: 4 additions & 20 deletions roles/deploy_flask_app/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ argument_specs:
description: Name for the EC2 instance.
type: str
required: True
deploy_flask_app_bastion_host_required_packages:
description: Packages to be installed on the bastion host.
type: list
elements: str
deploy_flask_app_bastion_ssh_private_key:
description: The path to ssh private key file to use to connect to the bastion host.
type: path
required: True
version_added: 2.1.0
deploy_flask_app_private_subnet_id:
description: Private subnet id of the bastion host.
type: str
Expand Down Expand Up @@ -60,10 +60,6 @@ argument_specs:
description: Username for the workers.
type: str
required: True
deploy_flask_app_git_repository:
description: Git repository to be cloned for the webapp.
type: str
required: True
deploy_flask_app_listening_port:
description: Load balancer port.
type: int
Expand All @@ -72,18 +68,6 @@ argument_specs:
description: A boolean value True to force init the app and False to not force init.
type: bool
required: True
deploy_flask_app_local_registry_user:
description: Registry user name.
type: str
required: True
deploy_flask_app_local_registry_pwd:
description: Registry password.
type: str
required: True
deploy_flask_app_local_registry_port:
description: Registry port.
type: int
required: True
deploy_flask_app_config:
description: A dict of config parameterys for the app.
type: dict
Expand Down
Loading
Loading