Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
abikouo committed Dec 22, 2023
1 parent 7a16851 commit 584a227
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ 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).
- >-
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).
3 changes: 2 additions & 1 deletion roles/deploy_flask_app/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
deploy_flask_app_workers_ssh_private_key: "/tmp/id_rsa"
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.

21 changes: 0 additions & 21 deletions roles/deploy_flask_app/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ argument_specs:
type: path
required: True
version_added: 2.1.0
deploy_flask_app_bastion_host_required_packages:
description: Packages to be installed on the bastion host.
type: list
elements: str
required: True
deploy_flask_app_private_subnet_id:
description: Private subnet id of the bastion host.
type: str
Expand Down Expand Up @@ -65,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 @@ -77,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
69 changes: 0 additions & 69 deletions roles/deploy_flask_app/tasks/build_app.yaml

This file was deleted.

99 changes: 50 additions & 49 deletions roles/deploy_flask_app/tasks/deploy_app.yaml
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
---
- name: Generate configuration (inventory, vars) from templates
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: 0644
with_items:
- src: inventory.j2
dest: ~/inventory.ini
- src: vars.yaml.j2
dest: vars.yaml
- name: Deploy application into worker
delegate_to: "{{ worker_id }}"
vars:
deploy_flask_app__worker_container_name: "webapp-container1"
block:
- name: Update ssh_config
ansible.builtin.lineinfile:
path: /etc/ssh/sshd_config
regex: "{{ item.regex }}"
line: "{{ item.line }}"
loop:
- regex: ^(# *)?ClientAliveInterval
line: ClientAliveInterval 1200
- regex: ^(# *)?ClientAliveCountMax
line: ClientAliveCountMax 3
become: true

- name: Ensure workers are reachable from bastion host
ansible.builtin.command:
cmd: "ansible -m ping -i ~/inventory.ini all"
- name: Install Podman
ansible.builtin.yum:
name:
- podman
update_cache: False
state: present
become: true

- name: Initialize database tables
ansible.builtin.shell:
cmd: >
podman run --rm
-e FLASK_APP="{{ deploy_flask_app_config.app_dir }}"
-e FLASK_ENV="{{ deploy_flask_app_config.env }}"
-e DATABASE_HOST="{{ deploy_flask_app_setup.add_host.host_vars.host_config.rds_info.host }}"
-e DATABASE_INSTANCE="{{ deploy_flask_app_setup.add_host.host_vars.host_config.rds_info.name }}"
-e DATABASE_USER="{{ deploy_flask_app_setup.add_host.host_vars.host_config.rds_info.master_username }}"
-e DATABASE_PASSWORD="{{ deploy_flask_app_setup.add_host.host_vars.host_config.rds_info.master_user_password }}"
-e ADMIN_USER="{{ deploy_flask_app_config.admin_user }}"
-e ADMIN_PASSWORD="{{ deploy_flask_app_config.admin_password }}"
-e WORKER_HOSTNAME="{{ inventory_hostname }}"
-e WORKERS_HOSTS="bastion"
webapp flask {{ deploy_flask_app_force_init | bool | ternary('force-init-db', 'init-db') }}
run_once: true
changed_when: false
- name: Check running container
ansible.builtin.shell:
cmd: >
podman container ps -a
-f name={{ deploy_flask_app__worker_container_name }}
--format=.Names
register: container
changed_when: false

- name: Copy playbook into bastion host
ansible.builtin.copy:
src: run_app.yaml
dest: ~/playbook.yaml
mode: 0644

- name: Deploy application into workers
ansible.builtin.shell:
cmd: >
ansible-playbook playbook.yaml -i inventory.ini -vvv
-e '@vars.yaml'
-e registry_host_port='{{ deploy_flask_app_setup.add_host.host_vars.host_config.private_ip }}:{{ deploy_flask_app_listening_port }}'
args:
chdir: ~/
changed_when: false

- name: Debug application url
ansible.builtin.debug:
msg: "Application url: {{ deploy_flask_app_lb_result.elb.dns_name }}:{{ deploy_flask_app_listening_port }}"
- name: Run application instance

Check failure on line 36 in roles/deploy_flask_app/tasks/deploy_app.yaml

View workflow job for this annotation

GitHub Actions / ansible-lint

command-instead-of-shell

Use shell only when shell functionality is required.
ansible.builtin.shell:
cmd: >-

Check warning on line 38 in roles/deploy_flask_app/tasks/deploy_app.yaml

View workflow job for this annotation

GitHub Actions / ansible-lint

jinja[spacing]

Jinja2 spacing could be improved: podman run --rm -e FLASK_APP="{{ deploy_flask_app_config.app_dir }}" -e FLASK_ENV="{{ deploy_flask_app_config.env }}" -e DATABASE_HOST="{{ deploy_flask_app__rds_host }}" -e DATABASE_INSTANCE="{{ deploy_flask_app__rds_dbname }}" -e DATABASE_USER="{{ deploy_flask_app_rds_master_username }}" -e DATABASE_PASSWORD="{{deploy_flask_app_rds_master_password }}" -e ADMIN_USER="{{ deploy_flask_app_config.admin_user }}" -e ADMIN_PASSWORD="{{ deploy_flask_app_config.admin_password }}" -e WORKER_HOSTNAME="{{ worker_id }}" -e WORKERS_HOSTS="{{ deploy_flask_app_instances | join(',') }}" -p 5000:5000 --name {{ deploy_flask_app__worker_container_name }} -d {{ deploy_flask_app_container_image }} -> podman run --rm -e FLASK_APP="{{ deploy_flask_app_config.app_dir }}" -e FLASK_ENV="{{ deploy_flask_app_config.env }}" -e DATABASE_HOST="{{ deploy_flask_app__rds_host }}" -e DATABASE_INSTANCE="{{ deploy_flask_app__rds_dbname }}" -e DATABASE_USER="{{ deploy_flask_app_rds_master_username }}" -e DATABASE_PASSWORD="{{ deploy_flask_app_rds_master_password }}" -e ADMIN_USER="{{ deploy_flask_app_config.admin_user }}" -e ADMIN_PASSWORD="{{ deploy_flask_app_config.admin_password }}" -e WORKER_HOSTNAME="{{ worker_id }}" -e WORKERS_HOSTS="{{ deploy_flask_app_instances | join(',') }}" -p 5000:5000 --name {{ deploy_flask_app__worker_container_name }} -d {{ deploy_flask_app_container_image }}
podman run --rm
-e FLASK_APP="{{ deploy_flask_app_config.app_dir }}"
-e FLASK_ENV="{{ deploy_flask_app_config.env }}"
-e DATABASE_HOST="{{ deploy_flask_app__rds_host }}"
-e DATABASE_INSTANCE="{{ deploy_flask_app__rds_dbname }}"
-e DATABASE_USER="{{ deploy_flask_app_rds_master_username }}"
-e DATABASE_PASSWORD="{{deploy_flask_app_rds_master_password }}"
-e ADMIN_USER="{{ deploy_flask_app_config.admin_user }}"
-e ADMIN_PASSWORD="{{ deploy_flask_app_config.admin_password }}"
-e WORKER_HOSTNAME="{{ worker_id }}"
-e WORKERS_HOSTS="{{ deploy_flask_app_instances | join(',') }}"
-p 5000:5000 --name {{ deploy_flask_app__worker_container_name }}
-d {{ deploy_flask_app_container_image }}
when:
- container.stdout == ""
changed_when: true
16 changes: 5 additions & 11 deletions roles/deploy_flask_app/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@
- name: Add bastion host to inventory
ansible.builtin.include_tasks: update_inventory.yaml

- name: Running from bastion host
delegate_to: bastion
block:
- name: Deploy resource from Bastion
ansible.builtin.include_tasks: setup_bastion.yaml

- name: Build application and push container image into private registry
ansible.builtin.include_tasks: build_app.yaml

- name: Deploy App
ansible.builtin.include_tasks: deploy_app.yaml
- name: Deploy application into workers
ansible.builtin.include_tasks: deploy_app.yaml
with_items: "{{ deploy_flask_app_vms.instances | map(attribute='instance_id') | list }}"
loop_control:
loop_var: worker_id
31 changes: 0 additions & 31 deletions roles/deploy_flask_app/tasks/setup_bastion.yaml

This file was deleted.

9 changes: 2 additions & 7 deletions roles/deploy_flask_app/tasks/setup_infra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,12 @@

- name: Create list of instances (join)
ansible.builtin.set_fact:
deploy_flask_app_instances_list: []
deploy_flask_app_instances: []
- name: Update join_instances
ansible.builtin.set_fact:
deploy_flask_app_instances_list: "{{ deploy_flask_app_instances_list + [item.instance_id + ':' + item.private_ip_address] }}"
deploy_flask_app_instances: "{{ deploy_flask_app_instances + [item.instance_id + ':' + item.private_ip_address] }}"
with_items: "{{ deploy_flask_app_vms.instances }}"

- name: Set variables
ansible.builtin.set_fact:
deploy_flask_app_workers_instances: "{{ deploy_flask_app_vms.instances }}"
deploy_flask_app_workers_join: "{{ deploy_flask_app_instances_list | join(',') }}"

- name: Create load balancer
amazon.aws.elb_classic_lb:
state: present
Expand Down
Loading

0 comments on commit 584a227

Please sign in to comment.