From 3f247fcbe33057b3066a5c1cd5c8eeb83ae69fa7 Mon Sep 17 00:00:00 2001 From: Kavin Kankeshwar Date: Tue, 23 Jul 2013 16:03:13 -0700 Subject: [PATCH] fixes ansible/ansible#3609 Add max_fail_pct to playbook parameter, to complement serial option, So if total number of failures execeed max_fail_pct * total number of hosts, do not go to the next serial batch --- lib/ansible/playbook/__init__.py | 4 ++++ lib/ansible/playbook/play.py | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 68e94d226b..ed89546be2 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -580,6 +580,10 @@ class PlayBook(object): if task.any_errors_fatal and len(host_list) < hosts_count: host_list = None + # If threshold for max nodes failed is exceeded , bail out. + if (hosts_count - len(host_list)) > int((play.max_fail_pct)/100.0 * hosts_count): + host_list = None + # if no hosts remain, drop out if not host_list: self.callbacks.on_no_hosts_remaining() diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index 03216fe1f1..5d0b29dff4 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -32,7 +32,7 @@ class Play(object): 'handlers', 'remote_user', 'remote_port', 'sudo', 'sudo_user', 'transport', 'playbook', 'tags', 'gather_facts', 'serial', '_ds', '_handlers', '_tasks', - 'basedir', 'any_errors_fatal', 'roles' + 'basedir', 'any_errors_fatal', 'roles', 'max_fail_pct' ] # to catch typos and so forth -- these are userland names @@ -41,7 +41,7 @@ class Play(object): 'hosts', 'name', 'vars', 'vars_prompt', 'vars_files', 'tasks', 'handlers', 'user', 'port', 'include', 'sudo', 'sudo_user', 'connection', 'tags', 'gather_facts', 'serial', - 'any_errors_fatal', 'roles', 'pre_tasks', 'post_tasks' + 'any_errors_fatal', 'roles', 'pre_tasks', 'post_tasks', 'max_fail_pct' ] # ************************************************* @@ -101,9 +101,9 @@ class Play(object): self.sudo_user = ds.get('sudo_user', self.playbook.sudo_user) self.transport = ds.get('connection', self.playbook.transport) self.gather_facts = ds.get('gather_facts', None) - self.serial = int(ds.get('serial', 0)) self.remote_port = self.remote_port self.any_errors_fatal = ds.get('any_errors_fatal', False) + self.max_fail_pct = int(ds.get('max_fail_pct', 100)) load_vars = {} if self.playbook.inventory.basedir() is not None: