docker_container: return status also when 0 for non-detached containers (#58)

* Return status also when 0.

* Fix PR number.
This commit is contained in:
Felix Fontein
2021-01-02 18:53:25 +01:00
committed by GitHub
parent 9b131399ce
commit e4b747d788
3 changed files with 15 additions and 1 deletions
+11 -1
View File
@@ -1136,6 +1136,13 @@ container:
},
...
}'
status:
description:
- In case a container is started without detaching, this contains the exit code of the process in the container.
- Before community.docker 1.1.0, this was only returned when non-zero.
returned: when I(state) is C(started) and I(detached) is C(false), and when waiting for the container result did not fail
type: int
sample: 0
'''
import os
@@ -3007,6 +3014,9 @@ class ContainerManager(DockerBaseClass):
status = self.client.wait(container_id)['StatusCode']
else:
status = self.client.wait(container_id)
self.client.fail_results['status'] = status
self.results['status'] = status
if self.parameters.auto_remove:
output = "Cannot retrieve result as auto_remove is enabled"
if self.parameters.output_logs:
@@ -3023,7 +3033,7 @@ class ContainerManager(DockerBaseClass):
output = "Result logged using `%s` driver" % logging_driver
if status != 0:
self.fail(output, status=status)
self.fail(output)
if self.parameters.cleanup:
self.container_remove(container_id, force=True)
insp = self._get_container(container_id)