diff --git a/lib/ansible/module_utils/docker_common.py b/lib/ansible/module_utils/docker_common.py index b97fa3f35d1..1d65de6c43e 100644 --- a/lib/ansible/module_utils/docker_common.py +++ b/lib/ansible/module_utils/docker_common.py @@ -187,6 +187,10 @@ class AnsibleDockerClient(Client): except Exception as exc: self.fail("Error connecting: %s" % exc) + docker_api_version = self.version()["ApiVersion"] + if self.module.params.get("init") and LooseVersion(docker_api_version) < LooseVersion("1.25"): + self.fail("docker API version is %s. Minimum version required is 1.25 to set init option." % (docker_api_version,)) + def log(self, msg, pretty_print=False): pass # if self.debug: diff --git a/lib/ansible/modules/cloud/docker/docker_container.py b/lib/ansible/modules/cloud/docker/docker_container.py index 0a1a1d9a6e4..a81c6aaa95b 100644 --- a/lib/ansible/modules/cloud/docker/docker_container.py +++ b/lib/ansible/modules/cloud/docker/docker_container.py @@ -139,6 +139,13 @@ options: description: - Repository path and tag used to create the container. If an image is not found or pull is true, the image will be pulled from the registry. If no tag is included, 'latest' will be used. + init: + description: + - Run an init inside the container that forwards signals and reaps processes. + This option requires Docker API 1.25+. + type: bool + default: 'no' + version_added: "2.6" interactive: description: - Keep stdin open after a container is launched, even if not attached. @@ -653,6 +660,7 @@ class TaskParameters(DockerBaseClass): self.hostname = None self.ignore_image = None self.image = None + self.init = None self.interactive = None self.ipc_mode = None self.keep_volumes = None @@ -898,7 +906,8 @@ class TaskParameters(DockerBaseClass): group_add='groups', devices='devices', pid_mode='pid_mode', - tmpfs='tmpfs' + tmpfs='tmpfs', + init='init' ) if HAS_DOCKER_PY_2 or HAS_DOCKER_PY_3: @@ -1999,6 +2008,7 @@ def main(): hostname=dict(type='str'), ignore_image=dict(type='bool', default=False), image=dict(type='str'), + init=dict(type='bool', default=False), interactive=dict(type='bool', default=False), ipc_mode=dict(type='str'), keep_volumes=dict(type='bool', default=True),