Support auto_remove in docker_container (#22929)

* Support auto_remove in docker_container

* Fail if not docker>=2 and auto_remove=True, don't set auto_remove in host_config if not docker>=2

* Make quoting more readable in ansible errors
This commit is contained in:
Matt Martz 2017-05-09 15:19:27 -05:00 committed by Chris Houseknecht
parent 0a22dbd9d8
commit 3324d0a4b0

View file

@ -35,6 +35,11 @@ description:
version_added: "2.1"
options:
auto_remove:
description:
- enable auto-removal of the container on daemon side when the container's process exits
default: false
version_added: "2.4"
blkio_weight:
description:
- Block IO (relative weight), between 10 and 1000.
@ -688,6 +693,7 @@ class TaskParameters(DockerBaseClass):
super(TaskParameters, self).__init__()
self.client = client
self.auto_remove = None
self.blkio_weight = None
self.capabilities = None
self.cleanup = None
@ -942,6 +948,11 @@ class TaskParameters(DockerBaseClass):
devices='devices',
pid_mode='pid_mode'
)
if HAS_DOCKER_PY_2:
# auto_remove is only supported in docker>=2
host_config_params['auto_remove'] = 'auto_remove'
params = dict()
for key, value in host_config_params.items():
if getattr(self, value, None) is not None:
@ -1228,6 +1239,7 @@ class Container(DockerBaseClass):
# Map parameters to container inspect results
config_mapping = dict(
auto_remove=host_config.get('AutoRemove'),
image=config.get('Image'),
expected_cmd=config.get('Cmd'),
hostname=config.get('Hostname'),
@ -1954,6 +1966,7 @@ class ContainerManager(DockerBaseClass):
def main():
argument_spec = dict(
auto_remove=dict(type='bool', default=False),
blkio_weight=dict(type='int'),
capabilities=dict(type='list'),
cleanup=dict(type='bool', default=False),
@ -2035,6 +2048,9 @@ def main():
supports_check_mode=True
)
if not HAS_DOCKER_PY_2 and client.module.params.get('auto_remove'):
client.module.fail_json(msg="'auto_remove' is not compatible with docker-py, and requires the docker python module")
cm = ContainerManager(client)
client.module.exit_json(**cm.results)