Change the retry logic to write a limit file, able to source limit from files by indicating with @filename
This commit is contained in:
parent
c695aa2d6a
commit
0d530f3bf0
3 changed files with 25 additions and 67 deletions
|
@ -192,7 +192,7 @@ def main(args):
|
||||||
if len(failed_hosts) > 0:
|
if len(failed_hosts) > 0:
|
||||||
filename = pb.generate_retry_inventory(failed_hosts)
|
filename = pb.generate_retry_inventory(failed_hosts)
|
||||||
if filename:
|
if filename:
|
||||||
print " to rerun against failed hosts only, use -i %s\n" % filename
|
print " to retry, use: --limit @%s\n" % filename
|
||||||
|
|
||||||
for h in hosts:
|
for h in hosts:
|
||||||
t = pb.stats.summarize(h)
|
t = pb.stats.summarize(h)
|
||||||
|
|
|
@ -330,7 +330,17 @@ class Inventory(object):
|
||||||
self._subset = None
|
self._subset = None
|
||||||
else:
|
else:
|
||||||
subset_pattern = subset_pattern.replace(',',':')
|
subset_pattern = subset_pattern.replace(',',':')
|
||||||
self._subset = subset_pattern.replace(";",":").split(":")
|
subset_pattern = subset_pattern.replace(";",":").split(":")
|
||||||
|
results = []
|
||||||
|
# allow Unix style @filename data
|
||||||
|
for x in subset_pattern:
|
||||||
|
if x.startswith("@"):
|
||||||
|
fd = open(x[1:])
|
||||||
|
results.extend(fd.read().split("\n"))
|
||||||
|
fd.close()
|
||||||
|
else:
|
||||||
|
results.append(x)
|
||||||
|
self._subset = results
|
||||||
|
|
||||||
def lift_restriction(self):
|
def lift_restriction(self):
|
||||||
""" Do not restrict list operations """
|
""" Do not restrict list operations """
|
||||||
|
|
|
@ -426,78 +426,26 @@ class PlayBook(object):
|
||||||
variable information in group_vars/host_vars but that is ok, and expected.
|
variable information in group_vars/host_vars but that is ok, and expected.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# TODO: move this into an inventory.serialize() method
|
|
||||||
|
|
||||||
buf = StringIO.StringIO()
|
buf = StringIO.StringIO()
|
||||||
|
for x in replay_hosts:
|
||||||
|
buf.write("%s\n" % x)
|
||||||
|
basedir = self.inventory.basedir()
|
||||||
|
filename = "%s.retry" % os.path.basename(self.filename)
|
||||||
|
|
||||||
buf.write("# dynamically generated inventory file\n")
|
if not os.path.exists('/var/tmp/ansible'):
|
||||||
buf.write("# retries previously failed hosts only\n")
|
try:
|
||||||
buf.write("\n")
|
os.makedirs('/var/tmp/ansible')
|
||||||
|
except:
|
||||||
inventory = self.inventory
|
pass
|
||||||
basedir = inventory.basedir()
|
filename = os.path.join('/var/tmp/ansible', filename)
|
||||||
filename = ".%s.retry" % os.path.basename(self.filename)
|
|
||||||
filename = os.path.join(basedir, filename)
|
|
||||||
|
|
||||||
def _simple_kv_vars(host_vars):
|
|
||||||
buf = ""
|
|
||||||
for (k, v) in host_vars.items():
|
|
||||||
if type(v) not in [ list, dict ]:
|
|
||||||
if isinstance(v,basestring):
|
|
||||||
buf = buf + " %s=%s" % (k, pipes.quote(v))
|
|
||||||
else:
|
|
||||||
buf = buf + " %s=%s" % (k, v)
|
|
||||||
return buf
|
|
||||||
|
|
||||||
# for all group names
|
|
||||||
for gname in inventory.groups_list():
|
|
||||||
|
|
||||||
# write the group name
|
|
||||||
group = inventory.get_group(gname)
|
|
||||||
group_vars = inventory.get_group_variables(gname)
|
|
||||||
|
|
||||||
# but only contain hosts that we want to replay
|
|
||||||
hostz = [ host.name for host in group.hosts ]
|
|
||||||
hostz = [ hname for hname in hostz if hname in replay_hosts ]
|
|
||||||
if len(hostz):
|
|
||||||
buf.write("[%s]\n" % group.name)
|
|
||||||
for hostname in hostz:
|
|
||||||
host = inventory.get_host(hostname)
|
|
||||||
host_vars = host.vars
|
|
||||||
hostname_vars = _simple_kv_vars(host_vars)
|
|
||||||
buf.write("%s %s\n" % (hostname, hostname_vars))
|
|
||||||
buf.write("\n")
|
|
||||||
|
|
||||||
# write out any child groups if present
|
|
||||||
if len(group.child_groups) and group.name not in [ 'all', 'ungrouped' ]:
|
|
||||||
buf.write("\n")
|
|
||||||
buf.write("[%s:children]\n" % gname)
|
|
||||||
for child_group in group.child_groups:
|
|
||||||
buf.write("%s\n" % child_group.name)
|
|
||||||
buf.write("\n")
|
|
||||||
|
|
||||||
# we do NOT write out group variables because they will have already
|
|
||||||
# been blended with the host
|
|
||||||
|
|
||||||
if len(group_vars.keys()) > 0 and group.name not in [ 'all', 'ungrouped' ]:
|
|
||||||
buf.write("[%s:vars]\n" % gname)
|
|
||||||
for (k,v) in group_vars.items():
|
|
||||||
if type(v) not in [list,dict]:
|
|
||||||
if isinstance(type(k), basestring):
|
|
||||||
buf.write("%s='%s'\n" % (k,v))
|
|
||||||
else:
|
|
||||||
buf.write("%s=%s\n" % (k,v))
|
|
||||||
buf.write("\n")
|
|
||||||
|
|
||||||
# if file isn't writeable, don't do anything.
|
|
||||||
# TODO: allow a environment variable to pick a different destination for this file
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fd = open(filename, 'w')
|
fd = open(filename, 'w')
|
||||||
fd.write(buf.getvalue())
|
fd.write(buf.getvalue())
|
||||||
fd.close()
|
fd.close()
|
||||||
return filename
|
return filename
|
||||||
except Exception, e:
|
except:
|
||||||
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# *****************************************************
|
# *****************************************************
|
||||||
|
|
Loading…
Reference in a new issue