@ -359,6 +359,10 @@ options:
description :
description :
- Use with restart policy to control maximum number of restart attempts .
- Use with restart policy to control maximum number of restart attempts .
default : 0
default : 0
runtime :
description :
- Runtime to use for the container .
version_added : " 2.8 "
shm_size :
shm_size :
description :
description :
- " Size of C(/dev/shm) (format: C(<number>[<unit>])). Number is positive integer.
- " Size of C(/dev/shm) (format: C(<number>[<unit>])). Number is positive integer.
@ -855,6 +859,7 @@ class TaskParameters(DockerBaseClass):
self . restart = None
self . restart = None
self . restart_retries = None
self . restart_retries = None
self . restart_policy = None
self . restart_policy = None
self . runtime = None
self . shm_size = None
self . shm_size = None
self . security_opts = None
self . security_opts = None
self . state = None
self . state = None
@ -1118,6 +1123,9 @@ class TaskParameters(DockerBaseClass):
if self . client . HAS_UTS_MODE_OPT :
if self . client . HAS_UTS_MODE_OPT :
host_config_params [ ' uts_mode ' ] = ' uts '
host_config_params [ ' uts_mode ' ] = ' uts '
if self . client . HAS_RUNTIME_OPT :
host_config_params [ ' runtime ' ] = ' runtime '
params = dict ( )
params = dict ( )
for key , value in host_config_params . items ( ) :
for key , value in host_config_params . items ( ) :
if getattr ( self , value , None ) is not None :
if getattr ( self , value , None ) is not None :
@ -1561,6 +1569,7 @@ class Container(DockerBaseClass):
expected_ports = host_config . get ( ' PortBindings ' ) ,
expected_ports = host_config . get ( ' PortBindings ' ) ,
read_only = host_config . get ( ' ReadonlyRootfs ' ) ,
read_only = host_config . get ( ' ReadonlyRootfs ' ) ,
restart_policy = restart_policy . get ( ' Name ' ) ,
restart_policy = restart_policy . get ( ' Name ' ) ,
runtime = host_config . get ( ' Runtime ' ) ,
# Cannot test shm_size, as shm_size is not included in container inspection results.
# Cannot test shm_size, as shm_size is not included in container inspection results.
# shm_size=host_config.get('ShmSize'),
# shm_size=host_config.get('ShmSize'),
security_opts = host_config . get ( " SecurityOpt " ) ,
security_opts = host_config . get ( " SecurityOpt " ) ,
@ -2421,6 +2430,10 @@ class AnsibleDockerClientContainer(AnsibleDockerClient):
self . module . warn ( " docker API version is %s . Minimum version required is 1.25 to set or "
self . module . warn ( " docker API version is %s . Minimum version required is 1.25 to set or "
" update the container ' s stop_timeout configuration. " % ( docker_api_version , ) )
" update the container ' s stop_timeout configuration. " % ( docker_api_version , ) )
runtime_supported = LooseVersion ( docker_api_version ) > = LooseVersion ( ' 1.12 ' )
if self . module . params . get ( " runtime " ) and not runtime_supported :
self . fail ( ' docker API version is %s . Minimum version required is 1.12 to set runtime option. ' % ( docker_api_version , ) )
self . HAS_INIT_OPT = init_supported
self . HAS_INIT_OPT = init_supported
self . HAS_UTS_MODE_OPT = uts_mode_supported
self . HAS_UTS_MODE_OPT = uts_mode_supported
self . HAS_BLKIO_WEIGHT_OPT = blkio_weight_supported
self . HAS_BLKIO_WEIGHT_OPT = blkio_weight_supported
@ -2428,6 +2441,8 @@ class AnsibleDockerClientContainer(AnsibleDockerClient):
self . HAS_STOP_TIMEOUT_OPT = stop_timeout_supported
self . HAS_STOP_TIMEOUT_OPT = stop_timeout_supported
self . HAS_AUTO_REMOVE_OPT = HAS_DOCKER_PY_2 or HAS_DOCKER_PY_3
self . HAS_AUTO_REMOVE_OPT = HAS_DOCKER_PY_2 or HAS_DOCKER_PY_3
self . HAS_RUNTIME_OPT = runtime_supported
if self . module . params . get ( ' auto_remove ' ) and not self . HAS_AUTO_REMOVE_OPT :
if self . module . params . get ( ' auto_remove ' ) and not self . HAS_AUTO_REMOVE_OPT :
self . fail ( " ' auto_remove ' is not compatible with the ' docker-py ' Python package. It requires the newer ' docker ' Python package. " )
self . fail ( " ' auto_remove ' is not compatible with the ' docker-py ' Python package. It requires the newer ' docker ' Python package. " )
@ -2496,6 +2511,7 @@ def main():
restart = dict ( type = ' bool ' , default = False ) ,
restart = dict ( type = ' bool ' , default = False ) ,
restart_policy = dict ( type = ' str ' , choices = [ ' no ' , ' on-failure ' , ' always ' , ' unless-stopped ' ] ) ,
restart_policy = dict ( type = ' str ' , choices = [ ' no ' , ' on-failure ' , ' always ' , ' unless-stopped ' ] ) ,
restart_retries = dict ( type = ' int ' , default = None ) ,
restart_retries = dict ( type = ' int ' , default = None ) ,
runtime = dict ( type = ' str ' , default = None ) ,
security_opts = dict ( type = ' list ' ) ,
security_opts = dict ( type = ' list ' ) ,
shm_size = dict ( type = ' str ' ) ,
shm_size = dict ( type = ' str ' ) ,
state = dict ( type = ' str ' , choices = [ ' absent ' , ' present ' , ' started ' , ' stopped ' ] , default = ' started ' ) ,
state = dict ( type = ' str ' , choices = [ ' absent ' , ' present ' , ' started ' , ' stopped ' ] , default = ' started ' ) ,