Add support for extra_hosts to docker module

extra_hosts parameter (maps to --add-host in 'docker run' syntax) is used
to add host-to-ip mappings to the container.
pull/18777/head
Heikki Partanen 10 years ago committed by Matt Clay
parent 1ceaa78dc0
commit ec566d86b3

@ -250,6 +250,9 @@ options:
retries. retries.
default: 0 default: 0
version_added: "1.9" version_added: "1.9"
extra_hosts:
description:
- Dict of custom host-to-IP mappings to be defined in the container
insecure_registry: insecure_registry:
description: description:
- Use insecure private registry by HTTP instead of HTTPS. Needed for - Use insecure private registry by HTTP instead of HTTPS. Needed for
@ -496,6 +499,7 @@ class DockerManager(object):
'dns': ((0, 3, 0), '1.10'), 'dns': ((0, 3, 0), '1.10'),
'volumes_from': ((0, 3, 0), '1.10'), 'volumes_from': ((0, 3, 0), '1.10'),
'restart_policy': ((0, 5, 0), '1.14'), 'restart_policy': ((0, 5, 0), '1.14'),
'extra_hosts': ((0, 7, 0), '1.3.1'),
'pid': ((1, 0, 0), '1.17'), 'pid': ((1, 0, 0), '1.17'),
# Clientside only # Clientside only
'insecure_registry': ((0, 5, 0), '0.0') 'insecure_registry': ((0, 5, 0), '0.0')
@ -1249,7 +1253,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'): 'restart_policy_retry', 'pid', 'extra_hosts'):
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:
@ -1270,6 +1274,10 @@ class DockerManager(object):
self.ensure_capability('pid') self.ensure_capability('pid')
params['pid_mode'] = optionals['pid'] params['pid_mode'] = optionals['pid']
if optionals['extra_hosts'] is not None:
self.ensure_capability('extra_hosts')
params['extra_hosts'] = optionals['extra_hosts']
for i in containers: for i in containers:
self.client.start(i['Id'], **params) self.client.start(i['Id'], **params)
self.increment_counter('started') self.increment_counter('started')
@ -1454,6 +1462,7 @@ def main():
state = dict(default='started', choices=['present', 'started', 'reloaded', 'restarted', 'stopped', 'killed', 'absent', 'running']), state = dict(default='started', choices=['present', 'started', 'reloaded', 'restarted', 'stopped', 'killed', 'absent', 'running']),
restart_policy = dict(default=None, choices=['always', 'on-failure', 'no']), restart_policy = dict(default=None, choices=['always', 'on-failure', 'no']),
restart_policy_retry = dict(default=0, type='int'), restart_policy_retry = dict(default=0, type='int'),
extra_hosts = dict(type='dict'),
debug = dict(default=False, type='bool'), debug = dict(default=False, type='bool'),
privileged = dict(default=False, type='bool'), privileged = dict(default=False, type='bool'),
stdin_open = dict(default=False, type='bool'), stdin_open = dict(default=False, type='bool'),

Loading…
Cancel
Save