Updated PR based on comments

This commit is contained in:
David Dyball 2015-09-08 16:19:26 +01:00
parent 2fd511b906
commit a0a374b8ca

View file

@ -109,6 +109,14 @@ options:
- none - none
- syslog - syslog
version_added: "2.0" version_added: "2.0"
log_opt:
description:
- Additional options to pass to the logging driver selected above. See Docker log-driver
documentation for more information (https://docs.docker.com/reference/logging/overview/).
Requires docker >=1.7.0.
required: false
default: null
version_added: "2.0"
memory_limit: memory_limit:
description: description:
- RAM allocated to the container as a number of bytes or as a human-readable - RAM allocated to the container as a number of bytes or as a human-readable
@ -415,6 +423,19 @@ EXAMPLES = '''
name: ohno name: ohno
image: someuser/oldandbusted image: someuser/oldandbusted
state: absent state: absent
# Example Syslogging Output
- name: myservice container
docker:
name: myservice
image: someservice/someimage
state: reloaded
log_driver: syslog
log_opt:
syslog-address: tcp://my-syslog-server:514
syslog-facility: daemon
syslog-tag: myservice
''' '''
HAS_DOCKER_PY = True HAS_DOCKER_PY = True
@ -570,6 +591,7 @@ class DockerManager(object):
'extra_hosts': ((0, 7, 0), '1.3.1'), 'extra_hosts': ((0, 7, 0), '1.3.1'),
'pid': ((1, 0, 0), '1.17'), 'pid': ((1, 0, 0), '1.17'),
'log_driver': ((1, 2, 0), '1.18'), 'log_driver': ((1, 2, 0), '1.18'),
'log_opt': ((1, 2, 0), '1.18'),
'host_config': ((0, 7, 0), '1.15'), 'host_config': ((0, 7, 0), '1.15'),
'cpu_set': ((0, 6, 0), '1.14'), 'cpu_set': ((0, 6, 0), '1.14'),
'cap_add': ((0, 5, 0), '1.14'), 'cap_add': ((0, 5, 0), '1.14'),
@ -801,7 +823,7 @@ class DockerManager(object):
optionals = {} optionals = {}
for optional_param in ('dns', 'volumes_from', 'restart_policy', for optional_param in ('dns', 'volumes_from', 'restart_policy',
'restart_policy_retry', 'pid', 'extra_hosts', 'log_driver', 'restart_policy_retry', 'pid', 'extra_hosts', 'log_driver',
'cap_add', 'cap_drop', 'read_only'): 'cap_add', 'cap_drop', 'read_only', 'log_opt'):
optionals[optional_param] = self.module.params.get(optional_param) optionals[optional_param] = self.module.params.get(optional_param)
if optionals['dns'] is not None: if optionals['dns'] is not None:
@ -833,6 +855,9 @@ class DockerManager(object):
if optionals['log_driver'] is not None: if optionals['log_driver'] is not None:
self.ensure_capability('log_driver') self.ensure_capability('log_driver')
log_config = docker.utils.LogConfig(type=docker.utils.LogConfig.types.JSON) log_config = docker.utils.LogConfig(type=docker.utils.LogConfig.types.JSON)
if optionals['log_opt'] is not None:
for k, v in optionals['log_opt'].iteritems():
log_config.set_config_value(k, v)
log_config.type = optionals['log_driver'] log_config.type = optionals['log_driver']
params['log_config'] = log_config params['log_config'] = log_config
@ -1270,6 +1295,17 @@ class DockerManager(object):
differing.append(container) differing.append(container)
continue continue
if self.ensure_capability('log_opt', False):
expected_logging_opts = self.module.params.get('log_opt') or {}
actual_log_opts = container['HostConfig']['LogConfig']['Config']
if len(set(expected_logging_opts.items()) - set(actual_log_opts.items())) != 0:
log_opt_reasons = {
'added': dict(set(expected_logging_opts.items()) - set(actual_log_opts.items())),
'removed': dict(set(actual_log_opts.items()) - set(expected_logging_opts.items()))
}
self.reload_reasons.append('log_opt ({0})'.format(log_opt_reasons))
differing.append(container)
return differing return differing
def get_deployed_containers(self): def get_deployed_containers(self):
@ -1627,6 +1663,7 @@ def main():
pid = dict(default=None), pid = dict(default=None),
insecure_registry = dict(default=False, type='bool'), insecure_registry = dict(default=False, type='bool'),
log_driver = dict(default=None, choices=['json-file', 'none', 'syslog']), log_driver = dict(default=None, choices=['json-file', 'none', 'syslog']),
log_opt = dict(default=None, type='dict'),
cpu_set = dict(default=None), cpu_set = dict(default=None),
cap_add = dict(default=None, type='list'), cap_add = dict(default=None, type='list'),
cap_drop = dict(default=None, type='list'), cap_drop = dict(default=None, type='list'),