mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
525 lines
14 KiB
YAML
525 lines
14 KiB
YAML
- name: Registering service name
|
|
set_fact:
|
|
service_name: "{{ name_prefix ~ '-mounts' }}"
|
|
volume_name_1: "{{ name_prefix ~ '-volume-1' }}"
|
|
volume_name_2: "{{ name_prefix ~ '-volume-2' }}"
|
|
|
|
- name: Registering service name
|
|
set_fact:
|
|
service_names: "{{ service_names + [service_name] }}"
|
|
volume_names: "{{ volume_names + [volume_name_1, volume_name_2] }}"
|
|
|
|
- docker_volume:
|
|
name: "{{ volume_name }}"
|
|
state: present
|
|
loop:
|
|
- "{{ volume_name_1 }}"
|
|
- "{{ volume_name_2 }}"
|
|
loop_control:
|
|
loop_var: volume_name
|
|
|
|
####################################################################
|
|
## mounts ##########################################################
|
|
####################################################################
|
|
|
|
- name: mounts
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
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
|
|
resolve_image: no
|
|
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
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "volume"
|
|
- source: "/tmp/"
|
|
target: "/tmp/{{ volume_name_2 }}"
|
|
type: "bind"
|
|
register: mounts_3
|
|
|
|
- name: mounts (empty)
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
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
|
|
resolve_image: no
|
|
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
|
|
|
|
####################################################################
|
|
## mounts.readonly #################################################
|
|
####################################################################
|
|
|
|
- name: mounts.readonly
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
readonly: true
|
|
register: mounts_readonly_1
|
|
|
|
|
|
- name: mounts.readonly (idempotency)
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
readonly: true
|
|
register: mounts_readonly_2
|
|
|
|
- name: mounts.readonly (change)
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
readonly: false
|
|
register: mounts_readonly_3
|
|
|
|
- name: cleanup
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
state: absent
|
|
diff: no
|
|
|
|
- assert:
|
|
that:
|
|
- mounts_readonly_1 is changed
|
|
- mounts_readonly_2 is not changed
|
|
- mounts_readonly_3 is changed
|
|
|
|
####################################################################
|
|
## mounts.propagation ##############################################
|
|
####################################################################
|
|
|
|
- name: mounts.propagation
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "/tmp"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "bind"
|
|
propagation: "slave"
|
|
register: mounts_propagation_1
|
|
|
|
|
|
- name: mounts.propagation (idempotency)
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "/tmp"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "bind"
|
|
propagation: "slave"
|
|
register: mounts_propagation_2
|
|
|
|
- name: mounts.propagation (change)
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "/tmp"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "bind"
|
|
propagation: "rprivate"
|
|
register: mounts_propagation_3
|
|
|
|
- name: cleanup
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
state: absent
|
|
diff: no
|
|
|
|
- assert:
|
|
that:
|
|
- mounts_propagation_1 is changed
|
|
- mounts_propagation_2 is not changed
|
|
- mounts_propagation_3 is changed
|
|
|
|
####################################################################
|
|
## mounts.labels ##################################################
|
|
####################################################################
|
|
|
|
- name: mounts.labels
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "volume"
|
|
labels:
|
|
mylabel: hello-world
|
|
my-other-label: hello-mars
|
|
register: mounts_labels_1
|
|
|
|
|
|
- name: mounts.labels (idempotency)
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "volume"
|
|
labels:
|
|
mylabel: hello-world
|
|
my-other-label: hello-mars
|
|
register: mounts_labels_2
|
|
|
|
- name: mounts.labels (change)
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "volume"
|
|
labels:
|
|
mylabel: hello-world
|
|
register: mounts_labels_3
|
|
|
|
- name: cleanup
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
state: absent
|
|
diff: no
|
|
|
|
- assert:
|
|
that:
|
|
- mounts_labels_1 is changed
|
|
- mounts_labels_2 is not changed
|
|
- mounts_labels_3 is changed
|
|
|
|
####################################################################
|
|
## mounts.no_copy ##################################################
|
|
####################################################################
|
|
|
|
- name: mounts.no_copy
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "volume"
|
|
no_copy: true
|
|
register: mounts_no_copy_1
|
|
|
|
|
|
- name: mounts.no_copy (idempotency)
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "volume"
|
|
no_copy: true
|
|
register: mounts_no_copy_2
|
|
|
|
- name: mounts.no_copy (change)
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "volume"
|
|
no_copy: false
|
|
register: mounts_no_copy_3
|
|
|
|
- name: cleanup
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
state: absent
|
|
diff: no
|
|
|
|
- assert:
|
|
that:
|
|
- mounts_no_copy_1 is changed
|
|
- mounts_no_copy_2 is not changed
|
|
- mounts_no_copy_3 is changed
|
|
|
|
####################################################################
|
|
## mounts.driver_config ############################################
|
|
####################################################################
|
|
|
|
- name: mounts.driver_config
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "volume"
|
|
driver_config:
|
|
name: "nfs"
|
|
options:
|
|
addr: "127.0.0.1"
|
|
register: mounts_driver_config_1
|
|
|
|
- name: mounts.driver_config
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "volume"
|
|
driver_config:
|
|
name: "nfs"
|
|
options:
|
|
addr: "127.0.0.1"
|
|
register: mounts_driver_config_2
|
|
|
|
- name: mounts.driver_config
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "volume"
|
|
driver_config:
|
|
name: "local"
|
|
register: mounts_driver_config_3
|
|
|
|
- name: cleanup
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
state: absent
|
|
diff: no
|
|
|
|
- assert:
|
|
that:
|
|
- mounts_driver_config_1 is changed
|
|
- mounts_driver_config_2 is not changed
|
|
- mounts_driver_config_3 is changed
|
|
|
|
####################################################################
|
|
## mounts.tmpfs_size ###############################################
|
|
####################################################################
|
|
|
|
- name: mounts.tmpfs_size
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "tmpfs"
|
|
tmpfs_size: "50M"
|
|
register: mounts_tmpfs_size_1
|
|
ignore_errors: yes
|
|
|
|
- name: mounts.tmpfs_size (idempotency)
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "tmpfs"
|
|
tmpfs_size: "50M"
|
|
register: mounts_tmpfs_size_2
|
|
ignore_errors: yes
|
|
|
|
- name: mounts.tmpfs_size (change)
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "tmpfs"
|
|
tmpfs_size: "25M"
|
|
register: mounts_tmpfs_size_3
|
|
ignore_errors: yes
|
|
|
|
- name: cleanup
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
state: absent
|
|
diff: no
|
|
|
|
- assert:
|
|
that:
|
|
- mounts_tmpfs_size_1 is changed
|
|
- mounts_tmpfs_size_2 is not changed
|
|
- mounts_tmpfs_size_3 is changed
|
|
when: docker_py_version is version('2.6.0', '>=')
|
|
- assert:
|
|
that:
|
|
- mounts_tmpfs_size_1 is failed
|
|
- "'Minimum version required' in mounts_tmpfs_size_1.msg"
|
|
when: docker_py_version is version('2.6.0', '<')
|
|
|
|
####################################################################
|
|
## mounts.tmpfs_mode ###############################################
|
|
####################################################################
|
|
|
|
- name: mounts.tmpfs_mode
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "tmpfs"
|
|
tmpfs_mode: 0444
|
|
register: mounts_tmpfs_mode_1
|
|
ignore_errors: yes
|
|
|
|
- name: mounts.tmpfs_mode (idempotency)
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "tmpfs"
|
|
tmpfs_mode: 0444
|
|
register: mounts_tmpfs_mode_2
|
|
ignore_errors: yes
|
|
|
|
- name: mounts.tmpfs_mode (change)
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
image: alpine:3.8
|
|
resolve_image: no
|
|
command: '/bin/sh -v -c "sleep 10m"'
|
|
mounts:
|
|
- source: "{{ volume_name_1 }}"
|
|
target: "/tmp/{{ volume_name_1 }}"
|
|
type: "tmpfs"
|
|
tmpfs_mode: 0777
|
|
register: mounts_tmpfs_mode_3
|
|
ignore_errors: yes
|
|
|
|
- name: cleanup
|
|
docker_swarm_service:
|
|
name: "{{ service_name }}"
|
|
state: absent
|
|
diff: no
|
|
|
|
- assert:
|
|
that:
|
|
- mounts_tmpfs_mode_1 is changed
|
|
- mounts_tmpfs_mode_2 is not changed
|
|
- mounts_tmpfs_mode_3 is changed
|
|
when: docker_py_version is version('2.6.0', '>=')
|
|
- assert:
|
|
that:
|
|
- mounts_tmpfs_size_1 is failed
|
|
- "'Minimum version required' in mounts_tmpfs_size_1.msg"
|
|
when: docker_py_version is version('2.6.0', '<')
|
|
|
|
####################################################################
|
|
####################################################################
|
|
####################################################################
|
|
|
|
- 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
|