| |
| # Copyright 2017-present Open Networking Foundation |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| |
| --- |
| - hosts: {{ swarm_manager_address }} |
| become: true |
| tasks: |
| {% if delete -%} |
| |
| - name: delete swarm service '{{ swarm_service_name }}' |
| shell: docker service rm {{ swarm_service_name }} |
| - name: remove the directory {{ host_volume_path }} |
| file: |
| path={{ host_volume_path }} |
| state=absent |
| |
| {% elif update -%} |
| |
| - name: Create host volume directory to share to docker container |
| file: |
| path={{ host_volume_path }} |
| state=directory |
| - name: update swarm service '{{ swarm_service_name }}' |
| shell: docker service update --force {{ volume }} {{ swarm_service_name }} |
| - name: get status of '{{ swarm_service_name }}' service |
| shell: docker service ps {{ swarm_service_name }} |
| |
| {% else -%} |
| |
| - name: remove the directory {{ host_volume_path }} |
| file: |
| path={{ host_volume_path }} |
| state=absent |
| - name: Create host volume directory to share to docker container |
| file: |
| path={{ host_volume_path }} |
| state=directory |
| - name: start swarm service '{{ swarm_service_name }}' |
| shell: docker service create {{ network_name }} --name {{ swarm_service_name }} {{ replica }} {{ restart_condition }} {{ volume }} {{ swarm_manager_address }}:{{ docker_registry_port }}/{{ image_name }}:{{ image_tag }} |
| |
| {% endif %} |
| |
| |
| {% if not delete -%} |
| - name: inspect '{{ swarm_service_name }}' service of swarm mode |
| shell: docker service inspect {{ swarm_service_name }} |
| {% endif %} |
| |