now listhosts shows the same info as v1
This commit is contained in:
parent
41d9bfde07
commit
a811c8841e
2 changed files with 17 additions and 7 deletions
|
@ -162,10 +162,11 @@ class PlaybookExecutor:
|
|||
|
||||
return serialized_batches
|
||||
|
||||
def listhosts(self):
|
||||
def list_hosts_per_play(self):
|
||||
|
||||
playlist = []
|
||||
try:
|
||||
i = 1
|
||||
for playbook_path in self._playbooks:
|
||||
pb = Playbook.load(playbook_path, variable_manager=self._variable_manager, loader=self._loader)
|
||||
for play in pb.get_entries():
|
||||
|
@ -175,10 +176,21 @@ class PlaybookExecutor:
|
|||
new_play = play.copy()
|
||||
new_play.post_validate(all_vars, fail_on_undefined=False)
|
||||
|
||||
playlist.append(set(self._inventory.get_hosts(new_play.hosts)))
|
||||
pname = play.get_name().strip()
|
||||
if pname == 'PLAY: <no name specified>':
|
||||
pname = 'play #%d' % i
|
||||
|
||||
playlist.append( {
|
||||
'name': pname,
|
||||
'pattern': play.hosts,
|
||||
'hosts': set(self._inventory.get_hosts(new_play.hosts)),
|
||||
} )
|
||||
i = i + 1
|
||||
|
||||
except AnsibleError:
|
||||
raise
|
||||
except Exception, e:
|
||||
#TODO: log exception
|
||||
raise AnsibleParserError("Failed to process plays: %s" % str(e))
|
||||
|
||||
return playlist
|
||||
|
|
|
@ -135,12 +135,10 @@ def main(args):
|
|||
pbex = PlaybookExecutor(playbooks=args, inventory=inventory, variable_manager=variable_manager, loader=loader, display=display, options=options)
|
||||
|
||||
if options.listhosts:
|
||||
i = 1
|
||||
for play in pbex.listhosts():
|
||||
print("\nplay #%d" % i)
|
||||
for host in sorted(play):
|
||||
for p in pbex.list_hosts_per_play():
|
||||
print("\n %s (%s): host count=%d" % (p['name'], p['pattern'], len(p['hosts'])))
|
||||
for host in p['hosts']:
|
||||
print(" %s" % host)
|
||||
i = i + 1
|
||||
sys.exit(0)
|
||||
elif options.listtasks:
|
||||
print('TODO: implement')
|
||||
|
|
Loading…
Reference in a new issue