From cbf0bd6baf57ab1ab5e53082db5adfc6e72a9b66 Mon Sep 17 00:00:00 2001 From: Howard Oettle Date: Wed, 27 Nov 2013 10:59:12 +0000 Subject: [PATCH] playbook: permit the serial attribute to be a pecentage string as well as well as a straight integer --- lib/ansible/playbook/__init__.py | 17 +++++++++++++++-- lib/ansible/playbook/play.py | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 051ab5a624..f037315e89 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -637,14 +637,27 @@ class PlayBook(object): play.update_vars_files(all_hosts, vault_password=self.vault_password) hosts_count = len(all_hosts) + if play.serial.endswith("%"): + + # This is a percentage, so calculate it based on the + # number of hosts + serial_pct = int(play.serial.replace("%","")) + serial = int((serial_pct)/100.0 * len(all_hosts)) + + # Ensure that no matter how small the percentage, serial + # can never fall below 1, so that things actually happen + serial = max(serial, 1) + else: + serial = int(play.serial) + serialized_batch = [] - if play.serial <= 0: + if serial <= 0: serialized_batch = [all_hosts] else: # do N forks all the way through before moving to next while len(all_hosts) > 0: play_hosts = [] - for x in range(play.serial): + for x in range(serial): if len(all_hosts) > 0: play_hosts.append(all_hosts.pop()) serialized_batch.append(play_hosts) diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index 28e098ff40..ed838f7db3 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -113,7 +113,7 @@ class Play(object): raise errors.AnsibleError('hosts declaration is required') elif isinstance(hosts, list): hosts = ';'.join(hosts) - self.serial = int(ds.get('serial', 0)) + self.serial = str(ds.get('serial', 0)) self.hosts = hosts self.name = ds.get('name', self.hosts) self._tasks = ds.get('tasks', [])