From d98c89201785ccadcd87eab68a611d904536ac58 Mon Sep 17 00:00:00 2001 From: Achintha Gunasekara Date: Wed, 6 Jun 2018 18:50:04 +1000 Subject: [PATCH] Adding a switch to output docker logs (#40693) * Adding a switch to print logs * Update to docs * Adding `version_added` for the new option * Updating version added * Moving `output_logs` before `paued` for alphabetically ordering. --- .../modules/cloud/docker/docker_container.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/ansible/modules/cloud/docker/docker_container.py b/lib/ansible/modules/cloud/docker/docker_container.py index a81c6aaa95b..24e86813dfa 100644 --- a/lib/ansible/modules/cloud/docker/docker_container.py +++ b/lib/ansible/modules/cloud/docker/docker_container.py @@ -245,6 +245,12 @@ options: - An integer value containing the score given to the container in order to tune OOM killer preferences. default: 0 version_added: "2.2" + output_logs: + description: + - If set to true, output of the container command will be printed (only effective when log_driver is set to json-file or journald. + type: bool + default: 'no' + version_added: "2.7" paused: description: - Use with the started state to pause running processes inside the container. @@ -669,6 +675,7 @@ class TaskParameters(DockerBaseClass): self.labels = None self.links = None self.log_driver = None + self.output_logs = None self.log_options = None self.mac_address = None self.memory = None @@ -1767,6 +1774,9 @@ class ContainerManager(DockerBaseClass): def fail(self, msg, **kwargs): self.client.module.fail_json(msg=msg, **kwargs) + def _output_logs(self, msg): + self.client.module.log(msg=msg) + def _get_container(self, container): ''' Expects container ID or Name. Returns a container object @@ -1907,6 +1917,8 @@ class ContainerManager(DockerBaseClass): if logging_driver == 'json-file' or logging_driver == 'journald': output = self.client.logs(container_id, stdout=True, stderr=True, stream=False, timestamps=False) + if self.parameters.output_logs: + self._output_logs(msg=output) else: output = "Result logged using `%s` driver" % logging_driver @@ -2031,6 +2043,7 @@ def main(): networks=dict(type='list'), oom_killer=dict(type='bool'), oom_score_adj=dict(type='int'), + output_logs=dict(type='bool', default=False), paused=dict(type='bool', default=False), pid_mode=dict(type='str'), privileged=dict(type='bool', default=False),