2019-01-16 09:50:06 +01:00
|
|
|
---
|
2019-03-06 21:50:05 +01:00
|
|
|
- block:
|
|
|
|
- name: Create a swarm service without name
|
|
|
|
register: output
|
|
|
|
docker_swarm_service:
|
|
|
|
state: present
|
|
|
|
ignore_errors: yes
|
2019-01-16 09:50:06 +01:00
|
|
|
|
2019-03-06 21:50:05 +01:00
|
|
|
- name: assert failure when name not set
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output is failed
|
|
|
|
- 'output.msg == "missing required arguments: name"'
|
2019-01-16 09:50:06 +01:00
|
|
|
|
2019-03-06 21:50:05 +01:00
|
|
|
- name: Remove an non-existing service
|
|
|
|
register: output
|
|
|
|
docker_swarm_service:
|
|
|
|
state: absent
|
|
|
|
name: non_existing_service
|
2019-01-16 09:50:06 +01:00
|
|
|
|
2019-03-06 21:50:05 +01:00
|
|
|
- name: assert output not changed when deleting non-existing service
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output is not changed
|
2019-01-16 09:50:06 +01:00
|
|
|
|
2019-03-06 21:50:05 +01:00
|
|
|
- name: create sample service
|
|
|
|
register: output
|
|
|
|
docker_swarm_service:
|
|
|
|
name: test_service
|
|
|
|
endpoint_mode: dnsrr
|
|
|
|
image: busybox
|
2019-03-06 23:01:00 +01:00
|
|
|
resolve_image: no
|
2019-03-06 21:50:05 +01:00
|
|
|
args:
|
|
|
|
- sleep
|
|
|
|
- "3600"
|
2019-01-16 09:50:06 +01:00
|
|
|
|
2019-03-06 21:50:05 +01:00
|
|
|
- name: assert sample service is created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output is changed
|
2019-01-16 09:50:06 +01:00
|
|
|
|
2019-03-06 21:50:05 +01:00
|
|
|
- name: change service args
|
|
|
|
register: output
|
|
|
|
docker_swarm_service:
|
|
|
|
name: test_service
|
|
|
|
image: busybox
|
2019-03-06 23:01:00 +01:00
|
|
|
resolve_image: no
|
2019-03-06 21:50:05 +01:00
|
|
|
args:
|
|
|
|
- sleep
|
|
|
|
- "1800"
|
2019-01-16 09:50:06 +01:00
|
|
|
|
2019-03-06 21:50:05 +01:00
|
|
|
- name: assert service args are correct
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.swarm_service.args == ['sleep', '1800']
|
2019-01-16 09:50:06 +01:00
|
|
|
|
2019-03-06 21:50:05 +01:00
|
|
|
- name: set service mode to global
|
|
|
|
register: output
|
|
|
|
docker_swarm_service:
|
|
|
|
name: test_service
|
|
|
|
image: busybox
|
2019-03-06 23:01:00 +01:00
|
|
|
resolve_image: no
|
2019-03-06 21:50:05 +01:00
|
|
|
endpoint_mode: vip
|
|
|
|
mode: global
|
|
|
|
args:
|
|
|
|
- sleep
|
|
|
|
- "1800"
|
2019-01-16 09:50:06 +01:00
|
|
|
|
2019-03-06 21:50:05 +01:00
|
|
|
- name: assert service mode changed caused service rebuild
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.rebuilt
|
2019-01-16 09:50:06 +01:00
|
|
|
|
2019-03-06 21:50:05 +01:00
|
|
|
- name: add published ports to service
|
|
|
|
register: output
|
|
|
|
docker_swarm_service:
|
|
|
|
name: test_service
|
|
|
|
image: busybox
|
2019-03-06 23:01:00 +01:00
|
|
|
resolve_image: no
|
2019-03-06 21:50:05 +01:00
|
|
|
mode: global
|
|
|
|
args:
|
|
|
|
- sleep
|
|
|
|
- "1800"
|
|
|
|
endpoint_mode: vip
|
|
|
|
publish:
|
|
|
|
- protocol: tcp
|
|
|
|
published_port: 60001
|
|
|
|
target_port: 60001
|
|
|
|
- protocol: udp
|
|
|
|
published_port: 60001
|
|
|
|
target_port: 60001
|
2019-01-16 09:50:06 +01:00
|
|
|
|
2019-03-06 21:50:05 +01:00
|
|
|
- name: fake image key as it is not predictable
|
|
|
|
set_fact:
|
|
|
|
ansible_docker_service_output: "{{ output.swarm_service|combine({'image': 'busybox'}) }}"
|
2019-01-16 09:50:06 +01:00
|
|
|
|
2019-03-06 21:50:05 +01:00
|
|
|
- name: assert service matches expectations
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- ansible_docker_service_output == service_expected_output
|
2019-01-27 17:48:16 +01:00
|
|
|
|
2019-03-06 21:50:05 +01:00
|
|
|
- name: delete sample service
|
|
|
|
register: output
|
|
|
|
docker_swarm_service:
|
|
|
|
name: test_service
|
|
|
|
state: absent
|
2019-01-16 09:50:06 +01:00
|
|
|
|
2019-03-06 21:50:05 +01:00
|
|
|
- name: assert service deletion returns changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output is success
|
|
|
|
- output is changed
|
|
|
|
when: docker_api_version is version('1.24', '>=') and docker_py_version is version('3.0.0', '>=')
|