diff --git a/changelogs/fragments/community.docker-66-ipv6-zones.yml b/changelogs/fragments/community.docker-66-ipv6-zones.yml new file mode 100644 index 0000000000..09970451f5 --- /dev/null +++ b/changelogs/fragments/community.docker-66-ipv6-zones.yml @@ -0,0 +1,2 @@ +bugfixes: +- "docker_container - allow IPv6 zones (RFC 4007) in bind IPs (https://github.com/ansible-collections/community.docker/pull/66)." diff --git a/plugins/modules/cloud/docker/docker_container.py b/plugins/modules/cloud/docker/docker_container.py index 557319c24c..30033ebf67 100644 --- a/plugins/modules/cloud/docker/docker_container.py +++ b/plugins/modules/cloud/docker/docker_container.py @@ -1721,7 +1721,7 @@ class TaskParameters(DockerBaseClass): elif p_len == 3: # We only allow IPv4 and IPv6 addresses for the bind address ipaddr = parts[0] - if not re.match(r'^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$', parts[0]) and not re.match(r'^\[[0-9a-fA-F:]+\]$', ipaddr): + if not re.match(r'^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$', parts[0]) and not re.match(r'^\[[0-9a-fA-F:]+(?:|%[^\]/]+)\]$', ipaddr): self.fail(('Bind addresses for published ports must be IPv4 or IPv6 addresses, not hostnames. ' 'Use the dig lookup to resolve hostnames. (Found hostname: {0})').format(ipaddr)) if re.match(r'^\[[0-9a-fA-F:]+\]$', ipaddr): diff --git a/tests/integration/targets/docker_container/tasks/tests/options.yml b/tests/integration/targets/docker_container/tasks/tests/options.yml index 79c329143e..ae46827315 100644 --- a/tests/integration/targets/docker_container/tasks/tests/options.yml +++ b/tests/integration/targets/docker_container/tasks/tests/options.yml @@ -2914,9 +2914,22 @@ avoid such warnings, please quote the value.' in log_options_2.warnings" published_ports: - '127.0.0.1:9002:9002/tcp' - '[::1]:9003:9003/tcp' + - '[fe80::1%test]:90:90/tcp' force_kill: yes register: published_ports_5 +- name: published_ports (ports with IP addresses, idempotent) + docker_container: + image: "{{ docker_test_image_alpine }}" + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + published_ports: + - '127.0.0.1:9002:9002/tcp' + - '[::1]:9003:9003/tcp' + - '[fe80::1%test]:90:90/tcp' + register: published_ports_6 + - name: published_ports (no published ports) docker_container: image: "{{ docker_test_image_alpine }}" @@ -2927,7 +2940,7 @@ avoid such warnings, please quote the value.' in log_options_2.warnings" comparisons: published_ports: strict force_kill: yes - register: published_ports_6 + register: published_ports_7 - name: cleanup docker_container: @@ -2943,7 +2956,8 @@ avoid such warnings, please quote the value.' in log_options_2.warnings" - published_ports_3 is not changed - published_ports_4 is changed - published_ports_5 is changed - - published_ports_6 is changed + - published_ports_6 is not changed + - published_ports_7 is changed #################################################################### ## pull ############################################################