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
pull/9365/head
Brian Coca 9 years ago
parent b8336f222d
commit 056602c424

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

@ -121,29 +121,7 @@ class PlaybookExecutor:
if self._tqm is None:
# we are just doing a listing
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)
entry['plays'].append(new_play)
else:
# make sure the tqm has callbacks loaded

Loading…
Cancel
Save