Skip to content

Commit

Permalink
Rename playbook and role vars
Browse files Browse the repository at this point in the history
  • Loading branch information
GomathiselviS committed Sep 8, 2023
1 parent c2ef58c commit 8b6309c
Show file tree
Hide file tree
Showing 18 changed files with 213 additions and 197 deletions.
2 changes: 1 addition & 1 deletion changelogs/fragments/add_deploy_flask_app_role.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +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)."
- "Rename the vars in webapp playbook with role name prefix (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)."
32 changes: 16 additions & 16 deletions playbooks/webapp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ To delete the webapp:
### EC2 instance

* **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: `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:
* **deploy_sshkey_pair_name** (str): Name for the EC2 key pair. Default: `"{{ resource_prefix }}-key"`
* **deploy_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
Expand All @@ -125,7 +125,7 @@ To delete the webapp:
* **rds_subnet_group_name** (str): Subnet group name for the RDS instance. Default: `"{{ resource_prefix }}-rds-sg"`
* **rds_secgroup_name** (str): Security group name for the RDS instance. Default: `"{{ resource_prefix }}-rds-sec"`
* **public_secgroup_name** (str): Security group name for the bastion host. Default: `"{{ resource_prefix }}-sg"`
* **app_listening_port** (int): Connection listening port for the app on the bastion host. Default: `5000`
* **deploy_flask_app_listening_port** (int): Connection listening port for the app on the bastion host. Default: `5000`
* **rds_listening_port** (int): Connection listening port for the RDS instance. Default: `5432`

### RDS instance
Expand All @@ -137,25 +137,25 @@ 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_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_`
* **deploy_flask_app_rds_master_username** (str): Name of the master user for the database instance. Default: `ansible`
* **deploy_flask_app_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: `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 }}"`
* **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:
* **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
env: development
admin_user: admin
admin_password: admin
```
* **app_force_init** (bool): Whether to drop existing tables and create new ones when deploying the webapp database. Default: `false`
* **deploy_flask_app_force_init** (bool): Whether to drop existing tables and create new ones when deploying the webapp database. Default: `false`

## Example Usage

Expand Down
6 changes: 5 additions & 1 deletion playbooks/webapp/migrate_webapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@
ansible.builtin.import_role:
name: cloud.aws_ops.deploy_flask_app
vars:
region: "{{ dest_region }}"
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 }}"
20 changes: 10 additions & 10 deletions playbooks/webapp/tasks/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
to_port: 22
- cidr_ip: 0.0.0.0/0
proto: tcp
from_port: "{{ app_listening_port }}"
to_port: "{{ app_listening_port }}"
from_port: "{{ deploy_flask_app_listening_port }}"
to_port: "{{ deploy_flask_app_listening_port }}"
rules_egress:
- cidr_ip: 0.0.0.0/0
proto: -1
Expand Down Expand Up @@ -163,8 +163,8 @@
db_name: "{{ rds_instance_name }}"
engine: "{{ rds_engine }}"
engine_version: "{{ rds_engine_version }}"
master_user_password: "{{ rds_master_password }}"
master_username: "{{ rds_master_username }}"
master_user_password: "{{ deploy_flask_app_rds_master_password }}"
master_username: "{{ deploy_flask_app_rds_master_username }}"
monitoring_interval: 0
storage_type: standard
skip_final_snapshot: true
Expand All @@ -183,8 +183,8 @@
db_instance_identifier: "{{ rds_identifier }}"
engine: "{{ rds_engine }}"
engine_version: "{{ rds_engine_version }}"
master_user_password: "{{ rds_master_password }}"
master_username: "{{ rds_master_username }}"
master_user_password: "{{ deploy_flask_app_rds_master_password }}"
master_username: "{{ deploy_flask_app_rds_master_username }}"
monitoring_interval: 0
storage_type: standard
skip_final_snapshot: true
Expand All @@ -202,11 +202,11 @@

- name: Set 'sshkey_file' variable
ansible.builtin.set_fact:
sshkey_file: ~/private-key-{{ sshkey_pair_name }}-{{ region | default(aws_region) }}
sshkey_file: ~/private-key-{{ deploy_flask_app_sshkey_pair_name }}-{{ region | default(aws_region) }}

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

- name: Save private key into file
Expand All @@ -218,10 +218,10 @@

- name: Create a virtual machine
amazon.aws.ec2_instance:
name: "{{ bastion_host_name }}"
name: "{{ deploy_flask_app_bastion_host_name }}"
instance_type: "{{ bastion_host_type }}"
image_id: "{{ images.images.0.image_id }}"
key_name: "{{ sshkey_pair_name }}"
key_name: "{{ deploy_flask_app_sshkey_pair_name }}"
subnet_id: "{{ subnet.subnet.id }}"
network:
assign_public_ip: true
Expand Down
4 changes: 2 additions & 2 deletions playbooks/webapp/tasks/delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
amazon.aws.ec2_instance_info:
filters:
instance-type: "{{ bastion_host_type }}"
key-name: "{{ sshkey_pair_name }}"
key-name: "{{ deploy_flask_app_sshkey_pair_name }}"
vpc-id: "{{ vpc_id }}"
register: bastion

Expand Down Expand Up @@ -74,7 +74,7 @@

- name: Delete key pair to connect to the bastion VM
amazon.aws.ec2_key:
name: "{{ sshkey_pair_name }}"
name: "{{ deploy_flask_app_sshkey_pair_name }}"
state: absent

- name: Delete RDS subnet group
Expand Down
62 changes: 29 additions & 33 deletions playbooks/webapp/vars/main.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
# Variables for create.yaml
aws_region: us-east-1
resource_prefix: "ansible-demo-test"
vpc_name: "{{ resource_prefix }}-vpc"
Expand All @@ -9,52 +10,47 @@ subnet_cidr:
- 10.1.2.0/24
resource_tags:
prefix: "{{ resource_prefix }}"
operation: create

rds_subnet_group_name: "{{ resource_prefix }}-rds-sg"
image_filter: Fedora-Cloud-Base-35-*
public_secgroup_name: "{{ resource_prefix }}-sg"
rds_subnet_group_name: "{{ resource_prefix }}-rds-sg"
rds_secgroup_name: "{{ resource_prefix }}-rds-sec"
rds_identifier: "{{ resource_prefix }}-rds-01"
sshkey_pair_name: "{{ resource_prefix }}-key"


bastion_host_name: "{{ resource_prefix }}-bastion"
bastion_host_username: fedora
rds_allocated_storage_gb: 20
rds_instance_class: db.m6g.large
rds_instance_name: mysampledb123
rds_engine: postgres
rds_engine_version: "14.8"
bastion_host_type: t2.xlarge
bastion_host_required_packages:
bastion_host_venv_path: ~/env
rds_listening_port: 5432

# Variables for the deploy_flask_app role
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
- podman
- httpd-tools
- ansible
bastion_host_venv_path: ~/env

workers_instance_type: t3.micro
workers_user_name: fedora
number_of_workers: 2

app_listening_port: 5000
app_git_repository: https://github.com/abikouo/webapp_pyflask_demo.git
app_config:
deploy_flask_app_workers_instance_type: t3.micro
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
app_force_init: false
rds_listening_port: 5432
local_registry_user: ansible
local_registry_pwd: testing123
local_registry_port: "{{ app_listening_port }}"

rds_allocated_storage_gb: 20
rds_instance_class: db.m6g.large
rds_instance_name: mysampledb123
rds_engine: postgres
rds_engine_version: "14.8"
rds_master_password: L#5cH2mgy_
rds_master_username: ansible

image_filter: Fedora-Cloud-Base-35-*

operation: create
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
10 changes: 5 additions & 5 deletions playbooks/webapp/webapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- name: Run operation create/delete
ansible.builtin.import_tasks: tasks/{{ operation }}.yaml

- name: Deploy resource from Bastion
- name: Deploy Flask App
hosts: localhost
gather_facts: false

Expand All @@ -28,7 +28,7 @@
ansible.builtin.include_role:
name: cloud.aws_ops.deploy_flask_app
vars:
private_subnet_id: "{{ private_subnet.subnet.id }}"
vpc_id: "{{ vpc.vpc.id }}"
vm_info: "{{ vm_result }}"
rds_info: "{{ rds_result }}"
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 }}"
53 changes: 32 additions & 21 deletions roles/deploy_flask_app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,33 @@ Role Variables

## variables to create new hosts and groups in inventory of in memory playbook.

* **region** (str): Region where the app is to be deployed.
* **bastion_host_username** (str): Username for the bastion host SSH user.
* **private_subnet_id** (str): Private subnet id of the bastion host
* **vpc_id** (str): vpc id for the host.
* **rds_info** (dict): A dict of information for the backend RDS. This dict has the output of amazon.aws.rds_instance_info mode.
* **rds_master_username** (str): Username for the RDS instance.
* **rds_master_password** (str): password for the RDS instance.
* **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_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
* **bastion_host_name** (str): Name for the EC2 instance.
* **bastion_host_required_packages** (list): Packages to be installed on the bastion host.
* **number_of_workers** (int): Number of instances to create.
* **workers_instance_type** (str): RC2 instance type for workers.
* **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_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
* **app_git_repository** (str): Git repository to be cloned for the webapp.
* **app_listening_port** (int): Load balancer port.
* **app_force_init** (bool): A boolean value True to force init the app and False to not force init.
* **local_registry_user** (str): Registry user name.
* **local_registry_pwd** (str): Registry password.
* **app_config** (dict): A dict of config parameterys for the 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.
**admin_password** (str): App config's admin password.
Expand All @@ -66,11 +69,11 @@ This role takes care of adding the bastion host to the inventory and deploying t
* A Bastion host.
* SSH key pair to connect to the host.

The setup of these resources needed for the app deployment can be done using a playbook similar to this [playbook]((https://github.com/ansible-collections/cloud.aws_ops/playbooks/webapp/tasks/create.yaml).
The setup of these resources needed for the app deployment can be done using a playbook similar to this [playbook](https://github.com/ansible-collections/cloud.aws_ops/playbooks/webapp/tasks/create.yaml).

**Deploy a simple flask app**

- name: Deploy resource from Bastion
- name: Import Deploy Flask App Role
hosts: localhost
gather_facts: false

Expand All @@ -79,7 +82,15 @@ The setup of these resources needed for the app deployment can be done using a p

tasks:
- name: Deploy app
ansible.builtin.import_tasks: deploy_app.yaml
ansible.builtin.import_role: deploy_flask_app.yaml

- name: Use Deploy Flask App Role
hosts: localhost
roles:
- role: cloud.aws_ops.deploy_flask_app
vars:
- [vars.yaml](https://github.com/ansible-collections/cloud.aws_ops/playbooks/webapp/vars/main.yaml)


License
-------
Expand Down
Loading

0 comments on commit 8b6309c

Please sign in to comment.