boyoung | f42f2bf | 2017-10-16 19:06:30 +0900 | [diff] [blame^] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
boyoung | 24b12a6 | 2017-10-12 10:32:44 +0900 | [diff] [blame] | 17 | --- |
| 18 | - hosts: {{ swarm_manager_address }} |
| 19 | become: true |
| 20 | tasks: |
| 21 | {% if delete -%} |
| 22 | |
| 23 | - name: delete swarm service '{{ swarm_service_name }}' |
| 24 | shell: docker service rm {{ swarm_service_name }} |
| 25 | - name: remove the directory {{ host_volume_path }} |
| 26 | file: |
| 27 | path={{ host_volume_path }} |
| 28 | state=absent |
| 29 | |
| 30 | {% elif update -%} |
| 31 | |
| 32 | - name: Create host volume directory to share to docker container |
| 33 | file: |
| 34 | path={{ host_volume_path }} |
| 35 | state=directory |
| 36 | - name: update swarm service '{{ swarm_service_name }}' |
| 37 | shell: docker service update --force {{ volume }} {{ swarm_service_name }} |
| 38 | - name: get status of '{{ swarm_service_name }}' service |
| 39 | shell: docker service ps {{ swarm_service_name }} |
| 40 | |
| 41 | {% else -%} |
| 42 | |
| 43 | - name: remove the directory {{ host_volume_path }} |
| 44 | file: |
| 45 | path={{ host_volume_path }} |
| 46 | state=absent |
| 47 | - name: Create host volume directory to share to docker container |
| 48 | file: |
| 49 | path={{ host_volume_path }} |
| 50 | state=directory |
| 51 | - name: start swarm service '{{ swarm_service_name }}' |
| 52 | shell: docker service create {{ network_name }} --name {{ swarm_service_name }} {{ replica }} {{ restart_condition }} {{ volume }} {{ swarm_manager_address }}:{{ docker_registry_port }}/{{ image_name }}:{{ image_tag }} |
| 53 | |
| 54 | {% endif %} |
| 55 | |
| 56 | |
| 57 | {% if not delete -%} |
| 58 | - name: inspect '{{ swarm_service_name }}' service of swarm mode |
| 59 | shell: docker service inspect {{ swarm_service_name }} |
| 60 | {% endif %} |
| 61 | |