# Buggy code
def container_start(self, container_id):
    self.log("start container %s" % (container_id))
    self.results["actions"].append(dict(started=container_id))
    self.results["changed"] = True
    if not self.check_mode:
        try:
            self.client.start(container=container_id)
        except Exception as exc:
            self.fail("Error starting container %s: %s" % (container_id, str(exc)))

        if not self.parameters.detach:
            status = self.client.wait(container_id)
            output = self.client.logs(
                container_id, stdout=True, stderr=True, stream=False, timestamps=False
            )
            if status != 0:
                self.fail(output, status=status)
            if self.parameters.cleanup:
                self.container_remove(container_id, force=True)
            insp = self._get_container(container_id)
            if insp.raw:
                insp.raw["Output"] = output
            else:
                insp.raw = dict(Output=output)
            return insp
    return self._get_container(container_id)


# Traceback (docker.errors.APIError)
TASK [Pull image] ***********************************************************************************************************************************************************************************************************************
fatal: [app.local]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to 127.0.0.1 closed.
", "module_stdout": "Traceback (most recent call last):
File \"/tmp/ansible_TLpSBI/ansible_module_docker_container.py\", line 2140, in <module>
main()
File \"/tmp/ansible_TLpSBI/ansible_module_docker_container.py\", line 2133, in main
cm = ContainerManager(client)
File \"/tmp/ansible_TLpSBI/ansible_module_docker_container.py\", line 1766, in __init__
self.present(state)
File \"/tmp/ansible_TLpSBI/ansible_module_docker_container.py\", line 1813, in present
container = self.container_start(container.Id)
File \"/tmp/ansible_TLpSBI/ansible_module_docker_container.py\", line 1969, in container_start
output = self.client.logs(container_id, stdout=True, stderr=True, stream=False, timestamps=False)
File \"/usr/lib/python2.7/site-packages/docker/utils/decorators.py\", line 19, in wrapped
return f(self, resource_id, *args, **kwargs)
File \"/usr/lib/python2.7/site-packages/docker/api/container.py\", line 839, in logs
return self._get_result(container, stream, res)
File \"/usr/lib/python2.7/site-packages/docker/api/client.py\", line 403, in _get_result
return self._get_result_tty(stream, res, cont['Config']['Tty'])
File \"/usr/lib/python2.7/site-packages/docker/api/client.py\", line 417, in _get_result_tty
self._raise_for_status(res)
File \"/usr/lib/python2.7/site-packages/docker/api/client.py\", line 222, in _raise_for_status
raise create_api_error_from_http_exception(e)
File \"/usr/lib/python2.7/site-packages/docker/errors.py\", line 31, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation)
docker.errors.APIError: 500 Server Error: Internal Server Error (\"configured logging reader does not support reading\")
", "msg": "MODULE FAILURE", "rc": 0}

# Fixed code
def container_start(self, container_id):
    self.log("start container %s" % (container_id))
    self.results["actions"].append(dict(started=container_id))
    self.results["changed"] = True
    if not self.check_mode:
        try:
            self.client.start(container=container_id)
        except Exception as exc:
            self.fail("Error starting container %s: %s" % (container_id, str(exc)))

        if not self.parameters.detach:
            status = self.client.wait(container_id)
            config = self.client.inspect_container(container_id)
            logging_driver = config["HostConfig"]["LogConfig"]["Type"]

            if logging_driver == "json-file" or logging_driver == "journald":
                output = self.client.logs(
                    container_id,
                    stdout=True,
                    stderr=True,
                    stream=False,
                    timestamps=False,
                )
            else:
                output = "Result logged using `%s` driver" % logging_driver

            if status != 0:
                self.fail(output, status=status)
            if self.parameters.cleanup:
                self.container_remove(container_id, force=True)
            insp = self._get_container(container_id)
            if insp.raw:
                insp.raw["Output"] = output
            else:
                insp.raw = dict(Output=output)
            return insp
    return self._get_container(container_id)