From a075ec9831ba1096af41c1d8d20eaf1b8e2909f7 Mon Sep 17 00:00:00 2001 From: kavink Date: Wed, 4 Sep 2013 18:30:33 -0700 Subject: Bug fix for a crash, when any_errors_fatal is true Reported by Rumen: TASK: [fail FAIL] ************************************************************* skipping: [hostname.com] failed: [hostname.com] => {"failed": true} msg: Failed as requested from task Traceback (most recent call last): File "/usr/local/bin/ansible-playbook", line 268, in sys.exit(main(sys.argv[1:])) File "/usr/local/bin/ansible-playbook", line 208, in main pb.run() File "/Library/Python/2.7/site-packages/ansible/playbook/__init__.py", line 262, in run if not self._run_play(play): File "/Library/Python/2.7/site-packages/ansible/playbook/__init__.py", line 580, in _run_play if (hosts_count - len(host_list)) > int((play.max_fail_pct)/100.0 * hosts_count): TypeError: object of type 'NoneType' has no len() --- lib/ansible/playbook/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 63d5934fd3..0ad9a65c0c 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -573,11 +573,11 @@ class PlayBook(object): host_list = self._list_available_hosts(play.hosts) - 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): + # If threshold for max nodes failed is exceeded or if any_errors_fatal is true, bail out. + if ( + (task.any_errors_fatal and len(host_list) < hosts_count) or + ((hosts_count - len(host_list)) > int((play.max_fail_pct)/100.0 * hosts_count)) + ): host_list = None # if no hosts remain, drop out -- cgit v1.2.1 From c24f6f438ba95299f80e2c40a305e6f4ad698f97 Mon Sep 17 00:00:00 2001 From: Kavin Kankeshwar Date: Fri, 6 Sep 2013 22:37:17 -0700 Subject: Avoid ugly formatting due to a long if statement --- lib/ansible/playbook/__init__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 0ad9a65c0c..6700e4c3c9 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -573,11 +573,12 @@ class PlayBook(object): host_list = self._list_available_hosts(play.hosts) - # If threshold for max nodes failed is exceeded or if any_errors_fatal is true, bail out. - if ( - (task.any_errors_fatal and len(host_list) < hosts_count) or - ((hosts_count - len(host_list)) > int((play.max_fail_pct)/100.0 * hosts_count)) - ): + # Set max_fail_pct to 0, So if any hosts fails, bail out + if task.any_errors_fatal and len(host_list) < hosts_count: + play.max_fail_pct = 0 + + # 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 -- cgit v1.2.1 From bcc2a4b513c59bcdbbc441304587ea88d830ca59 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Mon, 9 Sep 2013 10:20:41 -0500 Subject: Minor fix so the any_errors_fatal value is checked properly --- lib/ansible/playbook/play.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index ea069f3221..4ebc1b6cb0 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -111,7 +111,7 @@ class Play(object): self.transport = ds.get('connection', self.playbook.transport) self.gather_facts = ds.get('gather_facts', None) self.remote_port = self.remote_port - self.any_errors_fatal = ds.get('any_errors_fatal', False) + self.any_errors_fatal = utils.boolean(ds.get('any_errors_fatal', 'false')) self.accelerate = utils.boolean(ds.get('accelerate', 'false')) self.accelerate_port = ds.get('accelerate_port', None) self.max_fail_pct = int(ds.get('max_fail_percentage', 100)) -- cgit v1.2.1