@ -293,7 +293,7 @@ options:
init :
init :
description :
description :
- Run an init inside the container that forwards signals and reaps processes .
- Run an init inside the container that forwards signals and reaps processes .
This option requires Docker API 1.25 + .
This option requires Docker API > = 1.25 .
type : bool
type : bool
default : no
default : no
version_added : " 2.6 "
version_added : " 2.6 "
@ -429,12 +429,14 @@ options:
type : bool
type : bool
oom_score_adj :
oom_score_adj :
description :
description :
- An integer value containing the score given to the container in order to tune OOM killer preferences .
- An integer value containing the score given to the container in order to tune
OOM killer preferences .
type : int
type : int
version_added : " 2.2 "
version_added : " 2.2 "
output_logs :
output_logs :
description :
description :
- If set to true , output of the container command will be printed ( only effective when log_driver is set to json - file or journald .
- If set to true , output of the container command will be printed ( only effective
when log_driver is set to json - file or journald .
type : bool
type : bool
default : no
default : no
version_added : " 2.7 "
version_added : " 2.7 "
@ -446,7 +448,8 @@ options:
pid_mode :
pid_mode :
description :
description :
- Set the PID namespace mode for the container .
- Set the PID namespace mode for the container .
- Note that docker - py < 2.0 only supports ' host ' . Newer versions allow all values supported by the docker daemon .
- Note that Docker SDK for Python < 2.0 only supports ' host ' . Newer versions of the
Docker SDK for Python ( docker ) allow all values supported by the docker daemon .
type : str
type : str
pids_limit :
pids_limit :
description :
description :
@ -579,9 +582,9 @@ options:
will be set to this value .
will be set to this value .
- When the container is stopped , will be used as a timeout for stopping the
- When the container is stopped , will be used as a timeout for stopping the
container . In case the container has a custom C ( StopTimeout ) configuration ,
container . In case the container has a custom C ( StopTimeout ) configuration ,
the behavior depends on the version of docker. New versions of docker will
the behavior depends on the version of the docker daemon . New versions of
always use the container ' s configured C(StopTimeout) value if it has been
the docker daemon will always use the container ' s configured C(StopTimeout)
configured.
value if it has been configured.
type : int
type : int
trust_image_content :
trust_image_content :
description :
description :
@ -622,7 +625,7 @@ options:
- " Use docker CLI-style syntax: C(/host:/container[:mode]) "
- " Use docker CLI-style syntax: C(/host:/container[:mode]) "
- " Mount modes can be a comma-separated list of various modes such as C(ro), C(rw), C(consistent),
- " Mount modes can be a comma-separated list of various modes such as C(ro), C(rw), C(consistent),
C ( delegated ) , C ( cached ) , C ( rprivate ) , C ( private ) , C ( rshared ) , C ( shared ) , C ( rslave ) , C ( slave ) .
C ( delegated ) , C ( cached ) , C ( rprivate ) , C ( private ) , C ( rshared ) , C ( shared ) , C ( rslave ) , C ( slave ) .
Note that docker might not support all modes and combinations of such modes . "
Note that the docker daemon might not support all modes and combinations of such modes . "
- SELinux hosts can additionally use C ( z ) or C ( Z ) to use a shared or
- SELinux hosts can additionally use C ( z ) or C ( Z ) to use a shared or
private label for the volume .
private label for the volume .
- " Note that Ansible 2.7 and earlier only supported one mode, which had to be one of C(ro), C(rw),
- " Note that Ansible 2.7 and earlier only supported one mode, which had to be one of C(ro), C(rw),
@ -654,9 +657,10 @@ author:
- " Daan Oosterveld (@dusdanig) "
- " Daan Oosterveld (@dusdanig) "
- " Chris Houseknecht (@chouseknecht) "
- " Chris Houseknecht (@chouseknecht) "
- " Kassian Sun (@kassiansun) "
- " Kassian Sun (@kassiansun) "
- " Felix Fontein (@felixfontein) "
requirements :
requirements :
- " docker-py >= 1.8.0"
- " L(Docker SDK for Python,https:// docker-py.readthedocs.io/en/stable/) >= 1.8.0 (use L(docker-py,https://pypi.org/project/docker-py/) for Python 2.6) "
- " Docker API >= 1.20 "
- " Docker API >= 1.20 "
'''
'''
@ -945,7 +949,7 @@ try:
from docker . utils . types import Ulimit , LogConfig
from docker . utils . types import Ulimit , LogConfig
from docker . errors import APIError , NotFound
from docker . errors import APIError , NotFound
except Exception :
except Exception :
# missing docker-py handled in ansible.module_utils.docker.common
# missing Docker SDK for Python handled in ansible.module_utils.docker.common
pass
pass
@ -1351,7 +1355,7 @@ class TaskParameters(DockerBaseClass):
if self . client . docker_py_version > = LooseVersion ( ' 1.9 ' ) and self . client . docker_api_version > = LooseVersion ( ' 1.22 ' ) :
if self . client . docker_py_version > = LooseVersion ( ' 1.9 ' ) and self . client . docker_api_version > = LooseVersion ( ' 1.22 ' ) :
# blkio_weight can always be updated, but can only be set on creation
# blkio_weight can always be updated, but can only be set on creation
# when docker-py and d ocker API are new enough
# when Docker SDK for Python and D ocker API are new enough
host_config_params [ ' blkio_weight ' ] = ' blkio_weight '
host_config_params [ ' blkio_weight ' ] = ' blkio_weight '
if self . client . docker_py_version > = LooseVersion ( ' 3.0 ' ) :
if self . client . docker_py_version > = LooseVersion ( ' 3.0 ' ) :
@ -1819,15 +1823,15 @@ class Container(DockerBaseClass):
config_mapping [ ' log_options ' ] = log_config . get ( ' Config ' )
config_mapping [ ' log_options ' ] = log_config . get ( ' Config ' )
if self . parameters . client . option_minimal_versions [ ' auto_remove ' ] [ ' supported ' ] :
if self . parameters . client . option_minimal_versions [ ' auto_remove ' ] [ ' supported ' ] :
# auto_remove is only supported in docker>=2; unfortunately it has a default
# auto_remove is only supported in Docker SDK for Python >= 2.0.0; unfortunately
# value, that's why we have to jump through the hoops here
# it has a default value, that's why we have to jump through the hoops here
config_mapping [ ' auto_remove ' ] = host_config . get ( ' AutoRemove ' )
config_mapping [ ' auto_remove ' ] = host_config . get ( ' AutoRemove ' )
if self . parameters . client . option_minimal_versions [ ' stop_timeout ' ] [ ' supported ' ] :
if self . parameters . client . option_minimal_versions [ ' stop_timeout ' ] [ ' supported ' ] :
# stop_timeout is only supported in docker>=2.1. Note that stop_timeou t
# stop_timeout is only supported in Docker SDK for Python >= 2.1. Note tha t
# has a hybrid role, in that it used to be something only used for stopping
# stop_timeout has a hybrid role, in that it used to be something only used
# containers, and is now also used as a container property. That's why
# for stopping containers, and is now also used as a container property.
# it needs special handling here.
# That's why it needs special handling here.
config_mapping [ ' stop_timeout ' ] = config . get ( ' StopTimeout ' )
config_mapping [ ' stop_timeout ' ] = config . get ( ' StopTimeout ' )
if self . parameters . client . docker_api_version < LooseVersion ( ' 1.22 ' ) :
if self . parameters . client . docker_api_version < LooseVersion ( ' 1.22 ' ) :
@ -2544,8 +2548,8 @@ class ContainerManager(DockerBaseClass):
pass
pass
except APIError as exc :
except APIError as exc :
if ' Unpause the container before stopping or killing ' in exc . explanation :
if ' Unpause the container before stopping or killing ' in exc . explanation :
# New docker versions do not allow containers to be removed if they are paus ed
# New docker daemon versions do not allow containers to be removed
# Make sure we don't end up in an infinite loop
# if they are paused. Make sure we don't end up in an infinite loop.
if count == 3 :
if count == 3 :
self . fail ( " Error removing container %s (tried to unpause three times): %s " % ( container_id , str ( exc ) ) )
self . fail ( " Error removing container %s (tried to unpause three times): %s " % ( container_id , str ( exc ) ) )
count + = 1
count + = 1
@ -2611,8 +2615,8 @@ class ContainerManager(DockerBaseClass):
response = self . client . stop ( container_id )
response = self . client . stop ( container_id )
except APIError as exc :
except APIError as exc :
if ' Unpause the container before stopping or killing ' in exc . explanation :
if ' Unpause the container before stopping or killing ' in exc . explanation :
# New docker versions do not allow containers to be removed if they are paus ed
# New docker daemon versions do not allow containers to be removed
# Make sure we don't end up in an infinite loop
# if they are paused. Make sure we don't end up in an infinite loop.
if count == 3 :
if count == 3 :
self . fail ( " Error removing container %s (tried to unpause three times): %s " % ( container_id , str ( exc ) ) )
self . fail ( " Error removing container %s (tried to unpause three times): %s " % ( container_id , str ( exc ) ) )
count + = 1
count + = 1
@ -2754,14 +2758,14 @@ class AnsibleDockerClientContainer(AnsibleDockerClient):
if stop_timeout_needed_for_update and not stop_timeout_supported :
if stop_timeout_needed_for_update and not stop_timeout_supported :
# We warn (instead of fail) since in older versions, stop_timeout was not used
# We warn (instead of fail) since in older versions, stop_timeout was not used
# to update the container's configuration, but only when stopping a container.
# to update the container's configuration, but only when stopping a container.
self . module . warn ( " docker or docker-py version is %s . Minimum version required is 2.1 to update "
self . module . warn ( " Docker SDK for Python' s version is %s . Minimum version required is 2.1 to update "
" the container ' s stop_timeout configuration. "
" the container ' s stop_timeout configuration. "
" If you use the ' docker-py ' module, you have to switch to the docker ' Python' package." % ( docker_version , ) )
" If you use the ' docker-py ' module, you have to switch to the ' docker' Python package." % ( docker_version , ) )
else :
else :
if stop_timeout_needed_for_update and not stop_timeout_supported :
if stop_timeout_needed_for_update and not stop_timeout_supported :
# We warn (instead of fail) since in older versions, stop_timeout was not used
# We warn (instead of fail) since in older versions, stop_timeout was not used
# to update the container's configuration, but only when stopping a container.
# to update the container's configuration, but only when stopping a container.
self . module . warn ( " d ocker API version is %s . Minimum version required is 1.25 to set or "
self . module . warn ( " D ocker API version is %s . Minimum version required is 1.25 to set or "
" update the container ' s stop_timeout configuration. " % ( self . docker_api_version_str , ) )
" update the container ' s stop_timeout configuration. " % ( self . docker_api_version_str , ) )
self . option_minimal_versions [ ' stop_timeout ' ] [ ' supported ' ] = stop_timeout_supported
self . option_minimal_versions [ ' stop_timeout ' ] [ ' supported ' ] = stop_timeout_supported