rearranged --list- options, now they are consolidated when used toghether, less loops, more concise output

list-hosts works
list-tasks works, but needs better task naming (missing role info)
list-tags only shows play tags
This commit is contained in:
Brian Coca 2015-07-28 22:03:50 -04:00
parent b8336f222d
commit 056602c424
2 changed files with 36 additions and 34 deletions

View file

@ -151,19 +151,43 @@ class PlaybookCLI(CLI):
for p in results: for p in results:
self.display.display('\nplaybook: %s\n' % p['playbook']) self.display.display('\nplaybook: %s\n' % p['playbook'])
i = 1
for play in p['plays']: for play in p['plays']:
if play.name:
playname = play.name
else:
playname = '#' + str(i)
msg = "\n PLAY: %s" % (playname)
if self.options.listtags:
mytags = set(play.tags)
msg += '\n total tags: %d' % (len(mytags))
msg += '\n tags: [%s]' % (','.join(mytags))
if self.options.listhosts: if self.options.listhosts:
self.display.display("\n %s (%s): host count=%d" % (play['name'], play['pattern'], len(play['hosts']))) playhosts = set(inventory.get_hosts(play.hosts))
for host in play['hosts']: msg += "\n pattern: %s\n total hosts: %d\n hosts:" % (play.hosts, len(playhosts))
self.display.display(" %s" % host) for host in playhosts:
if self.options.listtasks: #TODO: do we want to display block info? msg += "\n %s" % host
self.display.display("\n %s" % (play['name']))
for task in play['tasks']: self.display.display(msg)
self.display.display(" %s" % task)
if self.options.listtags: #TODO: fix once we figure out block handling above if self.options.listtags or self.options.listtasks:
self.display.display("\n %s: tags count=%d" % (play['name'], len(play['tags']))) j = 1
for tag in play['tags']: taskmsg = ' tasks:'
self.display.display(" %s" % tag) for task in play.get_tasks():
taskmsg += "\n %s" % task
if self.options.listtags:
pass
#for task in play.get_tasks():
# mytags.union(set(task.tags))
#self.display.display(" %s" % ','.join(mytags))
j = j + 1
self.display.display(taskmsg)
i = i + 1
return 0 return 0
else: else:
return results return results

View file

@ -121,29 +121,7 @@ class PlaybookExecutor:
if self._tqm is None: if self._tqm is None:
# we are just doing a listing # we are just doing a listing
entry['plays'].append(new_play)
pname = new_play.get_name().strip()
if pname == 'PLAY: <no name specified>':
pname = 'PLAY: #%d' % i
p = { 'name': pname }
if self._options.listhosts:
p['pattern']=play.hosts
p['hosts']=set(self._inventory.get_hosts(new_play.hosts))
#TODO: play tasks are really blocks, need to figure out how to get task objects from them
elif self._options.listtasks:
p['tasks'] = []
for task in play.get_tasks():
p['tasks'].append(task)
#p['tasks'].append({'name': task.get_name().strip(), 'tags': task.tags})
elif self._options.listtags:
p['tags'] = set(new_play.tags)
for task in play.get_tasks():
p['tags'].update(task)
#p['tags'].update(task.tags)
entry['plays'].append(p)
else: else:
# make sure the tqm has callbacks loaded # make sure the tqm has callbacks loaded