mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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
|
return serialized_batches
|
||||||
|
|
||||||
def listhosts(self):
|
def list_hosts_per_play(self):
|
||||||
|
|
||||||
playlist = []
|
playlist = []
|
||||||
try:
|
try:
|
||||||
|
i = 1
|
||||||
for playbook_path in self._playbooks:
|
for playbook_path in self._playbooks:
|
||||||
pb = Playbook.load(playbook_path, variable_manager=self._variable_manager, loader=self._loader)
|
pb = Playbook.load(playbook_path, variable_manager=self._variable_manager, loader=self._loader)
|
||||||
for play in pb.get_entries():
|
for play in pb.get_entries():
|
||||||
|
@ -175,10 +176,21 @@ class PlaybookExecutor:
|
||||||
new_play = play.copy()
|
new_play = play.copy()
|
||||||
new_play.post_validate(all_vars, fail_on_undefined=False)
|
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:
|
except AnsibleError:
|
||||||
raise
|
raise
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
#TODO: log exception
|
||||||
raise AnsibleParserError("Failed to process plays: %s" % str(e))
|
raise AnsibleParserError("Failed to process plays: %s" % str(e))
|
||||||
|
|
||||||
return playlist
|
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)
|
pbex = PlaybookExecutor(playbooks=args, inventory=inventory, variable_manager=variable_manager, loader=loader, display=display, options=options)
|
||||||
|
|
||||||
if options.listhosts:
|
if options.listhosts:
|
||||||
i = 1
|
for p in pbex.list_hosts_per_play():
|
||||||
for play in pbex.listhosts():
|
print("\n %s (%s): host count=%d" % (p['name'], p['pattern'], len(p['hosts'])))
|
||||||
print("\nplay #%d" % i)
|
for host in p['hosts']:
|
||||||
for host in sorted(play):
|
|
||||||
print(" %s" % host)
|
print(" %s" % host)
|
||||||
i = i + 1
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
elif options.listtasks:
|
elif options.listtasks:
|
||||||
print('TODO: implement')
|
print('TODO: implement')
|
||||||
|
|
Loading…
Reference in a new issue