From 352daa0138b10dc8d6a87afe9afa03e5272d6907 Mon Sep 17 00:00:00 2001 From: Johannes 'fish' Ziemke Date: Thu, 15 May 2014 00:29:54 +0200 Subject: [PATCH 1/2] Add networking mode parameter (net) to docker Since 0.11 Docker supports different networking modes (see docker run --net). This commit add support for that to the ansible docker module. This depends on https://github.com/dotcloud/docker-py/commit/2d58351164eba01e30569f44a921d5aca40163ae --- library/cloud/docker | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/library/cloud/docker b/library/cloud/docker index 6dbcb9daf4..743b20c99c 100644 --- a/library/cloud/docker +++ b/library/cloud/docker @@ -183,6 +183,13 @@ options: default: false aliases: [] version_added: "1.6" + net: + description: + - Set Network mode for the container (bridge, none, container:, host) + required: false + default: false + aliases: [] + version_added: "1.11" author: Cove Schneider, Joshua Conner, Pavel Antonov requirements: [ "docker-py >= 0.3.0", "docker >= 0.10.0" ] ''' @@ -575,6 +582,7 @@ class DockerManager: 'publish_all_ports': self.module.params.get('publish_all_ports'), 'privileged': self.module.params.get('privileged'), 'links': self.links, + 'network_mode': self.module.params.get('net'), } if docker.utils.compare_version('1.10', self.client.version()['ApiVersion']) >= 0 and hasattr(docker, '__version__') and docker.__version__ > '0.3.0': params['dns'] = self.module.params.get('dns') @@ -660,7 +668,8 @@ def main(): stdin_open = dict(default=False, type='bool'), tty = dict(default=False, type='bool'), lxc_conf = dict(default=None, type='list'), - name = dict(default=None) + name = dict(default=None), + net = dict(default=None) ) ) From 4a08aac2cb11121dfe7bd90037cc82dc272b66df Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Fri, 8 Aug 2014 13:16:08 -0500 Subject: [PATCH 2/2] Updating version_added for docker net param and adding an example --- library/cloud/docker | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/library/cloud/docker b/library/cloud/docker index ecb319d2fd..fb453b70a6 100644 --- a/library/cloud/docker +++ b/library/cloud/docker @@ -185,11 +185,11 @@ options: version_added: "1.6" net: description: - - Set Network mode for the container (bridge, none, container:, host) + - Set Network mode for the container (bridge, none, container:, host). Requires docker >= 0.11. required: false default: false aliases: [] - version_added: "1.11" + version_added: "1.8" author: Cove Schneider, Joshua Conner, Pavel Antonov requirements: [ "docker-py >= 0.3.0", "docker >= 0.10.0" ] ''' @@ -300,6 +300,14 @@ Create containers with options specified as strings and lists as comma-separated sudo: yes tasks: docker: image=namespace/image_name links=postgresql:db,redis:redis + +Create a container with no networking: + +- hosts: web + sudo: yes + tasks: + docker: image=namespace/image_name net=none + ''' HAS_DOCKER_PY = True