Add 'init' option to docker_container module to support docker's --init
option (#34547)
* Add support for `--init` option to `docker_container` module Fixes #30761 * Validate docker API's version when docker_container's init option is True https://github.com/ansible/ansible/pull/34547#pullrequestreview-122355244 https://docs.docker.com/engine/reference/commandline/run/#options init option requires docker API 1.25+ . * Fix failure of sanity test
This commit is contained in:
parent
d9533c3cbf
commit
38c86b7eef
2 changed files with 15 additions and 1 deletions
|
@ -187,6 +187,10 @@ class AnsibleDockerClient(Client):
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.fail("Error connecting: %s" % 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):
|
def log(self, msg, pretty_print=False):
|
||||||
pass
|
pass
|
||||||
# if self.debug:
|
# if self.debug:
|
||||||
|
|
|
@ -139,6 +139,13 @@ options:
|
||||||
description:
|
description:
|
||||||
- Repository path and tag used to create the container. If an image is not found or pull is true, the image
|
- 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.
|
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:
|
interactive:
|
||||||
description:
|
description:
|
||||||
- Keep stdin open after a container is launched, even if not attached.
|
- Keep stdin open after a container is launched, even if not attached.
|
||||||
|
@ -653,6 +660,7 @@ class TaskParameters(DockerBaseClass):
|
||||||
self.hostname = None
|
self.hostname = None
|
||||||
self.ignore_image = None
|
self.ignore_image = None
|
||||||
self.image = None
|
self.image = None
|
||||||
|
self.init = None
|
||||||
self.interactive = None
|
self.interactive = None
|
||||||
self.ipc_mode = None
|
self.ipc_mode = None
|
||||||
self.keep_volumes = None
|
self.keep_volumes = None
|
||||||
|
@ -898,7 +906,8 @@ class TaskParameters(DockerBaseClass):
|
||||||
group_add='groups',
|
group_add='groups',
|
||||||
devices='devices',
|
devices='devices',
|
||||||
pid_mode='pid_mode',
|
pid_mode='pid_mode',
|
||||||
tmpfs='tmpfs'
|
tmpfs='tmpfs',
|
||||||
|
init='init'
|
||||||
)
|
)
|
||||||
|
|
||||||
if HAS_DOCKER_PY_2 or HAS_DOCKER_PY_3:
|
if HAS_DOCKER_PY_2 or HAS_DOCKER_PY_3:
|
||||||
|
@ -1999,6 +2008,7 @@ def main():
|
||||||
hostname=dict(type='str'),
|
hostname=dict(type='str'),
|
||||||
ignore_image=dict(type='bool', default=False),
|
ignore_image=dict(type='bool', default=False),
|
||||||
image=dict(type='str'),
|
image=dict(type='str'),
|
||||||
|
init=dict(type='bool', default=False),
|
||||||
interactive=dict(type='bool', default=False),
|
interactive=dict(type='bool', default=False),
|
||||||
ipc_mode=dict(type='str'),
|
ipc_mode=dict(type='str'),
|
||||||
keep_volumes=dict(type='bool', default=True),
|
keep_volumes=dict(type='bool', default=True),
|
||||||
|
|
Loading…
Reference in a new issue