70 lines
2.5 KiB
YAML
70 lines
2.5 KiB
YAML
---
|
|
- name: Deploy application stack
|
|
community.docker.docker_compose_v2:
|
|
project_src: "{{ application_stack_dest }}"
|
|
state: present
|
|
pull: always
|
|
recreate: "{{ application_compose_recreate }}"
|
|
remove_orphans: "{{ application_remove_orphans | bool }}"
|
|
register: application_compose_result
|
|
|
|
- name: Wait for application container to report Up
|
|
shell: |
|
|
docker compose -f {{ application_stack_dest }}/docker-compose.yml ps app | grep -Eiq "Up|running"
|
|
register: application_app_running
|
|
changed_when: false
|
|
until: application_app_running.rc == 0
|
|
retries: "{{ ((application_wait_timeout | int) + (application_wait_interval | int) - 1) // (application_wait_interval | int) }}"
|
|
delay: "{{ application_wait_interval | int }}"
|
|
when: application_compose_result.changed
|
|
|
|
- name: Ensure app container is running before migrations
|
|
shell: |
|
|
docker compose -f {{ application_stack_dest }}/docker-compose.yml ps app | grep -Eiq "Up|running"
|
|
args:
|
|
executable: /bin/bash
|
|
register: application_app_container_running
|
|
changed_when: false
|
|
failed_when: false
|
|
when: application_compose_result.changed
|
|
|
|
- name: Run database migrations
|
|
shell: |
|
|
docker compose -f {{ application_stack_dest }}/docker-compose.yml exec -T app {{ application_migration_command }}
|
|
args:
|
|
executable: /bin/bash
|
|
register: application_migration_result
|
|
changed_when: true
|
|
failed_when: false
|
|
ignore_errors: yes
|
|
when:
|
|
- application_run_migrations
|
|
- application_compose_result.changed
|
|
- application_app_container_running.rc == 0
|
|
|
|
- name: Collect application container status
|
|
shell: docker compose -f {{ application_stack_dest }}/docker-compose.yml ps
|
|
register: application_ps
|
|
changed_when: false
|
|
ignore_errors: yes
|
|
|
|
- name: Perform application health check
|
|
uri:
|
|
url: "{{ application_healthcheck_url }}"
|
|
method: GET
|
|
validate_certs: no
|
|
status_code: [200, 404, 502, 503]
|
|
timeout: 10
|
|
register: application_healthcheck_result
|
|
ignore_errors: yes
|
|
when:
|
|
- application_healthcheck_url | length > 0
|
|
- application_compose_result.changed
|
|
|
|
- name: Set application role summary facts
|
|
set_fact:
|
|
application_stack_changed: "{{ application_compose_result.changed | default(false) }}"
|
|
application_health_output: "{{ application_ps.stdout | default('') }}"
|
|
application_healthcheck_status: "{{ application_healthcheck_result.status | default('unknown') }}"
|
|
application_migration_stdout: "{{ application_migration_result.stdout | default('') }}"
|