From f88107bc9b29655b9c3f07c0929f2210153fee9d Mon Sep 17 00:00:00 2001 From: Ingo Gottwald Date: Sun, 19 Oct 2014 22:15:48 +0200 Subject: [PATCH] Add support for new docker restart policies --- lib/ansible/modules/cloud/docker/docker.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/ansible/modules/cloud/docker/docker.py b/lib/ansible/modules/cloud/docker/docker.py index a65b65bf90..0902c4a296 100644 --- a/lib/ansible/modules/cloud/docker/docker.py +++ b/lib/ansible/modules/cloud/docker/docker.py @@ -210,6 +210,20 @@ options: default: '' aliases: [] version_added: "1.8" + restart_policy: + description: + - Set the container restart policy + required: false + default: false + aliases: [] + version_added: "1.9" + restart_policy_retry: + description: + - Set the retry limit for container restart policy + required: false + default: false + aliases: [] + version_added: "1.9" author: Cove Schneider, Joshua Conner, Pavel Antonov requirements: [ "docker-py >= 0.3.0", "docker >= 0.10.0" ] @@ -665,6 +679,12 @@ class DockerManager: params['dns'] = self.module.params.get('dns') params['volumes_from'] = self.module.params.get('volumes_from') + if docker.utils.compare_version('1.14', self.client.version()['ApiVersion']) >= 0 and hasattr(docker, '__version__') and docker.__version__ >= '0.5.0': + if self.module.params.get('restart_policy') is not None: + params['restart_policy'] = { 'Name': self.module.params.get('restart_policy') } + if params['restart_policy']['Name'] == 'on-failure': + params['restart_policy']['MaximumRetryCount'] = self.module.params.get('restart_policy_retry') + for i in containers: self.client.start(i['Id'], **params) self.increment_counter('started') @@ -742,6 +762,8 @@ def main(): dns = dict(), detach = dict(default=True, type='bool'), state = dict(default='running', choices=['absent', 'present', 'running', 'stopped', 'killed', 'restarted']), + restart_policy = dict(default=None, choices=['always', 'on-failure', 'no']), + restart_policy_retry = dict(default=0, type='int'), debug = dict(default=False, type='bool'), privileged = dict(default=False, type='bool'), stdin_open = dict(default=False, type='bool'),