From 136d1366c9a9832a0601cc012a29f60ceae3932c Mon Sep 17 00:00:00 2001 From: abikouo Date: Tue, 9 Jan 2024 17:49:13 +0100 Subject: [PATCH] minor updates --- roles/deploy_flask_app/tasks/setup_infra.yaml | 7 +-- .../tasks/start_containers.yaml | 7 +++ .../templates/deploy_app.yaml.j2 | 20 +------ .../test_deploy_flask_app/tasks/create.yaml | 56 +++++++++++-------- 4 files changed, 44 insertions(+), 46 deletions(-) diff --git a/roles/deploy_flask_app/tasks/setup_infra.yaml b/roles/deploy_flask_app/tasks/setup_infra.yaml index 388f264..81fe2d6 100644 --- a/roles/deploy_flask_app/tasks/setup_infra.yaml +++ b/roles/deploy_flask_app/tasks/setup_infra.yaml @@ -70,9 +70,4 @@ subnets: - "{{ deploy_flask_app__public_subnet_id }}" scheme: internet-facing - wait: true - wait_timeout: 360 - retries: 5 - delay: 10 - until: deploy_flask_app_lb_result is successful - register: deploy_flask_app_lb_result + wait: false diff --git a/roles/deploy_flask_app/tasks/start_containers.yaml b/roles/deploy_flask_app/tasks/start_containers.yaml index ee875a6..8afcc36 100644 --- a/roles/deploy_flask_app/tasks/start_containers.yaml +++ b/roles/deploy_flask_app/tasks/start_containers.yaml @@ -103,3 +103,10 @@ delay: 5 until: result is successful register: result + + - name: "Ensure application is reachable on worker {{ worker.instance_id }}" + ansible.builtin.uri: + url: "http://{{ worker.private_ip_address }}:{{ deploy_flask_app_listening_port }}" + with_items: "{{ deploy_flask_app_vms.instances }}" + loop_control: + loop_var: worker diff --git a/roles/deploy_flask_app/templates/deploy_app.yaml.j2 b/roles/deploy_flask_app/templates/deploy_app.yaml.j2 index 7c39f04..357c13b 100644 --- a/roles/deploy_flask_app/templates/deploy_app.yaml.j2 +++ b/roles/deploy_flask_app/templates/deploy_app.yaml.j2 @@ -12,31 +12,19 @@ block: | ClientAliveInterval 1200 ClientAliveCountMax 3 - retries: 5 - delay: 5 - until: result is successful - register: result - name: Install Podman ansible.builtin.yum: name: - podman - update_cache: True + update_cache: false state: present - retries: 5 - delay: 5 - until: result is successful - register: result - name: Check running container ansible.builtin.shell: cmd: "podman container ps -a -f name=webapp-container-1 --format=.Names" register: container changed_when: false - retries: 5 - delay: 5 - until: result is successful - register: result - name: Run application instance ansible.builtin.shell: @@ -58,8 +46,4 @@ -d {{ deploy_flask_app_container_image }} when: - container.stdout == "" - changed_when: true - retries: 5 - delay: 5 - until: result is successful - register: result \ No newline at end of file + changed_when: true \ No newline at end of file diff --git a/tests/integration/targets/test_deploy_flask_app/tasks/create.yaml b/tests/integration/targets/test_deploy_flask_app/tasks/create.yaml index 6f89816..e609649 100644 --- a/tests/integration/targets/test_deploy_flask_app/tasks/create.yaml +++ b/tests/integration/targets/test_deploy_flask_app/tasks/create.yaml @@ -74,9 +74,8 @@ amazon.aws.ec2_vpc_nat_gateway: subnet_id: "{{ subnet.subnet.id }}" if_exist_do_not_create: true - wait: true + wait: false # Long running tasks, the availability will checked later state: present - register: nat_gw - name: Create Route table for internet gateway (public subnet) amazon.aws.ec2_vpc_route_table: @@ -92,20 +91,6 @@ route: internet state: present - - name: Create Route table for NAT gateway (private subnet) - amazon.aws.ec2_vpc_route_table: - vpc_id: "{{ vpc.vpc.id }}" - subnets: - - "{{ private_subnet.subnet.id }}" - routes: - - dest: 0.0.0.0/0 - gateway_id: "{{ nat_gw.nat_gateway_id }}" - lookup: tag - resource_tags: - subnet: private - route: nat-gateway - state: present - - name: Create security group for bastion amazon.aws.ec2_security_group: name: "{{ public_secgroup_name }}" @@ -144,7 +129,6 @@ - name: Create RDS instance (PostGreSQL Database) amazon.aws.rds_instance: force_update_password: true - wait: true allocated_storage: "{{ rds_allocated_storage_gb }}" backup_retention_period: 0 db_instance_class: "{{ rds_instance_class }}" @@ -160,11 +144,7 @@ db_subnet_group_name: "{{ rds_subnet_group_name }}" vpc_security_group_ids: - "{{ rds_sg.group_id }}" - - - name: Get RDS instance info - amazon.aws.rds_instance_info: - db_instance_identifier: "{{ rds_identifier }}" - register: rds_result + wait: false - name: Create key pair to connect to the VM amazon.aws.ec2_key: @@ -201,3 +181,35 @@ wait: true state: started register: vm_result + + - name: Wait for the NAT gateway to be available + amazon.aws.ec2_vpc_nat_gateway_info: + filters: + subnet-id: "{{ subnet.subnet.id }}" + state: "available" + register: nat_gateway + retries: 60 + delay: 5 + until: nat_gateway.result | length > 0 + + - name: Create Route table for NAT gateway (private subnet) + amazon.aws.ec2_vpc_route_table: + vpc_id: "{{ vpc.vpc.id }}" + subnets: + - "{{ private_subnet.subnet.id }}" + routes: + - dest: 0.0.0.0/0 + gateway_id: "{{ nat_gateway.result.0.nat_gateway_id }}" + lookup: tag + resource_tags: + subnet: private + route: nat-gateway + state: present + + - name: Wait for the RDS instance to be available + amazon.aws.rds_instance_info: + db_instance_identifier: "{{ rds_identifier }}" + retries: 60 + delay: 5 + until: rds_result.instances.0.db_instance_status == "available", + register: rds_result