Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
abikouo committed Jan 9, 2024
1 parent 0957321 commit 136d136
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 46 deletions.
7 changes: 1 addition & 6 deletions roles/deploy_flask_app/tasks/setup_infra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions roles/deploy_flask_app/tasks/start_containers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 2 additions & 18 deletions roles/deploy_flask_app/templates/deploy_app.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
changed_when: true
56 changes: 34 additions & 22 deletions tests/integration/targets/test_deploy_flask_app/tasks/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}"
Expand Down Expand Up @@ -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 }}"
Expand All @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit 136d136

Please sign in to comment.