diff options
author | Felix Fontein <felix@fontein.de> | 2021-03-08 10:07:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-08 03:07:46 -0600 |
commit | 68f32e43c1bdbfd4bec2d6923ca9b1c5a0d5ffd3 (patch) | |
tree | b9e7501ead660c42a0747d06a84102a0f539e695 | |
parent | 5855df4f0fff8030df34930c55c1023f54ab037b (diff) | |
download | ansible-68f32e43c1bdbfd4bec2d6923ca9b1c5a0d5ffd3.tar.gz |
Backport of https://github.com/ansible-collections/community.docker/pull/88 to stable-1. (#73816)
3 files changed, 28 insertions, 4 deletions
diff --git a/changelogs/fragments/community.docker-88-docker_container-healthcheck.yml b/changelogs/fragments/community.docker-88-docker_container-healthcheck.yml new file mode 100644 index 0000000000..949d0875b5 --- /dev/null +++ b/changelogs/fragments/community.docker-88-docker_container-healthcheck.yml @@ -0,0 +1,2 @@ +bugfixes: +- "docker_container - fix healthcheck disabling idempotency issue with strict comparison (https://github.com/ansible-collections/community.docker/issues/85)." diff --git a/lib/ansible/modules/cloud/docker/docker_container.py b/lib/ansible/modules/cloud/docker/docker_container.py index a9e8f17093..9255f7e20f 100644 --- a/lib/ansible/modules/cloud/docker/docker_container.py +++ b/lib/ansible/modules/cloud/docker/docker_container.py @@ -2168,6 +2168,12 @@ class Container(DockerBaseClass): match = self._compare(getattr(self.parameters, key), value, compare) if not match: + if key == 'expected_healthcheck' and config_mapping['disable_healthcheck'] and self.parameters.disable_healthcheck: + # If the healthcheck is disabled (both in parameters and for the current container), and the user + # requested strict comparison for healthcheck, the comparison will fail. That's why we ignore the + # expected_healthcheck comparison in this case. + continue + # no match. record the differences p = getattr(self.parameters, key) c = value diff --git a/test/integration/targets/docker_container/tasks/tests/options.yml b/test/integration/targets/docker_container/tasks/tests/options.yml index 8fe47cf557..d58e17f73f 100644 --- a/test/integration/targets/docker_container/tasks/tests/options.yml +++ b/test/integration/targets/docker_container/tasks/tests/options.yml @@ -1562,6 +1562,21 @@ register: healthcheck_6 ignore_errors: yes +- name: healthcheck (disabled, idempotency, strict) + docker_container: + image: "{{ docker_test_image_alpine }}" + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + healthcheck: + test: + - NONE + force_kill: yes + comparisons: + '*': strict + register: healthcheck_7 + ignore_errors: yes + - name: healthcheck (string in healthcheck test, changed) docker_container: image: quay.io/ansible/docker-test-containers:alpine3.8 @@ -1571,7 +1586,7 @@ healthcheck: test: "sleep 1" force_kill: yes - register: healthcheck_7 + register: healthcheck_8 ignore_errors: yes - name: healthcheck (string in healthcheck test, idempotency) @@ -1583,7 +1598,7 @@ healthcheck: test: "sleep 1" force_kill: yes - register: healthcheck_8 + register: healthcheck_9 ignore_errors: yes - name: cleanup @@ -1601,8 +1616,9 @@ - healthcheck_4 is not changed - healthcheck_5 is changed - healthcheck_6 is not changed - - healthcheck_7 is changed - - healthcheck_8 is not changed + - healthcheck_7 is not changed + - healthcheck_8 is changed + - healthcheck_9 is not changed when: docker_py_version is version('2.0.0', '>=') - assert: that: |