summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fontein <felix@fontein.de>2020-02-03 19:13:17 +0100
committerGitHub <noreply@github.com>2020-02-03 13:13:17 -0500
commit5c1a3a3ac2086119bd16316dde379047d90cd86c (patch)
treee4e89484171b645f7e5a1e046b9d294a55a5df49
parentd6f2b4e788ed13756ba4e4a05b8b7a879900dbc3 (diff)
downloadansible-5c1a3a3ac2086119bd16316dde379047d90cd86c.tar.gz
docker_container and docker_swarm_service: allow to actually disable healthcheck of image (#66599)
* Allow to actually disable healthcheck of image. * Add changelog.
-rw-r--r--changelogs/fragments/66599-docker-healthcheck.yml3
-rw-r--r--lib/ansible/modules/cloud/docker/docker_container.py4
-rw-r--r--lib/ansible/modules/cloud/docker/docker_swarm_service.py9
3 files changed, 14 insertions, 2 deletions
diff --git a/changelogs/fragments/66599-docker-healthcheck.yml b/changelogs/fragments/66599-docker-healthcheck.yml
new file mode 100644
index 0000000000..30026c9090
--- /dev/null
+++ b/changelogs/fragments/66599-docker-healthcheck.yml
@@ -0,0 +1,3 @@
+bugfixes:
+- "docker_container - passing ``test: [NONE]`` now actually disables the image's healthcheck, as documented."
+- "docker_swarm_service - passing ``test: [NONE]`` now actually disables the image's healthcheck, as documented."
diff --git a/lib/ansible/modules/cloud/docker/docker_container.py b/lib/ansible/modules/cloud/docker/docker_container.py
index 24856e8aa5..2c8c7df85d 100644
--- a/lib/ansible/modules/cloud/docker/docker_container.py
+++ b/lib/ansible/modules/cloud/docker/docker_container.py
@@ -1480,6 +1480,10 @@ class TaskParameters(DockerBaseClass):
if self.client.option_minimal_versions[value]['supported']:
result[key] = getattr(self, value)
+ if self.disable_healthcheck:
+ # Make sure image's health check is overridden
+ result['healthcheck'] = {'test': ['NONE']}
+
if self.networks_cli_compatible and self.networks:
network = self.networks[0]
params = dict()
diff --git a/lib/ansible/modules/cloud/docker/docker_swarm_service.py b/lib/ansible/modules/cloud/docker/docker_swarm_service.py
index 359f84972e..d4e83a2df5 100644
--- a/lib/ansible/modules/cloud/docker/docker_swarm_service.py
+++ b/lib/ansible/modules/cloud/docker/docker_swarm_service.py
@@ -1927,8 +1927,11 @@ class DockerService(DockerBaseClass):
def has_healthcheck_changed(self, old_publish):
if self.healthcheck_disabled is False and self.healthcheck is None:
return False
- if self.healthcheck_disabled and old_publish.healthcheck is None:
- return False
+ if self.healthcheck_disabled:
+ if old_publish.healthcheck is None:
+ return False
+ if old_publish.healthcheck.get('test') == ['NONE']:
+ return False
return self.healthcheck != old_publish.healthcheck
def has_publish_changed(self, old_publish):
@@ -2053,6 +2056,8 @@ class DockerService(DockerBaseClass):
container_spec_args['labels'] = self.container_labels
if self.healthcheck is not None:
container_spec_args['healthcheck'] = types.Healthcheck(**self.healthcheck)
+ elif self.healthcheck_disabled:
+ container_spec_args['healthcheck'] = types.Healthcheck(test=['NONE'])
if self.hostname is not None:
container_spec_args['hostname'] = self.hostname
if self.hosts is not None: