boyoung | 24b12a6 | 2017-10-12 10:32:44 +0900 | [diff] [blame^] | 1 | --- |
| 2 | - hosts: {{ swarm_manager_address }} |
| 3 | become: true |
| 4 | tasks: |
| 5 | {% if delete -%} |
| 6 | |
| 7 | - name: delete swarm service '{{ swarm_service_name }}' |
| 8 | shell: docker service rm {{ swarm_service_name }} |
| 9 | - name: remove the directory {{ host_volume_path }} |
| 10 | file: |
| 11 | path={{ host_volume_path }} |
| 12 | state=absent |
| 13 | |
| 14 | {% elif update -%} |
| 15 | |
| 16 | - name: Create host volume directory to share to docker container |
| 17 | file: |
| 18 | path={{ host_volume_path }} |
| 19 | state=directory |
| 20 | - name: update swarm service '{{ swarm_service_name }}' |
| 21 | shell: docker service update --force {{ volume }} {{ swarm_service_name }} |
| 22 | - name: get status of '{{ swarm_service_name }}' service |
| 23 | shell: docker service ps {{ swarm_service_name }} |
| 24 | |
| 25 | {% else -%} |
| 26 | |
| 27 | - name: remove the directory {{ host_volume_path }} |
| 28 | file: |
| 29 | path={{ host_volume_path }} |
| 30 | state=absent |
| 31 | - name: Create host volume directory to share to docker container |
| 32 | file: |
| 33 | path={{ host_volume_path }} |
| 34 | state=directory |
| 35 | - name: start swarm service '{{ swarm_service_name }}' |
| 36 | shell: docker service create {{ network_name }} --name {{ swarm_service_name }} {{ replica }} {{ restart_condition }} {{ volume }} {{ swarm_manager_address }}:{{ docker_registry_port }}/{{ image_name }}:{{ image_tag }} |
| 37 | |
| 38 | {% endif %} |
| 39 | |
| 40 | |
| 41 | {% if not delete -%} |
| 42 | - name: inspect '{{ swarm_service_name }}' service of swarm mode |
| 43 | shell: docker service inspect {{ swarm_service_name }} |
| 44 | {% endif %} |
| 45 | |