From 4e1f6683d9948d9cac51215667d0ff43657ca3c0 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 28 Sep 2020 20:40:57 +0200 Subject: [PATCH] docker_container: fix idempotency problem with empty published_ports list (#979) * Distinguish between [] and None. * Add changelog fragment. * Fix typo. --- ..._container-published_ports-empty-idempotency.yml | 2 ++ plugins/modules/cloud/docker/docker_container.py | 2 +- .../docker_container/tasks/tests/options.yml | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/979-docker_container-published_ports-empty-idempotency.yml diff --git a/changelogs/fragments/979-docker_container-published_ports-empty-idempotency.yml b/changelogs/fragments/979-docker_container-published_ports-empty-idempotency.yml new file mode 100644 index 0000000000..5df2f7ca12 --- /dev/null +++ b/changelogs/fragments/979-docker_container-published_ports-empty-idempotency.yml @@ -0,0 +1,2 @@ +bugfixes: +- "docker_container - fix idempotency problem with ``published_ports`` when strict comparison is used and list is empty (https://github.com/ansible-collections/community.general/issues/978)." diff --git a/plugins/modules/cloud/docker/docker_container.py b/plugins/modules/cloud/docker/docker_container.py index e28bd5747d..cfc893cdf7 100644 --- a/plugins/modules/cloud/docker/docker_container.py +++ b/plugins/modules/cloud/docker/docker_container.py @@ -2400,7 +2400,7 @@ class Container(DockerBaseClass): return shlex.split(self.parameters.entrypoint) def _get_expected_ports(self): - if not self.parameters.published_ports: + if self.parameters.published_ports is None: return None expected_bound_ports = {} for container_port, config in self.parameters.published_ports.items(): diff --git a/tests/integration/targets/docker_container/tasks/tests/options.yml b/tests/integration/targets/docker_container/tasks/tests/options.yml index 5cced99584..9958f08fa3 100644 --- a/tests/integration/targets/docker_container/tasks/tests/options.yml +++ b/tests/integration/targets/docker_container/tasks/tests/options.yml @@ -2873,6 +2873,18 @@ avoid such warnings, please quote the value.' in log_options_2.warnings" force_kill: yes register: published_ports_5 +- name: published_ports (no published ports) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + published_ports: [] + comparisons: + published_ports: strict + force_kill: yes + register: published_ports_6 + - name: cleanup docker_container: name: "{{ cname }}" @@ -2887,6 +2899,7 @@ 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 #################################################################### ## pull ############################################################