@ -92,6 +92,11 @@ options:
- Do not use cache when building an image .
- Do not use cache when building an image .
type : bool
type : bool
default : no
default : no
etc_hosts :
description :
- Extra hosts to add to C ( / etc / hosts ) in building containers , as a mapping of hostname to IP address .
type : dict
version_added : " 2.9 "
args :
args :
description :
description :
- Provide a dictionary of C ( key : value ) build arguments that map to Dockerfile ARG directive .
- Provide a dictionary of C ( key : value ) build arguments that map to Dockerfile ARG directive .
@ -324,6 +329,7 @@ requirements:
author :
author :
- Pavel Antonov ( @softzilla )
- Pavel Antonov ( @softzilla )
- Chris Houseknecht ( @chouseknecht )
- Chris Houseknecht ( @chouseknecht )
- Sorin Sbarnea ( @ssbarnea )
'''
'''
@ -424,6 +430,7 @@ import traceback
from distutils . version import LooseVersion
from distutils . version import LooseVersion
from ansible . module_utils . docker . common import (
from ansible . module_utils . docker . common import (
clean_dict_booleans_for_docker_api ,
docker_version ,
docker_version ,
AnsibleDockerClient ,
AnsibleDockerClient ,
DockerBaseClass ,
DockerBaseClass ,
@ -469,6 +476,7 @@ class ImageManager(DockerBaseClass):
self . load_path = parameters . get ( ' load_path ' )
self . load_path = parameters . get ( ' load_path ' )
self . name = parameters . get ( ' name ' )
self . name = parameters . get ( ' name ' )
self . network = build . get ( ' network ' )
self . network = build . get ( ' network ' )
self . extra_hosts = clean_dict_booleans_for_docker_api ( build . get ( ' etc_hosts ' ) )
self . nocache = build . get ( ' nocache ' , False )
self . nocache = build . get ( ' nocache ' , False )
self . build_path = build . get ( ' path ' )
self . build_path = build . get ( ' path ' )
self . pull = build . get ( ' pull ' )
self . pull = build . get ( ' pull ' )
@ -738,6 +746,8 @@ class ImageManager(DockerBaseClass):
params [ ' cache_from ' ] = self . cache_from
params [ ' cache_from ' ] = self . cache_from
if self . network :
if self . network :
params [ ' network_mode ' ] = self . network
params [ ' network_mode ' ] = self . network
if self . extra_hosts :
params [ ' extra_hosts ' ] = self . extra_hosts
if self . use_config_proxy :
if self . use_config_proxy :
params [ ' use_config_proxy ' ] = self . use_config_proxy
params [ ' use_config_proxy ' ] = self . use_config_proxy
# Due to a bug in docker-py, it will crash if
# Due to a bug in docker-py, it will crash if
@ -813,6 +823,7 @@ def main():
args = dict ( type = ' dict ' ) ,
args = dict ( type = ' dict ' ) ,
use_config_proxy = dict ( type = ' bool ' ) ,
use_config_proxy = dict ( type = ' bool ' ) ,
target = dict ( type = ' str ' ) ,
target = dict ( type = ' str ' ) ,
etc_hosts = dict ( type = ' dict ' ) ,
) ) ,
) ) ,
archive_path = dict ( type = ' path ' ) ,
archive_path = dict ( type = ' path ' ) ,
container_limits = dict ( type = ' dict ' , options = dict (
container_limits = dict ( type = ' dict ' , options = dict (
@ -859,11 +870,15 @@ def main():
def detect_use_config_proxy ( client ) :
def detect_use_config_proxy ( client ) :
return client . module . params [ ' build ' ] and client . module . params [ ' build ' ] . get ( ' use_config_proxy ' ) is not None
return client . module . params [ ' build ' ] and client . module . params [ ' build ' ] . get ( ' use_config_proxy ' ) is not None
def detect_etc_hosts ( client ) :
return client . module . params [ ' build ' ] and bool ( client . module . params [ ' build ' ] . get ( ' etc_hosts ' ) )
option_minimal_versions = dict ( )
option_minimal_versions = dict ( )
option_minimal_versions [ " build.cache_from " ] = dict ( docker_py_version = ' 2.1.0 ' , docker_api_version = ' 1.25 ' , detect_usage = detect_build_cache_from )
option_minimal_versions [ " build.cache_from " ] = dict ( docker_py_version = ' 2.1.0 ' , docker_api_version = ' 1.25 ' , detect_usage = detect_build_cache_from )
option_minimal_versions [ " build.network " ] = dict ( docker_py_version = ' 2.4.0 ' , docker_api_version = ' 1.25 ' , detect_usage = detect_build_network )
option_minimal_versions [ " build.network " ] = dict ( docker_py_version = ' 2.4.0 ' , docker_api_version = ' 1.25 ' , detect_usage = detect_build_network )
option_minimal_versions [ " build.target " ] = dict ( docker_py_version = ' 2.4.0 ' , detect_usage = detect_build_target )
option_minimal_versions [ " build.target " ] = dict ( docker_py_version = ' 2.4.0 ' , detect_usage = detect_build_target )
option_minimal_versions [ " build.use_config_proxy " ] = dict ( docker_py_version = ' 3.7.0 ' , detect_usage = detect_use_config_proxy )
option_minimal_versions [ " build.use_config_proxy " ] = dict ( docker_py_version = ' 3.7.0 ' , detect_usage = detect_use_config_proxy )
option_minimal_versions [ " build.etc_hosts " ] = dict ( docker_py_version = ' 2.6.0 ' , docker_api_version = ' 1.27 ' , detect_usage = detect_etc_hosts )
client = AnsibleDockerClient (
client = AnsibleDockerClient (
argument_spec = argument_spec ,
argument_spec = argument_spec ,