This repository has been archived on 2026-03-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
kube_build/playbooks/docker_update_containers.yml
T
2023-12-11 14:06:37 -05:00

52 lines
1.6 KiB
YAML

---
- name: Update Docker Containers With New Images
hosts: Docker
gather_facts: yes
tasks:
- name: Stop and remove Docker containers
ansible.builtin.command: docker compose down
args:
chdir: "{{ compose_file_path | dirname }}"
loop: "{{ compose_file_paths }}"
ignore_errors: yes
loop_control:
loop_var: compose_file_path
- name: Run docker compose up
ansible.builtin.command: docker compose up -d
args:
chdir: "{{ compose_file_path | dirname }}"
loop: "{{ compose_file_paths }}"
loop_control:
loop_var: compose_file_path
- name: Pause for 60 seconds to allow containers to stabilize
ansible.builtin.pause:
seconds: 60
- name: Check container status
ansible.builtin.shell: docker compose ps -q | xargs -n1 docker container inspect --format '{{ "{{" }} .State.Running {{ "}}" }}'
args:
chdir: "{{ compose_file_path | dirname }}"
loop: "{{ compose_file_paths }}"
register: container_status
ignore_errors: yes
loop_control:
loop_var: compose_file_path
- name: Conditional restart of containers
ansible.builtin.command: docker compose up -d
args:
chdir: "{{ result_item.item.path | dirname }}"
loop: "{{ container_status.results }}"
when: "'false' in result_item.stdout"
register: restart_status
loop_control:
loop_var: result_item
- name: Pause for 60 seconds to allow containers to stabilize
ansible.builtin.pause:
seconds: 60
- import_playbook: docker_status.yml