From ea83727fcfc414a172ed38a8ec6956ec1845ebdb Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Mon, 30 Mar 2015 15:52:17 -0400 Subject: [PATCH] Wait for process exit on detached=no. --- lib/ansible/modules/cloud/docker/docker.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/docker/docker.py b/lib/ansible/modules/cloud/docker/docker.py index 2c802c7fc3..3e3d13044a 100644 --- a/lib/ansible/modules/cloud/docker/docker.py +++ b/lib/ansible/modules/cloud/docker/docker.py @@ -196,7 +196,8 @@ options: default: null detach: description: - - Enable detached mode to leave the container running in background. + - Enable detached mode to leave the container running in background. If + disabled, fail unless the process exits cleanly. default: true state: description: @@ -1346,6 +1347,13 @@ class DockerManager(object): self.client.start(i) self.increment_counter('started') + if not self.module.params.get('detach'): + status = self.client.wait(i['Id']) + if status != 0: + output = self.client.logs(i['Id'], stdout=True, stderr=True, + stream=False, timestamps=False) + self.module.fail_json(status=status, msg=output) + def stop_containers(self, containers): for i in containers: self.client.stop(i['Id'])