Last active
November 15, 2019 13:17
-
-
Save radimih/7ae1dcd1a80d83f12f8cbc2a6ffd5923 to your computer and use it in GitHub Desktop.
Проверить статус обновления Docker Swarm-сервиса
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# ВНИМАНИЕ! При создании сервиса, к сожалению, невозможно по выдаче команды | |
# docker service inspect определить успешность запуска реплик сервиса - | |
# секция UpdateStatus отсутсвует, а по другим параметрам все ок. | |
# Соответственно, этот плейбук бесполезен при создании сервиса. | |
- name: "Swarm service '{{ service }}': get status" | |
docker_swarm_service_info: | |
name: "{{ service }}" | |
register: service_info | |
- name: "Swarm service '{{ service }}': verify that service exists" | |
fail: | |
msg: "Swarm service '{{ service }}' does not exist" | |
when: service_info.service is none | |
- name: "Swarm service '{{ service }}': check success of update" | |
block: | |
- name: "Swarm service '{{ service }}': wait for updating" | |
docker_swarm_service_info: | |
name: "{{ service }}" | |
register: service_info | |
until: service_info.service.UpdateStatus.State != "updating" | |
delay: 10 | |
retries: 30 | |
- name: "Swarm service '{{ service }}': to fail if failed to update" | |
fail: | |
msg: >- | |
From docker service inspect: | |
update status='{{ service_info.service.UpdateStatus.State }}', | |
message='{{ service_info.service.UpdateStatus.Message }}' | |
when: | |
- service_info.service.UpdateStatus.State != "completed" | |
# Выполнять блок только если сервис обновляется. | |
# При создании сервиса или если сервис фактически не обновляется | |
# (образ не изменился) в выдаче команды docker service inspect | |
# отсутсвует секция UpdateStatus, поэтому невозможно отследить | |
# процесс обновления сервиса | |
when: service_info.service.UpdateStatus is defined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: "Docker Swarm" | |
hosts: localhost | |
tasks: | |
- name: "Run/Update and check docker swarm service" | |
block: | |
- name: "Run/update Docker Swarm service (async action)" | |
docker_swarm_service: | |
name: "{{ service_name }}" | |
image: test:ok | |
replicas: 1 | |
- name: "Check success of Swarm service update" | |
import_tasks: check-swarm-service.yml | |
vars: | |
service: "{{ service_name }}" | |
vars: | |
service_name: test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment