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:
Michael DeHaan 2012-08-18 09:52:13 -04:00
commit 898d7676f7
4 changed files with 62 additions and 23 deletions

View file

@ -34,7 +34,7 @@ class Inventory(object):
Host inventory for ansible.
"""
__slots__ = [ 'host_list', 'groups', '_restriction', '_subset', '_is_script',
__slots__ = [ 'host_list', 'groups', '_restriction', '_also_restriction', '_subset', '_is_script',
'parser', '_vars_per_host', '_vars_per_group', '_hosts_cache' ]
def __init__(self, host_list=C.DEFAULT_HOST_LIST):
@ -55,6 +55,7 @@ class Inventory(object):
# a list of host(names) to contain current inquiries to
self._restriction = None
self._also_restriction = None
self._subset = None
# whether the inventory file is a script
@ -122,6 +123,8 @@ class Inventory(object):
# exclude hosts mentioned in any restriction (ex: failed hosts)
if self._restriction is not None:
hosts = [ h for h in hosts if h.name in self._restriction ]
if self._also_restriction is not None:
hosts = [ h for h in hosts if h.name in self._also_restriction ]
return sorted(hosts, key=lambda x: x.name)
@ -281,6 +284,7 @@ class Inventory(object):
def list_groups(self):
return sorted([ g.name for g in self.groups ], key=lambda x: x.name)
# TODO: remove this function
def get_restriction(self):
return self._restriction
@ -294,6 +298,15 @@ class Inventory(object):
restriction = [ restriction ]
self._restriction = restriction
def also_restrict_to(self, restriction):
"""
Works like restict_to but offers an additional restriction. Playbooks use this
to implement serial behavior.
"""
if type(restriction) != list:
restriction = [ restriction ]
self._also_restriction = restriction
def subset(self, subset_pattern):
"""
Limits inventory results to a subset of inventory that matches a given
@ -308,8 +321,11 @@ class Inventory(object):
def lift_restriction(self):
""" Do not restrict list operations """
self._restriction = None
def lift_also_restriction(self):
""" Clears the also restriction """
self._also_restriction = None
def is_file(self):
""" did inventory come from a file? """