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

Add role deploy_flask_app #85

Merged
merged 21 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Name | Description
[cloud.aws_ops.manage_vpc_peering](https://github.com/ansible-collections/cloud.aws_ops/blob/main/roles/manage_vpc_peering/README.md)|A role to create, delete and accept existing VPC peering connections.
[cloud.aws_ops.moving_objects_between_buckets](https://github.com/ansible-collections/cloud.aws_ops/blob/main/roles/moving_objects_between_buckets/README.md)|A role to move objects from one bucket to another bucket.
[cloud.aws_ops.awsconfig_apigateway_with_lambda_integration](https://github.com/ansible-collections/cloud.aws_ops/blob/main/roles/awsconfig_apigateway_with_lambda_integration/README.md)|A role to create/delete an API gateway with lambda function integration.
[cloud.aws_ops.manage_transit_gateway](https://github.com/ansible-collections/cloud.aws_ops/blob/main/roles/manage_transit_gateway/README.md)|A role to create/delete transit_gateway with vpc and vpn attachments.
[cloud.aws_ops.deploy_flask_app](https://github.com/ansible-collections/cloud.aws_ops/blob/main/roles/deploy_flask_app/README.md)|A role to deploy a flask web application on AWS.

### Playbooks
Name | Description
Expand Down
5 changes: 5 additions & 0 deletions changelogs/fragments/add_deploy_flask_app_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
breaking_changes:
- "Rename webapp playbook variable rds_master_user to rds_master_username (https://github.com/redhat-cop/cloud.aws_ops/pull/85)."
minor_changes:
- "Convert deploy_flask_app playbook to role (https://github.com/redhat-cop/cloud.aws_ops/pull/85)."
6 changes: 3 additions & 3 deletions playbooks/webapp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ To delete the webapp:
* **image_filter** (str): Name of AWS AMI to use. Default: `Fedora-Cloud-Base-35-*`
* **sshkey_pair_name** (str): Name for the EC2 key pair. Default: `"{{ resource_prefix }}-key"`
* **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`
* **bastion_host_type** (str): Instance type for the EC2 instance. Default: `t3.micro`
* **bastion_host_username** (str): Username for the bastion host SSH user. Default: `fedora`
* **bastion_host_required_packages** (list, elements str): Packages to be installed on the bastion host. Default:
```yaml
Expand Down Expand Up @@ -137,14 +137,14 @@ To delete the webapp:
* **rds_instance_name** (str): Name for the database. Default: `mysampledb123`
* **rds_engine** (str): Engine to use for the database. Default: `postgres`
* **rds_engine_version** (str): Version number of the database engine to use. Default: `"14.8"`
* **rds_master_user** (str): Name of the master user for the database instance. Default: `ansible`
* **rds_master_username** (str): Name of the master user for the database instance. Default: `ansible`
* **rds_master_password** (str): Password for the master database user. Default: `L#5cH2mgy_`

### Webapp

* **app_git_repository** (str): Git repository for the webapp. Default: `https://github.com/abikouo/webapp_pyflask_demo.git`
* **number_of_workers** (int): Number of worker instances to create. Default: `2`
* **workers_instance_type** (str): EC2 instance type for workers. Default: `t2.large`
* **workers_instance_type** (str): EC2 instance type for workers. Default: `t3.micro`
* **local_registry_user** (str): Username for local Podman registry. Default: `ansible`
* **local_registry_pwd** (str): Password for local Podman registry. Default: `testing123`
* **local_registry_port** (int): Port for the local Podman registery. Default: `"{{ app_listening_port }}"`
Expand Down
3 changes: 2 additions & 1 deletion playbooks/webapp/migrate_webapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@

tasks:
- name: Deploy app
ansible.builtin.import_tasks: tasks/deploy_app.yaml
ansible.builtin.import_role:
name: cloud.aws_ops.deploy_flask_app
vars:
region: "{{ dest_region }}"
38 changes: 6 additions & 32 deletions playbooks/webapp/tasks/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
region: "{{ region | default(aws_region) }}"

- name: Create resources playbook
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: "{{ region }}"

block:
- name: Get image ID to create an instance
Expand Down Expand Up @@ -153,10 +147,10 @@
- name: Get RDS instance info
amazon.aws.rds_instance_info:
db_instance_identifier: "{{ rds_identifier }}"
register: rds_info
register: rds_result

- name: Create RDS instance
when: rds_info.instances | length == 0
when: rds_result.instances | length == 0
block:
- name: Create RDS instance (PostGreSQL Database)
amazon.aws.rds_instance:
Expand All @@ -170,7 +164,7 @@
engine: "{{ rds_engine }}"
engine_version: "{{ rds_engine_version }}"
master_user_password: "{{ rds_master_password }}"
master_username: "{{ rds_master_user }}"
master_username: "{{ rds_master_username }}"
monitoring_interval: 0
storage_type: standard
skip_final_snapshot: true
Expand All @@ -190,7 +184,7 @@
engine: "{{ rds_engine }}"
engine_version: "{{ rds_engine_version }}"
master_user_password: "{{ rds_master_password }}"
master_username: "{{ rds_master_user }}"
master_username: "{{ rds_master_username }}"
monitoring_interval: 0
storage_type: standard
skip_final_snapshot: true
Expand All @@ -204,7 +198,7 @@
- name: Get RDS instance info
amazon.aws.rds_instance_info:
db_instance_identifier: "{{ rds_identifier }}"
register: rds_info
register: rds_result

- name: Set 'sshkey_file' variable
ansible.builtin.set_fact:
Expand Down Expand Up @@ -237,24 +231,4 @@
- "{{ secgroup.group_id }}"
wait: true
state: started
register: result

- name: Add host to inventory
ansible.builtin.add_host:
hostname: bastion
ansible_ssh_user: "{{ bastion_host_username }}"
ansible_host: "{{ result.instances.0.public_ip_address }}"
ansible_ssh_common_args: -o "UserKnownHostsFile=/dev/null" -o StrictHostKeyChecking=no -i {{ sshkey_file }}
ansible_host_name: "{{ result.instances.0.public_dns_name | split('.') | first }}"
host_config:
public_subnet_id: "{{ subnet.subnet.id }}"
private_subnet_id: "{{ private_subnet.subnet.id }}"
image_id: "{{ images.images.0.image_id }}"
group_id: "{{ secgroup.group_id }}"
private_ip: "{{ result.instances.0.private_ip_address }}"
vpc_id: "{{ vpc.vpc.id }}"
rds_info:
host: "{{ rds_info.instances.0.endpoint.address }}"
name: "{{ rds_instance_name }}"
master_user_password: "{{ rds_master_password }}"
master_username: "{{ rds_master_user }}"
register: vm_result
10 changes: 4 additions & 6 deletions playbooks/webapp/tasks/delete.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
---
- name: Delete resources playbook
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: "{{ region | default(aws_region) }}"

block:
- name: Set 'region' variable
ansible.builtin.set_fact:
region: "{{ region | default(aws_region) }}"

- name: Get vpc information
amazon.aws.ec2_vpc_net_info:
filters:
Expand Down
242 changes: 0 additions & 242 deletions playbooks/webapp/tasks/deploy_app.yaml

This file was deleted.

Loading