playbook: permit the serial attribute to be a pecentage string as well as well as a straight integer
This commit is contained in:
parent
a2537cfe49
commit
cbf0bd6baf
2 changed files with 16 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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', [])
|
||||
|
|
Loading…
Reference in a new issue