Skip to content

Commit

Permalink
docker_container: return status also when 0 for non-detached containe…
Browse files Browse the repository at this point in the history
…rs (#58)

* Return status also when 0.

* Fix PR number.
  • Loading branch information
felixfontein authored Jan 2, 2021
1 parent 9b13139 commit e4b747d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "docker_container - when a container is started with ``detached=false``, ``status`` is now also returned when it is 0 (https://github.com/ansible-collections/community.docker/issues/26, https://github.com/ansible-collections/community.docker/pull/58)."
12 changes: 11 additions & 1 deletion plugins/modules/docker_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,13 @@
},
...
}'
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
Expand Down Expand Up @@ -3007,6 +3014,9 @@ def container_start(self, container_id):
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:
Expand All @@ -3023,7 +3033,7 @@ def container_start(self, container_id):
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,11 @@
# often enough to be annoying. That's why we disable this for now,
# and simply test that 'Output' is contained in the result.
- "'Output' in detach_no_cleanup.container"
- detach_no_cleanup.status == 0
# - "'Hello from Docker!' in detach_no_cleanup.container.Output"
- detach_no_cleanup_cleanup is changed
- "'Output' in detach_cleanup.container"
- detach_cleanup.status == 0
# - "'Hello from Docker!' in detach_cleanup.container.Output"
- detach_cleanup_cleanup is not changed
- assert:
Expand Down

0 comments on commit e4b747d

Please sign in to comment.