Skip to content

Commit

Permalink
add retries when trying to connect to ec2 instances
Browse files Browse the repository at this point in the history
  • Loading branch information
abikouo committed Jan 9, 2024
1 parent b45004c commit 0957321
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
24 changes: 24 additions & 0 deletions roles/deploy_flask_app/tasks/start_containers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,41 @@
path: "~/.ssh"
- state: touch
path: "~/.ssh/config"
retries: 5
delay: 5
until: result is successful
register: result

- name: Update local .ssh/config
ansible.builtin.blockinfile:
state: present
insertafter: EOF
dest: "~/.ssh/config"
content: "{{ lookup('template', 'bastion_ssh_config.j2') }}"
retries: 5
delay: 5
until: result is successful
register: result

- name: Copy remote ssh private key file into bastion
ansible.builtin.copy:
src: "{{ deploy_flask_app_bastion_ssh_private_key }}"
dest: "{{ deploy_flask_app_workers_ssh_private_key }}"
mode: 0400
retries: 5
delay: 5
until: result is successful
register: result

- name: Generate workers inventory file
ansible.builtin.copy:
content: "{{ lookup('template', 'workers_inventory.yaml.j2') }}"
dest: "{{ deploy_flask_app_workers_inventory_file }}"
mode: 0755
retries: 5
delay: 5
until: result is successful
register: result

- name: Generate playbook to deploy application
ansible.builtin.copy:
Expand All @@ -72,10 +88,18 @@
vars:
deploy_flask_app_instances_list: "{{ deploy_flask_app_instances | join(',') }}"
deploy_flask_app_worker_hostname: "{{ '{{' }} inventory_hostname {{ '}}' }}"
retries: 5
delay: 5
until: result is successful
register: result

- name: Deploy application into workers
ansible.builtin.command: >-
ansible-playbook
--inventory {{ deploy_flask_app_workers_inventory_file }}
{{ deploy_flask_app_workers_playbook_file }}
-v
retries: 5
delay: 5
until: result is successful
register: result
18 changes: 17 additions & 1 deletion roles/deploy_flask_app/templates/deploy_app.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,31 @@
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
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 @@ -46,4 +58,8 @@
-d {{ deploy_flask_app_container_image }}
when:
- container.stdout == ""
changed_when: true
changed_when: true
retries: 5
delay: 5
until: result is successful
register: result
1 change: 0 additions & 1 deletion tests/integration/targets/test_deploy_flask_app/aliases
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cloud/aws
role/deploy_flask_app
time=35m
unstable

0 comments on commit 0957321

Please sign in to comment.