diff --git a/playbooks/webapp/tasks/create.yaml b/playbooks/webapp/tasks/create.yaml index ee870b65..76d6e9e3 100644 --- a/playbooks/webapp/tasks/create.yaml +++ b/playbooks/webapp/tasks/create.yaml @@ -218,15 +218,6 @@ 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 - - name: Ensure IAM instance role exists amazon.aws.iam_role: name: "{{ ec2_iam_role_name }}" @@ -237,7 +228,6 @@ 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 }}" @@ -254,7 +244,7 @@ - "{{ secgroup.group_id }}" user_data: | #!/bin/bash - yum install -y python3 python-virtualenv sshpass netcat + yum install -y python3 python-virtualenv sshpass netcat ansible wait: true state: started register: vm_result diff --git a/playbooks/webapp/vars/main.yaml b/playbooks/webapp/vars/main.yaml index a0de9c64..d4a7fbc9 100644 --- a/playbooks/webapp/vars/main.yaml +++ b/playbooks/webapp/vars/main.yaml @@ -12,7 +12,7 @@ resource_tags: prefix: "{{ resource_prefix }}" operation: create -image_filter: Fedora-Cloud-Base-35-*gp2-0 +image_filter: Fedora-Cloud-Base-38-* public_secgroup_name: "{{ resource_prefix }}-sg" ec2_iam_role_name: "{{ resource_prefix }}-role" rds_subnet_group_name: "{{ resource_prefix }}-rds-sg" @@ -23,7 +23,7 @@ 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_type: t3.micro bastion_host_venv_path: ~/env rds_listening_port: 5432 @@ -31,7 +31,7 @@ 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_workers_instance_type: t2.xlarge +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 diff --git a/roles/deploy_flask_app/tasks/main.yaml b/roles/deploy_flask_app/tasks/main.yaml index 93a2073a..c68cfbf7 100644 --- a/roles/deploy_flask_app/tasks/main.yaml +++ b/roles/deploy_flask_app/tasks/main.yaml @@ -18,3 +18,7 @@ - name: Start application container into workers ansible.builtin.include_tasks: start_containers.yaml + + - name: Display application URL + ansible.builtin.debug: + msg: "Application accessible at http://{{ deploy_flask_app_lb_result.elb.dns_name }}:{{ deploy_flask_app_listening_port }}" diff --git a/tests/integration/targets/setup_rsa_keys/handlers/main.yml b/tests/integration/targets/setup_rsa_keys/handlers/main.yml index 03ea4269..04fcf9aa 100644 --- a/tests/integration/targets/setup_rsa_keys/handlers/main.yml +++ b/tests/integration/targets/setup_rsa_keys/handlers/main.yml @@ -1,6 +1,6 @@ --- -- name: Delete temporary RSA key directory +- name: Delete RSA key directory ansible.builtin.file: state: absent - path: "{{ setup_rsa_keys__tmpdir }}" + path: "{{ setup_rsa_keys__path }}" ignore_errors: true diff --git a/tests/integration/targets/setup_rsa_keys/tasks/main.yml b/tests/integration/targets/setup_rsa_keys/tasks/main.yml index 23c16c8a..8ef0edfe 100644 --- a/tests/integration/targets/setup_rsa_keys/tasks/main.yml +++ b/tests/integration/targets/setup_rsa_keys/tasks/main.yml @@ -19,6 +19,7 @@ ansible.builtin.file: path: "{{ setup_rsa_keys__path }}" state: directory + notify: 'Delete RSA key directory' - name: Generate RSA keys community.crypto.openssh_keypair: diff --git a/tests/integration/targets/test_deploy_flask_app/aliases b/tests/integration/targets/test_deploy_flask_app/aliases index de2fdf2f..c63f9525 100644 --- a/tests/integration/targets/test_deploy_flask_app/aliases +++ b/tests/integration/targets/test_deploy_flask_app/aliases @@ -1,3 +1,4 @@ cloud/aws role/deploy_flask_app time=35m +unstable diff --git a/tests/integration/targets/test_playbook_webapp/aliases b/tests/integration/targets/test_playbook_webapp/aliases new file mode 100644 index 00000000..87ff2914 --- /dev/null +++ b/tests/integration/targets/test_playbook_webapp/aliases @@ -0,0 +1,2 @@ +time=35m +cloud/aws diff --git a/tests/integration/targets/test_playbook_webapp/runme.sh b/tests/integration/targets/test_playbook_webapp/runme.sh new file mode 100755 index 00000000..25064858 --- /dev/null +++ b/tests/integration/targets/test_playbook_webapp/runme.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -eux + +function cleanup() { + ansible-playbook webapp.yaml -e "operation=delete" "$@" + exit 1 +} + +trap 'cleanup "${@}"' ERR + +ansible-playbook webapp.yaml "$@" diff --git a/tests/integration/targets/test_playbook_webapp/webapp.yaml b/tests/integration/targets/test_playbook_webapp/webapp.yaml new file mode 100644 index 00000000..09ef0ea3 --- /dev/null +++ b/tests/integration/targets/test_playbook_webapp/webapp.yaml @@ -0,0 +1 @@ +- import_playbook: cloud.aws_ops.webapp.webapp