From 9be3ebc5966404cdc6df7622c80e57b44d99e05d Mon Sep 17 00:00:00 2001 From: John Hu Date: Wed, 26 Dec 2018 21:23:39 +0800 Subject: [PATCH] docker_image: add network parameter (#50313) * docker_image: add network parameter Add a network parameter to the docker_image module to specify the network to use for RUN commands. Called it network instead of network_mode as the latter seems like a legacy of when there were just a few default options to choose from, while now the name of an arbitrary network can be specified. Fixes #21433 * Format description * Update docker_image option_minimal_versions * Ensure network_mode param optional --- lib/ansible/modules/cloud/docker/docker_image.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/ansible/modules/cloud/docker/docker_image.py b/lib/ansible/modules/cloud/docker/docker_image.py index 36f6dcb5b7..8dcd9eb7d7 100644 --- a/lib/ansible/modules/cloud/docker/docker_image.py +++ b/lib/ansible/modules/cloud/docker/docker_image.py @@ -94,6 +94,11 @@ options: required: false version_added: "2.1" type: bool + network: + description: + - The network to use for C(RUN) build instructions. + required: false + version_added: "2.8" nocache: description: - Do not use cache when building an image. @@ -299,6 +304,7 @@ class ImageManager(DockerBaseClass): self.force = parameters.get('force') self.load_path = parameters.get('load_path') self.name = parameters.get('name') + self.network = parameters.get('network') self.nocache = parameters.get('nocache') self.path = parameters.get('path') self.pull = parameters.get('pull') @@ -552,6 +558,8 @@ class ImageManager(DockerBaseClass): params['buildargs'] = self.buildargs if self.cache_from: params['cache_from'] = self.cache_from + if self.network: + params['network_mode'] = self.network for line in self.client.build(**params): # line = json.loads(line) @@ -613,6 +621,7 @@ def main(): http_timeout=dict(type='int'), load_path=dict(type='path'), name=dict(type='str', required=True), + network=dict(type='str'), nocache=dict(type='bool', default=False), path=dict(type='path', aliases=['build_path']), pull=dict(type='bool', default=True), @@ -627,6 +636,7 @@ def main(): option_minimal_versions = dict( cache_from=dict(docker_py_version='2.1.0', docker_api_version='1.25'), + network=dict(docker_py_version='2.4.0', docker_api_version='1.25'), ) client = AnsibleDockerClient(