From ec566d86b3bc2408f635ecc93650b690c7030050 Mon Sep 17 00:00:00 2001 From: Heikki Partanen Date: Tue, 7 Apr 2015 10:08:43 +0300 Subject: [PATCH] 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. --- lib/ansible/modules/cloud/docker/docker.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/docker/docker.py b/lib/ansible/modules/cloud/docker/docker.py index d56a0383d4..417b44c7de 100644 --- a/lib/ansible/modules/cloud/docker/docker.py +++ b/lib/ansible/modules/cloud/docker/docker.py @@ -250,6 +250,9 @@ options: retries. default: 0 version_added: "1.9" + extra_hosts: + description: + - Dict of custom host-to-IP mappings to be defined in the container insecure_registry: description: - Use insecure private registry by HTTP instead of HTTPS. Needed for @@ -496,6 +499,7 @@ class DockerManager(object): 'dns': ((0, 3, 0), '1.10'), 'volumes_from': ((0, 3, 0), '1.10'), 'restart_policy': ((0, 5, 0), '1.14'), + 'extra_hosts': ((0, 7, 0), '1.3.1'), 'pid': ((1, 0, 0), '1.17'), # Clientside only 'insecure_registry': ((0, 5, 0), '0.0') @@ -1249,7 +1253,7 @@ class DockerManager(object): optionals = {} 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) if optionals['dns'] is not None: @@ -1270,6 +1274,10 @@ class DockerManager(object): self.ensure_capability('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: self.client.start(i['Id'], **params) self.increment_counter('started') @@ -1454,6 +1462,7 @@ def main(): 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_retry = dict(default=0, type='int'), + extra_hosts = dict(type='dict'), debug = dict(default=False, type='bool'), privileged = dict(default=False, type='bool'), stdin_open = dict(default=False, type='bool'),