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.
pull/41177/head
Achintha Gunasekara 7 years ago committed by Martin Krizek
parent 5f7ffd39dc
commit d98c892017

@ -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),

Loading…
Cancel
Save