docker_container: fix port bindings with IPv6 addresses (#59715)

* Pass IPv6 addresses for port bindings without square brackets.

* Add changelog.

* Add test.
pull/59999/head
Felix Fontein 5 years ago committed by GitHub
parent f94772f807
commit a7573102bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- "docker_container - fix port bindings with IPv6 addresses."

@ -1453,13 +1453,16 @@ class TaskParameters(DockerBaseClass):
port_binds = [(default_ip, port) for port in parse_port_range(parts[0], self.client)] port_binds = [(default_ip, port) for port in parse_port_range(parts[0], self.client)]
elif p_len == 3: elif p_len == 3:
# We only allow IPv4 and IPv6 addresses for the bind address # We only allow IPv4 and IPv6 addresses for the bind address
if not re.match(r'^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$', parts[0]) and not re.match(r'^\[[0-9a-fA-F:]+\]$', parts[0]): 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):
self.fail(('Bind addresses for published ports must be IPv4 or IPv6 addresses, not hostnames. ' 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(parts[0])) 'Use the dig lookup to resolve hostnames. (Found hostname: {0})').format(ipaddr))
if re.match(r'^\[[0-9a-fA-F:]+\]$', ipaddr):
ipaddr = ipaddr[1:-1]
if parts[1]: if parts[1]:
port_binds = [(parts[0], port) for port in parse_port_range(parts[1], self.client)] port_binds = [(ipaddr, port) for port in parse_port_range(parts[1], self.client)]
else: else:
port_binds = len(container_ports) * [(parts[0],)] port_binds = len(container_ports) * [(ipaddr,)]
for bind, container_port in zip(port_binds, container_ports): for bind, container_port in zip(port_binds, container_ports):
idx = '{0}/{1}'.format(container_port, protocol) if protocol else container_port idx = '{0}/{1}'.format(container_port, protocol) if protocol else container_port

@ -2804,6 +2804,18 @@ avoid such warnings, please quote the value.' in log_options_2.warnings"
force_kill: yes force_kill: yes
register: published_ports_4 register: published_ports_4
- name: published_ports (ports with IP addresses)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
published_ports:
- '127.0.0.1:9002:9002/tcp'
- '[::1]:9003:9003/tcp'
force_kill: yes
register: published_ports_5
- name: cleanup - name: cleanup
docker_container: docker_container:
name: "{{ cname }}" name: "{{ cname }}"
@ -2817,6 +2829,7 @@ avoid such warnings, please quote the value.' in log_options_2.warnings"
- published_ports_2 is not changed - published_ports_2 is not changed
- published_ports_3 is not changed - published_ports_3 is not changed
- published_ports_4 is changed - published_ports_4 is changed
- published_ports_5 is changed
#################################################################### ####################################################################
## pull ############################################################ ## pull ############################################################

Loading…
Cancel
Save