From 05c6df53f0f4afb9da21c8e570654cb09d427164 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 8 Oct 2018 09:23:23 +0200 Subject: [PATCH] docker_container: improve publish all ports functionality (#46594) * Improve handling of published_ports: all. * Add changelog. (cherry picked from commit 8afe46dc02b35d55d0df5dac65249561ee454df0) --- .../fragments/46594-docker_container-publish-all-ports.yml | 2 ++ lib/ansible/modules/cloud/docker/docker_container.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/46594-docker_container-publish-all-ports.yml diff --git a/changelogs/fragments/46594-docker_container-publish-all-ports.yml b/changelogs/fragments/46594-docker_container-publish-all-ports.yml new file mode 100644 index 00000000000..6b9ff8d7150 --- /dev/null +++ b/changelogs/fragments/46594-docker_container-publish-all-ports.yml @@ -0,0 +1,2 @@ +bugfixes: +- "docker_container - ``publish_ports: all`` was not used correctly when checking idempotency." diff --git a/lib/ansible/modules/cloud/docker/docker_container.py b/lib/ansible/modules/cloud/docker/docker_container.py index dc39027d52f..358195c868d 100644 --- a/lib/ansible/modules/cloud/docker/docker_container.py +++ b/lib/ansible/modules/cloud/docker/docker_container.py @@ -267,7 +267,7 @@ options: - "Use docker CLI syntax: C(8000), C(9000:8000), or C(0.0.0.0:9000:8000), where 8000 is a container port, 9000 is a host port, and 0.0.0.0 is a host interface." - Container ports must be exposed either in the Dockerfile or via the C(expose) option. - - A value of all will publish all exposed container ports to random host ports, ignoring + - A value of C(all) will publish all exposed container ports to random host ports, ignoring any other mappings. - If C(networks) parameter is provided, will inspect each network to see if there exists a bridge network with optional parameter com.docker.network.bridge.host_binding_ipv4. @@ -1408,7 +1408,8 @@ class Container(DockerBaseClass): expected_volumes=config.get('Volumes'), expected_binds=host_config.get('Binds'), volumes_from=host_config.get('VolumesFrom'), - working_dir=config.get('WorkingDir') + working_dir=config.get('WorkingDir'), + publish_all_ports=host_config.get('PublishAllPorts'), ) if self.parameters.restart_policy: config_mapping['restart_retries'] = restart_policy.get('MaximumRetryCount') @@ -2127,6 +2128,8 @@ class AnsibleDockerClientContainer(AnsibleDockerClient): # Process legacy ignore options if self.module.params['ignore_image']: comparisons['image']['comparison'] = 'ignore' + # Add implicit options + comparisons['publish_all_ports'] = dict(type='value', comparison='strict', name='published_ports') self.comparisons = comparisons def __init__(self, **kwargs):