mirror of
https://github.com/ansible-collections/community.docker.git
synced 2025-12-15 11:32:05 +00:00
* Add debug flag to failing task.
* Add more debug output.
* Fix pull idempotency.
* Revert "Add more debug output."
This reverts commit 64020149bf.
* Fix casing.
* Remove unreliable test.
* Add 'debug: true' to all tasks.
* Reformat.
* Fix idempotency problem for IPv6 addresses.
* Fix expose ranges handling.
* Update changelog fragment to also mention other affected modules.
425 lines
12 KiB
YAML
425 lines
12 KiB
YAML
---
|
|
# Copyright (c) Ansible Project
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
- name: Registering container name
|
|
ansible.builtin.set_fact:
|
|
cname: "{{ cname_prefix ~ '-options' }}"
|
|
cname2: "{{ cname_prefix ~ '-options-h1' }}"
|
|
- name: Registering container name
|
|
ansible.builtin.set_fact:
|
|
cnames: "{{ cnames + [cname, cname2] }}"
|
|
|
|
####################################################################
|
|
## published_ports: error handling #################################
|
|
####################################################################
|
|
|
|
- name: published_ports -- non-closing square bracket
|
|
community.docker.docker_container:
|
|
image: "{{ docker_test_image_alpine }}"
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
published_ports:
|
|
- "[::1:2000:3000"
|
|
register: published_ports_1
|
|
ignore_errors: true
|
|
|
|
- name: published_ports -- forgot square brackets for IPv6
|
|
community.docker.docker_container:
|
|
image: "{{ docker_test_image_alpine }}"
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
published_ports:
|
|
- "::1:2000:3000"
|
|
register: published_ports_2
|
|
ignore_errors: true
|
|
|
|
- name: published_ports -- disallow hostnames
|
|
community.docker.docker_container:
|
|
image: "{{ docker_test_image_alpine }}"
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
published_ports:
|
|
- "foo:2000:3000"
|
|
register: published_ports_3
|
|
ignore_errors: true
|
|
|
|
- ansible.builtin.assert:
|
|
that:
|
|
- published_ports_1 is failed
|
|
- published_ports_1.msg == 'Cannot find closing "]" in input "[::1:2000:3000" for opening "[" at index 1!'
|
|
- published_ports_2 is failed
|
|
- published_ports_2.msg == 'Invalid port description "::1:2000:3000" - expected 1 to 3 colon-separated parts, but got 5. Maybe you forgot to use square brackets ([...]) around an IPv6 address?'
|
|
- published_ports_3 is failed
|
|
- "published_ports_3.msg == 'Bind addresses for published ports must be IPv4 or IPv6 addresses, not hostnames. Use the dig lookup to resolve hostnames. (Found hostname: foo)'"
|
|
|
|
####################################################################
|
|
## published_ports: port range #####################################
|
|
####################################################################
|
|
|
|
- name: published_ports -- port range
|
|
community.docker.docker_container:
|
|
image: "{{ docker_test_image_alpine }}"
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
exposed_ports:
|
|
- "9001"
|
|
- "9010-9050"
|
|
published_ports:
|
|
- "9001:9001"
|
|
- "9010-9050:9010-9050"
|
|
force_kill: true
|
|
register: published_ports_1
|
|
|
|
- name: published_ports -- port range (idempotency)
|
|
community.docker.docker_container:
|
|
image: "{{ docker_test_image_alpine }}"
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
exposed_ports:
|
|
- "9001"
|
|
- "9010-9050"
|
|
published_ports:
|
|
- "9001:9001"
|
|
- "9010-9050:9010-9050"
|
|
force_kill: true
|
|
register: published_ports_2
|
|
|
|
- name: published_ports -- port range (different range)
|
|
community.docker.docker_container:
|
|
image: "{{ docker_test_image_alpine }}"
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
exposed_ports:
|
|
- "9001"
|
|
- "9010-9050"
|
|
published_ports:
|
|
- "9001:9001"
|
|
- "9020-9060:9020-9060"
|
|
force_kill: true
|
|
register: published_ports_3
|
|
|
|
- name: published_ports -- port range (same range, but listed explicitly)
|
|
community.docker.docker_container:
|
|
image: "{{ docker_test_image_alpine }}"
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
exposed_ports:
|
|
- "9001"
|
|
- "9010"
|
|
- "9011"
|
|
- "9012"
|
|
- "9013"
|
|
- "9014"
|
|
- "9015"
|
|
- "9016"
|
|
- "9017"
|
|
- "9018"
|
|
- "9019"
|
|
- "9020"
|
|
- "9021"
|
|
- "9022"
|
|
- "9023"
|
|
- "9024"
|
|
- "9025"
|
|
- "9026"
|
|
- "9027"
|
|
- "9028"
|
|
- "9029"
|
|
- "9030"
|
|
- "9031"
|
|
- "9032"
|
|
- "9033"
|
|
- "9034"
|
|
- "9035"
|
|
- "9036"
|
|
- "9037"
|
|
- "9038"
|
|
- "9039"
|
|
- "9040"
|
|
- "9041"
|
|
- "9042"
|
|
- "9043"
|
|
- "9044"
|
|
- "9045"
|
|
- "9046"
|
|
- "9047"
|
|
- "9048"
|
|
- "9049"
|
|
- "9050"
|
|
published_ports:
|
|
- "9001:9001"
|
|
- "9020:9020"
|
|
- "9021:9021"
|
|
- "9022:9022"
|
|
- "9023:9023"
|
|
- "9024:9024"
|
|
- "9025:9025"
|
|
- "9026:9026"
|
|
- "9027:9027"
|
|
- "9028:9028"
|
|
- "9029:9029"
|
|
- "9030:9030"
|
|
- "9031:9031"
|
|
- "9032:9032"
|
|
- "9033:9033"
|
|
- "9034:9034"
|
|
- "9035:9035"
|
|
- "9036:9036"
|
|
- "9037:9037"
|
|
- "9038:9038"
|
|
- "9039:9039"
|
|
- "9040:9040"
|
|
- "9041:9041"
|
|
- "9042:9042"
|
|
- "9043:9043"
|
|
- "9044:9044"
|
|
- "9045:9045"
|
|
- "9046:9046"
|
|
- "9047:9047"
|
|
- "9048:9048"
|
|
- "9049:9049"
|
|
- "9050:9050"
|
|
- "9051:9051"
|
|
- "9052:9052"
|
|
- "9053:9053"
|
|
- "9054:9054"
|
|
- "9055:9055"
|
|
- "9056:9056"
|
|
- "9057:9057"
|
|
- "9058:9058"
|
|
- "9059:9059"
|
|
- "9060:9060"
|
|
force_kill: true
|
|
register: published_ports_4
|
|
|
|
- name: cleanup
|
|
community.docker.docker_container:
|
|
name: "{{ cname }}"
|
|
state: absent
|
|
force_kill: true
|
|
diff: false
|
|
|
|
- ansible.builtin.assert:
|
|
that:
|
|
- published_ports_1 is changed
|
|
- published_ports_2 is not changed
|
|
- published_ports_3 is changed
|
|
- published_ports_4 is not changed
|
|
|
|
####################################################################
|
|
## published_ports: one-element container port range ###############
|
|
####################################################################
|
|
|
|
- name: published_ports -- one-element container port range
|
|
community.docker.docker_container:
|
|
image: "{{ docker_test_image_alpine }}"
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ item }}"
|
|
state: started
|
|
published_ports:
|
|
- "9010-9050:9010"
|
|
force_kill: true
|
|
loop:
|
|
- '{{ cname }}'
|
|
- '{{ cname2 }}'
|
|
register: published_ports_1
|
|
|
|
- name: published_ports -- one-element container port range (idempotency)
|
|
community.docker.docker_container:
|
|
image: "{{ docker_test_image_alpine }}"
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ item }}"
|
|
state: started
|
|
published_ports:
|
|
- "9010-9050:9010"
|
|
force_kill: true
|
|
loop:
|
|
- '{{ cname }}'
|
|
- '{{ cname2 }}'
|
|
register: published_ports_2
|
|
|
|
- name: published_ports -- one-element container port range (different range)
|
|
community.docker.docker_container:
|
|
image: "{{ docker_test_image_alpine }}"
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ item }}"
|
|
state: started
|
|
published_ports:
|
|
- "9010-9051:9010"
|
|
force_kill: true
|
|
loop:
|
|
- '{{ cname }}'
|
|
- '{{ cname2 }}'
|
|
register: published_ports_3
|
|
|
|
- name: cleanup
|
|
community.docker.docker_container:
|
|
name: "{{ item }}"
|
|
state: absent
|
|
force_kill: true
|
|
loop:
|
|
- '{{ cname }}'
|
|
- '{{ cname2 }}'
|
|
diff: false
|
|
|
|
- ansible.builtin.assert:
|
|
that:
|
|
- published_ports_1 is changed
|
|
- published_ports_2 is not changed
|
|
- published_ports_3 is changed
|
|
|
|
####################################################################
|
|
## published_ports: IPv6 addresses #################################
|
|
####################################################################
|
|
|
|
- when: docker_host_info.host_info.ServerVersion is version('27.0.0', '<')
|
|
block:
|
|
- name: published_ports -- IPv6
|
|
community.docker.docker_container:
|
|
image: "{{ docker_test_image_alpine }}"
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
published_ports:
|
|
- "[::1]:9001:9001"
|
|
force_kill: true
|
|
register: published_ports_1
|
|
|
|
- name: published_ports -- IPv6 (idempotency)
|
|
community.docker.docker_container:
|
|
image: "{{ docker_test_image_alpine }}"
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
published_ports:
|
|
- "[::1]:9001:9001"
|
|
force_kill: true
|
|
register: published_ports_2
|
|
|
|
- name: published_ports -- IPv6 (different IP)
|
|
community.docker.docker_container:
|
|
image: "{{ docker_test_image_alpine }}"
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
published_ports:
|
|
- "127.0.0.1:9001:9001"
|
|
force_kill: true
|
|
register: published_ports_3
|
|
|
|
- name: published_ports -- IPv6 (hostname)
|
|
community.docker.docker_container:
|
|
image: "{{ docker_test_image_alpine }}"
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
published_ports:
|
|
- "localhost:9001:9001"
|
|
force_kill: true
|
|
register: published_ports_4
|
|
ignore_errors: true
|
|
|
|
- name: cleanup
|
|
community.docker.docker_container:
|
|
name: "{{ cname }}"
|
|
state: absent
|
|
force_kill: true
|
|
diff: false
|
|
|
|
- ansible.builtin.assert:
|
|
that:
|
|
- published_ports_1 is changed
|
|
- published_ports_2 is not changed
|
|
- published_ports_3 is changed
|
|
- published_ports_4 is failed
|
|
|
|
####################################################################
|
|
## publish_all_ports ###############################################
|
|
####################################################################
|
|
|
|
- ansible.builtin.set_fact:
|
|
publish_all_ports_test_cases:
|
|
- test_name: no_options
|
|
changed: true
|
|
- test_name: null_to_true
|
|
publish_all_ports_value: true
|
|
changed: true
|
|
- test_name: true_idempotency
|
|
publish_all_ports_value: true
|
|
changed: false
|
|
- test_name: true_to_null
|
|
changed: false
|
|
- test_name: null_to_true_2
|
|
publish_all_ports_value: true
|
|
changed: false
|
|
- test_name: true_to_false
|
|
publish_all_ports_value: false
|
|
changed: true
|
|
- test_name: false_idempotency
|
|
publish_all_ports_value: false
|
|
changed: false
|
|
- test_name: false_to_null
|
|
changed: false
|
|
- test_name: null_with_published_ports
|
|
published_ports_value: &ports
|
|
- "9001:9001"
|
|
- "9010-9050:9010-9050"
|
|
changed: true
|
|
- test_name: null_to_true_with_published_ports
|
|
publish_all_ports_value: true
|
|
published_ports_value: *ports
|
|
changed: true
|
|
- test_name: true_idempotency_with_published_ports
|
|
publish_all_ports_value: true
|
|
published_ports_value: *ports
|
|
changed: false
|
|
- test_name: true_to_null_with_published_ports
|
|
published_ports_value: *ports
|
|
changed: false
|
|
- test_name: null_to_true_2_with_published_ports
|
|
publish_all_ports_value: true
|
|
published_ports_value: *ports
|
|
changed: false
|
|
- test_name: true_to_false_with_published_ports
|
|
publish_all_ports_value: false
|
|
published_ports_value: *ports
|
|
changed: true
|
|
- test_name: false_idempotency_with_published_ports
|
|
publish_all_ports_value: false
|
|
published_ports_value: *ports
|
|
changed: false
|
|
- test_name: false_to_null_with_published_ports
|
|
published_ports_value: *ports
|
|
changed: false
|
|
|
|
- name: publish_all_ports ({{ test_case.test_name }})
|
|
community.docker.docker_container:
|
|
image: "{{ docker_test_image_alpine }}"
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
publish_all_ports: "{{ test_case.publish_all_ports_value | default(omit) }}"
|
|
published_ports: "{{ test_case.published_ports_value | default(omit) }}"
|
|
force_kill: true
|
|
register: publish_all_ports
|
|
loop_control:
|
|
loop_var: test_case
|
|
loop: "{{ publish_all_ports_test_cases }}"
|
|
|
|
- ansible.builtin.assert:
|
|
that:
|
|
- publish_all_ports.results[index].changed == test_case.changed
|
|
loop: "{{ publish_all_ports_test_cases }}"
|
|
loop_control:
|
|
index_var: index
|
|
loop_var: test_case
|