Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a switch to output docker logs #40693

Merged
merged 5 commits into from
Jun 6, 2018
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/ansible/modules/cloud/docker/docker_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@
- 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.
Expand Down Expand Up @@ -661,6 +667,7 @@ def __init__(self, client):
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
Expand Down Expand Up @@ -1758,6 +1765,9 @@ def absent(self):
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
Expand Down Expand Up @@ -1898,6 +1908,8 @@ def container_start(self, container_id):

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

Expand Down Expand Up @@ -2022,6 +2034,7 @@ def main():
oom_killer=dict(type='bool'),
oom_score_adj=dict(type='int'),
paused=dict(type='bool', default=False),
output_logs=dict(type='bool', default=False),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this before paused to make options alphabetically ordered?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kassiansun Updated and ready_for_review again.

pid_mode=dict(type='str'),
privileged=dict(type='bool', default=False),
published_ports=dict(type='list', aliases=['ports']),
Expand Down