1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/integration/targets/docker_swarm_service/tasks/tests/options.yml
Hannes Ljungberg c80ad43371 docker_swarm_service: Add working_dir option (#52425)
* Add working_dir option

* Check local mounts var to align with other checks

* Add changelog fragment

* Add trailing comma
2019-02-18 13:42:19 +00:00

2613 lines
65 KiB
YAML

---
- name: Registering container name
set_fact:
service_name: "{{ name_prefix ~ '-options' }}"
network_name_1: "{{ name_prefix ~ '-network-1' }}"
network_name_2: "{{ name_prefix ~ '-network-2' }}"
config_name_1: "{{ name_prefix ~ '-configs-1' }}"
config_name_2: "{{ name_prefix ~ '-configs-2' }}"
volume_name_1: "{{ name_prefix ~ '-volume-1' }}"
volume_name_2: "{{ name_prefix ~ '-volume-2' }}"
secret_name_1: "{{ name_prefix ~ '-secret-1' }}"
secret_name_2: "{{ name_prefix ~ '-secret-2' }}"
- name: Registering container name
set_fact:
service_names: "{{ service_names }} + [service_name]"
network_names: "{{ network_names }} + [network_name_1, network_name_2]"
config_names: "{{ config_names }} + [config_name_1, config_name_2]"
volume_names: "{{ volume_names }} + [volume_name_1, volume_name_2]"
secret_names: "{{ secret_names }} + [secret_name_1, secret_name_2]"
- docker_config:
name: "{{ config_name_1 }}"
data: "hello"
state: present
register: "config_result_1"
- docker_config:
name: "{{ config_name_2 }}"
data: "test"
state: present
register: "config_result_2"
- docker_secret:
name: "{{ secret_name_1 }}"
data: "secret1"
state: "present"
register: "secret_result_1"
- docker_secret:
name: "{{ secret_name_2 }}"
data: "secret2"
state: "present"
register: "secret_result_2"
- docker_network:
name: "{{ network_name }}"
driver: "overlay"
state: present
loop:
- "{{ network_name_1 }}"
- "{{ network_name_2 }}"
loop_control:
loop_var: network_name
- docker_volume:
name: "{{ volume_name }}"
state: present
loop:
- "{{ volume_name_1 }}"
- "{{ volume_name_2 }}"
loop_control:
loop_var: volume_name
####################################################################
## args ############################################################
####################################################################
- name: args
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
args:
- sleep
- "3600"
register: args_1
- name: args (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
args:
- sleep
- "3600"
register: args_2
- name: args (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
args:
- sleep
- "3400"
register: args_3
- name: args (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
args: []
register: args_4
- name: args (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
args: []
register: args_5
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- args_1 is changed
- args_2 is not changed
- args_3 is changed
- args_4 is changed
- args_5 is not changed
####################################################################
## configs #########################################################
####################################################################
- name: configs
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
configs:
- config_id: "{{ config_result_1.config_id }}"
config_name: "{{ config_name_1 }}"
filename: "/tmp/{{ config_name_1 }}.txt"
register: configs_1
- name: configs (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
configs:
- config_id: "{{ config_result_1.config_id }}"
config_name: "{{ config_name_1 }}"
filename: "/tmp/{{ config_name_1 }}.txt"
register: configs_2
- name: configs (add)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
configs:
- config_id: "{{ config_result_1.config_id }}"
config_name: "{{ config_name_1 }}"
filename: "/tmp/{{ config_name_1 }}.txt"
- config_id: "{{ config_result_2.config_id }}"
config_name: "{{ config_name_2 }}"
filename: "/tmp/{{ config_name_2 }}.txt"
register: configs_3
- name: configs (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
configs: []
register: configs_4
- name: configs (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
configs: []
register: configs_5
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- configs_1 is changed
- configs_2 is not changed
- configs_3 is changed
- configs_4 is changed
- configs_5 is not changed
when: docker_api_version is version('1.30', '>=')
- assert:
that:
- configs_1 is failed
- "('version is ' ~ docker_api_version ~'. Minimum version required is 1.30') in configs_1.msg"
when: docker_api_version is version('1.30', '<')
####################################################################
## constraints #####################################################
####################################################################
- name: constraints
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
constraints:
- "node.role == manager"
register: constraints_1
- name: constraints (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
constraints:
- "node.role == manager"
register: constraints_2
- name: constraints (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
constraints:
- "node.role == worker"
register: constraints_3
- name: constraints (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
constraints: []
register: constraints_4
- name: constraints (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
constraints: []
register: constraints_5
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- constraints_1 is changed
- constraints_2 is not changed
- constraints_3 is changed
- constraints_4 is changed
- constraints_5 is not changed
####################################################################
## command #########################################################
####################################################################
- name: command
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
register: command_1
- name: command (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
register: command_2
- name: command (less parameters)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
register: command_3
- name: command (as list)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command:
- "/bin/sh"
- "-c"
- "sleep 10m"
register: command_4
- name: command (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: []
register: command_5
- name: command (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: []
register: command_6
- name: command (string failure)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: yes
register: command_7
ignore_errors: yes
- name: command (list failure)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command:
- "/bin/sh"
- yes
register: command_8
ignore_errors: yes
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- command_1 is changed
- command_2 is not changed
- command_3 is changed
- command_4 is not changed
- command_5 is changed
- command_6 is not changed
- command_7 is failed
- command_8 is failed
####################################################################
## container_labels ################################################
####################################################################
- name: container_labels
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
container_labels:
test_1: "1"
test_2: "2"
register: container_labels_1
- name: container_labels (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
container_labels:
test_1: "1"
test_2: "2"
register: container_labels_2
- name: container_labels (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
container_labels:
test_1: "1"
test_2: "3"
register: container_labels_3
- name: container_labels (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
container_labels: {}
register: container_labels_4
- name: container_labels (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
container_labels: {}
register: container_labels_5
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- container_labels_1 is changed
- container_labels_2 is not changed
- container_labels_3 is changed
- container_labels_4 is changed
- container_labels_5 is not changed
####################################################################
## dns #############################################################
####################################################################
- name: dns
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns:
- 1.1.1.1
- 8.8.8.8
register: dns_1
- name: dns (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns:
- 1.1.1.1
- 8.8.8.8
register: dns_2
- name: dns_servers (changed order)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns:
- 8.8.8.8
- 1.1.1.1
register: dns_3
- name: dns_servers (changed elements)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns:
- 8.8.8.8
- 9.9.9.9
register: dns_4
- name: dns_servers (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns: []
register: dns_5
- name: dns_servers (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns: []
register: dns_6
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- dns_1 is changed
- dns_2 is not changed
- dns_3 is changed
- dns_4 is changed
- dns_5 is changed
- dns_6 is not changed
when: docker_api_version is version('1.25', '>=')
- assert:
that:
- dns_1 is failed
- "('version is ' ~ docker_api_version ~'. Minimum version required is 1.25') in dns_1.msg"
when: docker_api_version is version('1.25', '<')
####################################################################
## dns_options #####################################################
####################################################################
- name: dns_options
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns_options:
- "timeout:10"
- rotate
register: dns_options_1
ignore_errors: yes
- name: dns_options (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns_options:
- "timeout:10"
- rotate
register: dns_options_2
ignore_errors: yes
- name: dns_options (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns_options:
- "timeout:10"
- no-check-names
register: dns_options_3
ignore_errors: yes
- name: dns_options (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns_options: []
register: dns_options_4
ignore_errors: yes
- name: dns_options (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns_options: []
register: dns_options_5
ignore_errors: yes
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- dns_options_1 is changed
- dns_options_2 is not changed
- dns_options_3 is changed
- dns_options_4 is changed
- dns_options_5 is not changed
when: docker_api_version is version('1.25', '>=')
- assert:
that:
- dns_options_1 is failed
- "('version is ' ~ docker_api_version ~'. Minimum version required is 1.25') in dns_options_1.msg"
when: docker_api_version is version('1.25', '<')
####################################################################
## dns_search ######################################################
####################################################################
- name: dns_search
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns_search:
- example.com
- example.org
register: dns_search_1
- name: dns_search (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns_search:
- example.com
- example.org
register: dns_search_2
- name: dns_search (different order)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns_search:
- example.org
- example.com
register: dns_search_3
- name: dns_search (changed elements)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns_search:
- ansible.com
- example.com
register: dns_search_4
- name: dns_search (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns_search: []
register: dns_search_5
- name: dns_search (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
dns_search: []
register: dns_search_6
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- dns_search_1 is changed
- dns_search_2 is not changed
- dns_search_3 is changed
- dns_search_4 is changed
- dns_search_5 is changed
- dns_search_6 is not changed
when: docker_api_version is version('1.25', '>=')
- assert:
that:
- dns_search_1 is failed
- "('version is ' ~ docker_api_version ~'. Minimum version required is 1.25') in dns_search_1.msg"
when: docker_api_version is version('1.25', '<')
####################################################################
## endpoint_mode ###################################################
####################################################################
- name: endpoint_mode
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
endpoint_mode: "dnsrr"
register: endpoint_mode_1
- name: endpoint_mode (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
endpoint_mode: "dnsrr"
register: endpoint_mode_2
- name: endpoint_mode (changes)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
endpoint_mode: "vip"
register: endpoint_mode_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- endpoint_mode_1 is changed
- endpoint_mode_2 is not changed
- endpoint_mode_3 is changed
####################################################################
## env #############################################################
####################################################################
- name: env
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
env:
- "TEST1=val1"
- "TEST2=val2"
register: env_1
- name: env (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
env:
TEST1: val1
TEST2: val2
register: env_2
- name: env (changes)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
env:
- "TEST1=val1"
- "TEST2=val3"
register: env_3
- name: env (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
env: []
register: env_4
- name: env (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
env: []
register: env_5
- name: env (fail unwrapped values)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
env:
TEST1: true
register: env_6
ignore_errors: yes
- name: env (fail invalid formatted string)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
env:
- "TEST1=val3"
- "TEST2"
register: env_7
ignore_errors: yes
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- env_1 is changed
- env_2 is not changed
- env_3 is changed
- env_4 is changed
- env_5 is not changed
- env_6 is failed
- env_7 is failed
####################################################################
## env_files #######################################################
####################################################################
- name: env_files
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
env_files:
- "{{ role_path }}/files/env-file-1"
register: env_file_1
- name: env_files (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
env_files:
- "{{ role_path }}/files/env-file-1"
register: env_file_2
- name: env_files (more items)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
env_files:
- "{{ role_path }}/files/env-file-1"
- "{{ role_path }}/files/env-file-2"
register: env_file_3
- name: env_files (order)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
env_files:
- "{{ role_path }}/files/env-file-2"
- "{{ role_path }}/files/env-file-1"
register: env_file_4
- name: env_files (multiple idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
env_files:
- "{{ role_path }}/files/env-file-2"
- "{{ role_path }}/files/env-file-1"
register: env_file_5
- name: env_files (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
env_files: []
register: env_file_6
- name: env_files (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
env_files: []
register: env_file_7
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- env_file_1 is changed
- env_file_2 is not changed
- env_file_3 is changed
- env_file_4 is changed
- env_file_5 is not changed
- env_file_6 is changed
- env_file_7 is not changed
###################################################################
## force_update ###################################################
###################################################################
- name: force_update
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
args:
- sleep
- "3600"
force_update: yes
register: force_update_1
- name: force_update (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
args:
- sleep
- "3600"
force_update: yes
register: force_update_2
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- force_update_1 is changed
- force_update_2 is changed
when: docker_api_version is version('1.25', '>=')
- assert:
that:
- force_update_1 is failed
- "('version is ' ~ docker_api_version ~'. Minimum version required is 1.25') in force_update_1.msg"
when: docker_api_version is version('1.25', '<')
####################################################################
## groups ##########################################################
####################################################################
- name: groups
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
groups:
- 1234
- 5678
register: groups_1
- name: groups (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
groups:
- 1234
- 5678
register: groups_2
- name: groups (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
groups:
- 1234
register: groups_3
- name: groups (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
groups: []
register: groups_4
- name: groups (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
groups: []
register: groups_5
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- groups_1 is changed
- groups_2 is not changed
- groups_3 is changed
- groups_4 is changed
- groups_5 is not changed
####################################################################
## healthcheck #####################################################
####################################################################
- name: healthcheck
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
healthcheck:
test:
- CMD
- sleep
- 1
timeout: 2s
interval: 0h0m2s3ms4us
retries: 2
register: healthcheck_1
- name: healthcheck (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
healthcheck:
test:
- CMD
- sleep
- 1
timeout: 2s
interval: 0h0m2s3ms4us
retries: 2
register: healthcheck_2
- name: healthcheck (changed)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
healthcheck:
test:
- CMD
- sleep
- 1
timeout: 3s
interval: 0h1m2s3ms4us
retries: 3
register: healthcheck_3
- name: healthcheck (disabled)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
healthcheck:
test:
- NONE
register: healthcheck_4
- name: healthcheck (disabled, idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
healthcheck:
test:
- NONE
register: healthcheck_5
- name: healthcheck (string in healthcheck test, changed)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
healthcheck:
test: "sleep 1"
register: healthcheck_6
- name: healthcheck (string in healthcheck test, idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
healthcheck:
test: "sleep 1"
register: healthcheck_7
- name: healthcheck (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
labels: {}
register: healthcheck_8
- name: healthcheck (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
labels: {}
register: healthcheck_9
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- healthcheck_1 is changed
- healthcheck_2 is not changed
- healthcheck_3 is changed
- healthcheck_4 is changed
- healthcheck_5 is not changed
- healthcheck_6 is changed
- healthcheck_7 is not changed
- healthcheck_8 is changed
- healthcheck_9 is not changed
when: docker_py_version is version('2.4.0', '>=')
- assert:
that:
- healthcheck_1 is failed
- "('version is ' ~ docker_py_version ~'. Minimum version required is 2.4.0') in healthcheck_1.msg"
when: docker_py_version is version('2.4.0', '<')
###################################################################
## hostname #######################################################
###################################################################
- name: hostname
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
hostname: me.example.com
register: hostname_1
- name: hostname (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
hostname: me.example.com
register: hostname_2
- name: hostname (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
hostname: me.example.org
register: hostname_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- hostname_1 is changed
- hostname_2 is not changed
- hostname_3 is changed
when: docker_api_version is version('1.25', '>=')
- assert:
that:
- hostname_1 is failed
- "('version is ' ~ docker_api_version ~'. Minimum version required is 1.25') in hostname_1.msg"
when: docker_api_version is version('1.25', '<')
###################################################################
## image ##########################################################
###################################################################
- name: image
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
register: image_1
- name: image (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
register: image_2
- name: image (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.7
register: image_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- image_1 is changed
- image_2 is not changed
- image_3 is changed
####################################################################
## labels ##########################################################
####################################################################
- name: labels
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
labels:
test_1: "1"
test_2: "2"
register: labels_1
- name: labels (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
labels:
test_1: "1"
test_2: "2"
register: labels_2
- name: labels (changes)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
labels:
test_1: "1"
test_2: "2"
test_3: "3"
register: labels_3
- name: labels (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
labels: {}
register: labels_4
- name: labels (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
labels: {}
register: labels_5
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- labels_1 is changed
- labels_2 is not changed
- labels_3 is changed
- labels_4 is changed
- labels_5 is not changed
###################################################################
## limit_cpu ######################################################
###################################################################
- name: limit_cpu
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
limit_cpu: 1
register: limit_cpu_1
- name: limit_cpu (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
limit_cpu: 1
register: limit_cpu_2
- name: limit_cpu (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
limit_cpu: 2
register: limit_cpu_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- limit_cpu_1 is changed
- limit_cpu_2 is not changed
- limit_cpu_3 is changed
###################################################################
## limit_memory ###################################################
###################################################################
- name: limit_memory
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
limit_memory: 64000000
register: limit_memory_1
- name: limit_memory (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
limit_memory: 64000000
register: limit_memory_2
- name: limit_memory (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
limit_memory: 32000000
register: limit_memory_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- limit_memory_1 is changed
- limit_memory_2 is not changed
- limit_memory_3 is changed
####################################################################
## log_driver ######################################################
####################################################################
- name: log_driver
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
log_driver: json-file
register: log_driver_1
- name: log_driver (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
log_driver: json-file
register: log_driver_2
- name: log_driver (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
log_driver: syslog
register: log_driver_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- log_driver_1 is changed
- log_driver_2 is not changed
- log_driver_3 is changed
####################################################################
## log_driver_options ##############################################
####################################################################
- name: log_driver_options
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
log_driver: json-file
log_driver_options:
labels: production_status
env: os,customer
register: log_driver_options_1
- name: log_driver_options (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
log_driver: json-file
log_driver_options:
env: os,customer
labels: production_status
register: log_driver_options_2
- name: log_driver_options (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
log_driver: json-file
log_driver_options:
env: os,customer
labels: production_status
max-file: "1"
register: log_driver_options_3
- name: log_driver_options (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
log_driver: json-file
log_driver_options: {}
register: log_driver_options_4
- name: log_driver_options (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
log_driver: json-file
log_driver_options: {}
register: log_driver_options_5
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- log_driver_options_1 is changed
- log_driver_options_2 is not changed
- log_driver_options_3 is changed
- log_driver_options_4 is changed
- log_driver_options_5 is not changed
###################################################################
## mode ###########################################################
###################################################################
- name: mode
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
mode: "replicated"
replicas: 1
register: mode_1
- name: mode (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
mode: "replicated"
replicas: 1
register: mode_2
- name: mode (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
mode: "global"
replicas: 1
register: mode_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- mode_1 is changed
- mode_2 is not changed
- mode_3 is changed
####################################################################
## mounts ##########################################################
####################################################################
- name: mounts
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
mounts:
- source: "{{ volume_name_1 }}"
target: "/tmp/{{ volume_name_1 }}"
type: "volume"
register: mounts_1
- name: mounts (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
mounts:
- source: "{{ volume_name_1 }}"
target: "/tmp/{{ volume_name_1 }}"
type: "volume"
register: mounts_2
- name: mounts (add)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
mounts:
- source: "{{ volume_name_1 }}"
target: "/tmp/{{ volume_name_1 }}"
type: "volume"
- source: "{{ volume_name_2 }}"
target: "/tmp/{{ volume_name_2 }}"
type: "volume"
register: mounts_3
- name: mounts (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
mounts: []
register: mounts_4
- name: mounts (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
mounts: []
register: mounts_5
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- mounts_1 is changed
- mounts_2 is not changed
- mounts_3 is changed
- mounts_4 is changed
- mounts_5 is not changed
####################################################################
## networks ########################################################
####################################################################
- name: networks
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
networks:
- "{{ network_name_1 }}"
register: networks_1
- name: networks (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
networks:
- "{{ network_name_1 }}"
register: networks_2
- name: networks (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
networks: []
register: networks_3
- name: networks (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
networks: []
register: networks_4
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- networks_1 is changed
- networks_2 is not changed
- networks_3 is changed
- networks_4 is not changed
####################################################################
## stop_signal #####################################################
####################################################################
- name: stop_signal
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
stop_signal: 30
register: stop_signal_1
- name: stop_signal (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
stop_signal: 30
register: stop_signal_2
- name: stop_signal (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
stop_signal: 9
register: stop_signal_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- stop_signal_1 is changed
- stop_signal_2 is not changed
- stop_signal_3 is changed
####################################################################
## placement_preferences ###########################################
####################################################################
- name: placement_preferences
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
placement_preferences:
- spread: "node.labels.test"
register: placement_preferences_1
- name: placement_preferences (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
placement_preferences:
- spread: "node.labels.test"
register: placement_preferences_2
- name: placement_preferences (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
placement_preferences:
- spread: "node.labels.test2"
register: placement_preferences_3
- name: placement_preferences (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
placement_preferences: []
register: placement_preferences_4
- name: placement_preferences (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
placement_preferences: []
register: placement_preferences_5
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- placement_preferences_1 is changed
- placement_preferences_2 is not changed
- placement_preferences_3 is changed
- placement_preferences_4 is changed
- placement_preferences_5 is not changed
####################################################################
## publish #########################################################
####################################################################
- name: publish
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
publish:
- protocol: tcp
published_port: 60001
target_port: 60001
- protocol: udp
published_port: 60002
target_port: 60002
register: publish_1
- name: publish (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
publish:
- protocol: udp
published_port: 60002
target_port: 60002
- published_port: 60001
target_port: 60001
register: publish_2
- name: publish (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
publish:
- protocol: tcp
published_port: 60002
target_port: 60003
- protocol: udp
published_port: 60001
target_port: 60001
register: publish_3
- name: publish (mode)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
publish:
- protocol: tcp
published_port: 60002
target_port: 60003
mode: host
- protocol: udp
published_port: 60001
target_port: 60001
mode: host
register: publish_4
- name: publish (mode idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
publish:
- protocol: udp
published_port: 60001
target_port: 60001
mode: host
- protocol: tcp
published_port: 60002
target_port: 60003
mode: host
register: publish_5
- name: publish (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
publish: []
register: publish_6
- name: publish (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
publish: []
register: publish_7
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- publish_1 is changed
- publish_2 is not changed
- publish_3 is changed
- publish_4 is changed
- publish_5 is not changed
- publish_6 is changed
- publish_7 is not changed
when: docker_api_version is version('1.25', '>=')
- assert:
that:
- publish_1 is failed
- "('version is ' ~ docker_api_version ~'. Minimum version required is 1.25') in publish_1.msg"
when: docker_api_version is version('1.25', '<')
###################################################################
## replicas #######################################################
###################################################################
- name: replicas
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
replicas: 2
register: replicas_1
- name: replicas (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
replicas: 2
register: replicas_2
- name: replicas (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
replicas: 3
register: replicas_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- replicas_1 is changed
- replicas_2 is not changed
- replicas_3 is changed
###################################################################
## reserve_cpu ####################################################
###################################################################
- name: reserve_cpu
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
reserve_cpu: 1
register: reserve_cpu_1
- name: reserve_cpu (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
reserve_cpu: 1
register: reserve_cpu_2
- name: reserve_cpu (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
reserve_cpu: 2
register: reserve_cpu_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- reserve_cpu_1 is changed
- reserve_cpu_2 is not changed
- reserve_cpu_3 is changed
###################################################################
## reserve_memory #################################################
###################################################################
- name: reserve_memory
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
reserve_memory: 64000000
register: reserve_memory_1
- name: reserve_memory (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
reserve_memory: 64000000
register: reserve_memory_2
- name: reserve_memory (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
reserve_memory: 32000000
register: reserve_memory_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- reserve_memory_1 is changed
- reserve_memory_2 is not changed
- reserve_memory_3 is changed
###################################################################
# resolve_image ###################################################
###################################################################
- name: resolve_image (false)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
resolve_image: false
register: resolve_image_1
- name: resolve_image (false idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
resolve_image: false
register: resolve_image_2
- name: resolve_image (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
resolve_image: true
register: resolve_image_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- resolve_image_1 is changed
- resolve_image_2 is not changed
- resolve_image_3 is changed
###################################################################
## restart_policy #################################################
###################################################################
- name: restart_policy
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
restart_policy: "on-failure"
register: restart_policy_1
- name: restart_policy (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
restart_policy: "on-failure"
register: restart_policy_2
- name: restart_policy (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
restart_policy: "any"
register: restart_policy_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- restart_policy_1 is changed
- restart_policy_2 is not changed
- restart_policy_3 is changed
###################################################################
## restart_policy_attempts ########################################
###################################################################
- name: restart_policy_attempts
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
restart_policy_attempts: 1
register: restart_policy_attempts_1
- name: restart_policy_attempts (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
restart_policy_attempts: 1
register: restart_policy_attempts_2
- name: restart_policy_attempts (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
restart_policy_attempts: 2
register: restart_policy_attempts_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- restart_policy_attempts_1 is changed
- restart_policy_attempts_2 is not changed
- restart_policy_attempts_3 is changed
###################################################################
## restart_policy_delay ###########################################
###################################################################
- name: restart_policy_delay
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
restart_policy_delay: 5
register: restart_policy_delay_1
- name: restart_policy_delay (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
restart_policy_delay: 5
register: restart_policy_delay_2
- name: restart_policy_delay (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
restart_policy_delay: 10
register: restart_policy_delay_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- restart_policy_delay_1 is changed
- restart_policy_delay_2 is not changed
- restart_policy_delay_3 is changed
###################################################################
## restart_policy_window ##########################################
###################################################################
- name: restart_policy_window
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
restart_policy_window: 10
register: restart_policy_window_1
- name: restart_policy_window (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
restart_policy_window: 10
register: restart_policy_window_2
- name: restart_policy_window (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
restart_policy_window: 20
register: restart_policy_window_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- restart_policy_window_1 is changed
- restart_policy_window_2 is not changed
- restart_policy_window_3 is changed
####################################################################
## secrets #########################################################
####################################################################
- name: secrets
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
secrets:
- secret_id: "{{ secret_result_1.secret_id }}"
secret_name: "{{ secret_name_1 }}"
filename: "/run/secrets/{{ secret_name_1 }}.txt"
register: secrets_1
- name: secrets (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
secrets:
- secret_id: "{{ secret_result_1.secret_id }}"
secret_name: "{{ secret_name_1 }}"
filename: "/run/secrets/{{ secret_name_1 }}.txt"
register: secrets_2
- name: secrets (add)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
secrets:
- secret_id: "{{ secret_result_1.secret_id }}"
secret_name: "{{ secret_name_1 }}"
filename: "/run/secrets/{{ secret_name_1 }}.txt"
- secret_id: "{{ secret_result_2.secret_id }}"
secret_name: "{{ secret_name_2 }}"
filename: "/run/secrets/{{ secret_name_2 }}.txt"
register: secrets_3
- name: secrets (empty)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
secrets: []
register: secrets_4
- name: secrets (empty idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
secrets: []
register: secrets_5
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- secrets_1 is changed
- secrets_2 is not changed
- secrets_3 is changed
- secrets_4 is changed
- secrets_5 is not changed
when: docker_api_version is version('1.25', '>=')
- assert:
that:
- secrets_1 is failed
- "('version is ' ~ docker_api_version ~'. Minimum version required is 1.25') in secrets_1.msg"
when: docker_api_version is version('1.25', '<')
###################################################################
# tty #############################################################
###################################################################
- name: tty
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
tty: yes
register: tty_1
- name: tty (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
tty: yes
register: tty_2
- name: tty (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
tty: no
register: tty_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- tty_1 is changed
- tty_2 is not changed
- tty_3 is changed
when: docker_api_version is version('1.25', '>=')
- assert:
that:
- tty_1 is failed
- "('version is ' ~ docker_api_version ~'. Minimum version required is 1.25') in tty_1.msg"
when: docker_api_version is version('1.25', '<')
###################################################################
## update_delay ###################################################
###################################################################
- name: update_delay
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_delay: 5
register: update_delay_1
- name: update_delay (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_delay: 5
register: update_delay_2
- name: update_delay (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_delay: 12
register: update_delay_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- update_delay_1 is changed
- update_delay_2 is not changed
- update_delay_3 is changed
###################################################################
## update_failure_action ##########################################
###################################################################
- name: update_failure_action
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_failure_action: "pause"
register: update_failure_action_1
- name: update_failure_action (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_failure_action: "pause"
register: update_failure_action_2
- name: update_failure_action (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_failure_action: "continue"
register: update_failure_action_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- update_failure_action_1 is changed
- update_failure_action_2 is not changed
- update_failure_action_3 is changed
###################################################################
## update_max_failure_ratio #######################################
###################################################################
- name: update_max_failure_ratio
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_max_failure_ratio: 0.25
register: update_max_failure_ratio_1
- name: update_max_failure_ratio (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_max_failure_ratio: 0.25
register: update_max_failure_ratio_2
- name: update_max_failure_ratio (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_max_failure_ratio: 0.50
register: update_max_failure_ratio_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- update_max_failure_ratio_1 is changed
- update_max_failure_ratio_2 is not changed
- update_max_failure_ratio_3 is changed
###################################################################
# update_monitor ##################################################
###################################################################
- name: update_monitor
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_monitor: 10000000000
register: update_monitor_1
- name: update_monitor (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_monitor: 10000000000
register: update_monitor_2
- name: update_monitor (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_monitor: 6000000000
register: update_monitor_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- update_monitor_1 is changed
- update_monitor_2 is not changed
- update_monitor_3 is changed
###################################################################
# update_order ####################################################
###################################################################
- name: update_order
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_order: "start-first"
register: update_order_1
- name: update_order (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_order: "start-first"
register: update_order_2
- name: update_order (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_order: "stop-first"
register: update_order_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- update_order_1 is changed
- update_order_2 is not changed
- update_order_3 is changed
when: docker_api_version is version('1.29', '>=')
- assert:
that:
- secrets_1 is failed
- "('version is ' ~ docker_api_version ~'. Minimum version required is 1.29') in update_order_1.msg"
when: docker_api_version is version('1.29', '<')
###################################################################
## update_parallelism #############################################
###################################################################
- name: update_parallelism
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_parallelism: 2
register: update_parallelism_1
- name: update_parallelism (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_parallelism: 2
register: update_parallelism_2
- name: update_parallelism (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
update_parallelism: 1
register: update_parallelism_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- update_parallelism_1 is changed
- update_parallelism_2 is not changed
- update_parallelism_3 is changed
###################################################################
## user ###########################################################
###################################################################
- name: user
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
user: "operator"
register: user_1
- name: user (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
user: "operator"
register: user_2
- name: user (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
command: '/bin/sh -v -c "sleep 10m"'
user: "root"
register: user_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- user_1 is changed
- user_2 is not changed
- user_3 is changed
####################################################################
## working_dir #####################################################
####################################################################
- name: working_dir
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
working_dir: /tmp
register: working_dir_1
- name: working_dir (idempotency)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
working_dir: /tmp
register: working_dir_2
- name: working_dir (change)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
working_dir: /
register: working_dir_3
- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
state: absent
diff: no
- assert:
that:
- working_dir_1 is changed
- working_dir_2 is not changed
- working_dir_3 is changed
####################################################################
####################################################################
####################################################################
- name: Delete networks
docker_network:
name: "{{ network_name }}"
state: absent
force: yes
loop:
- "{{ network_name_1 }}"
- "{{ network_name_2 }}"
loop_control:
loop_var: network_name
ignore_errors: yes
- name: Delete volumes
docker_volume:
name: "{{ volume_name }}"
state: absent
loop:
- "{{ volume_name_1 }}"
- "{{ volume_name_2 }}"
loop_control:
loop_var: volume_name
ignore_errors: yes
- name: Delete configs
docker_network:
name: "{{ config_name }}"
state: absent
force: yes
loop:
- "{{ config_name_1 }}"
- "{{ config_name_2 }}"
loop_control:
loop_var: config_name
ignore_errors: yes
- name: Delete secrets
docker_network:
name: "{{ secret_name }}"
state: absent
force: yes
loop:
- "{{ secret_name_1 }}"
- "{{ secret_name_2 }}"
loop_control:
loop_var: secret_name
ignore_errors: yes