mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07:00
Adds the 'serial' keyword to a playbook which controls how many hosts can be running through a playbook at a single time.
The default is 0, which means all hosts. If set to 1, each host would run a playbook all the way through before moving on the next host. Fact gathering is still parallel, regardless of the serial setting.
This commit is contained in:
parent
e13c33bb86
commit
898d7676f7
4 changed files with 62 additions and 23 deletions
|
@ -150,8 +150,8 @@ class PlayBook(object):
|
|||
# loop through all patterns and run them
|
||||
self.callbacks.on_start()
|
||||
for play_ds in self.playbook:
|
||||
self._run_play(Play(self,play_ds))
|
||||
|
||||
play = Play(self,play_ds)
|
||||
self._run_play(play)
|
||||
# summarize the results
|
||||
results = {}
|
||||
for host in self.stats.processed.keys():
|
||||
|
@ -301,22 +301,43 @@ class PlayBook(object):
|
|||
self._do_setup_step(play)
|
||||
|
||||
# now with that data, handle contentional variable file imports!
|
||||
play.update_vars_files(self.inventory.list_hosts(play.hosts))
|
||||
|
||||
for task in play.tasks():
|
||||
# only run the task if the requested tags match
|
||||
should_run = False
|
||||
for x in self.only_tags:
|
||||
for y in task.tags:
|
||||
if (x==y):
|
||||
should_run = True
|
||||
break
|
||||
if should_run:
|
||||
self._run_task(play, task, False)
|
||||
all_hosts = self.inventory.list_hosts(play.hosts)
|
||||
play.update_vars_files(all_hosts)
|
||||
|
||||
serialized_batch = []
|
||||
if play.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(1, play.serial):
|
||||
if len(all_hosts) > 0:
|
||||
play_hosts.append(all_hosts.pop())
|
||||
serialized_batch.append(play_hosts)
|
||||
|
||||
for on_hosts in serialized_batch:
|
||||
|
||||
self.inventory.also_restrict_to(on_hosts)
|
||||
|
||||
for task in play.tasks():
|
||||
# only run the task if the requested tags match
|
||||
should_run = False
|
||||
for x in self.only_tags:
|
||||
for y in task.tags:
|
||||
if (x==y):
|
||||
should_run = True
|
||||
break
|
||||
if should_run:
|
||||
self._run_task(play, task, False)
|
||||
|
||||
# run notify actions
|
||||
for handler in play.handlers():
|
||||
if len(handler.notified_by) > 0:
|
||||
self.inventory.restrict_to(handler.notified_by)
|
||||
self._run_task(play, handler, True)
|
||||
self.inventory.lift_restriction()
|
||||
|
||||
self.inventory.lift_also_restriction()
|
||||
|
||||
# run notify actions
|
||||
for handler in play.handlers():
|
||||
if len(handler.notified_by) > 0:
|
||||
self.inventory.restrict_to(handler.notified_by)
|
||||
self._run_task(play, handler, True)
|
||||
self.inventory.lift_restriction()
|
||||
|
|
|
@ -29,7 +29,7 @@ class Play(object):
|
|||
'hosts', 'name', 'vars', 'vars_prompt', 'vars_files',
|
||||
'handlers', 'remote_user', 'remote_port',
|
||||
'sudo', 'sudo_user', 'transport', 'playbook',
|
||||
'tags', 'gather_facts', '_ds', '_handlers', '_tasks'
|
||||
'tags', 'gather_facts', 'serial', '_ds', '_handlers', '_tasks'
|
||||
]
|
||||
|
||||
# to catch typos and so forth -- these are userland names
|
||||
|
@ -37,7 +37,7 @@ class Play(object):
|
|||
VALID_KEYS = [
|
||||
'hosts', 'name', 'vars', 'vars_prompt', 'vars_files',
|
||||
'tasks', 'handlers', 'user', 'port', 'include',
|
||||
'sudo', 'sudo_user', 'connection', 'tags', 'gather_facts'
|
||||
'sudo', 'sudo_user', 'connection', 'tags', 'gather_facts', 'serial'
|
||||
]
|
||||
|
||||
# *************************************************
|
||||
|
@ -75,6 +75,7 @@ class Play(object):
|
|||
self.transport = ds.get('connection', self.playbook.transport)
|
||||
self.tags = ds.get('tags', None)
|
||||
self.gather_facts = ds.get('gather_facts', True)
|
||||
self.serial = ds.get('serial', 0)
|
||||
|
||||
self._update_vars_files_for_host(None)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue