mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Create Play objects for --list-hosts to mimic actual behaviour
This makes --list-hosts work more like actually running the playbook, and thus gets the correct hosts with regard to includes and similar. Fixes #1959.
This commit is contained in:
parent
a79373f6b2
commit
9a34c20cc5
1 changed files with 7 additions and 13 deletions
|
@ -125,20 +125,14 @@ def main(args):
|
|||
if options.listhosts:
|
||||
print 'playbook: %s' % playbook
|
||||
playnum = 0
|
||||
for play in pb.playbook:
|
||||
for (play_ds, play_basedir) in zip(pb.playbook, pb.play_basedirs):
|
||||
playnum += 1
|
||||
if 'hosts' in play:
|
||||
label = 'unnamed'
|
||||
if 'name' in play:
|
||||
label = play['name']
|
||||
tmp_hosts = play['hosts']
|
||||
if isinstance(tmp_hosts, list):
|
||||
tmp_hosts = ':'.join(tmp_hosts)
|
||||
tmp_hosts = utils.template(pb.basedir, tmp_hosts, extra_vars)
|
||||
hosts = pb.inventory.list_hosts(tmp_hosts)
|
||||
print ' hosts in play %s (%s): #%d' % (playnum, label, len(hosts))
|
||||
for host in hosts:
|
||||
print ' %s' % host
|
||||
play = ansible.playbook.Play(pb, play_ds, play_basedir)
|
||||
label = play.name
|
||||
hosts = pb.inventory.list_hosts(play.hosts)
|
||||
print ' hosts in play %s (%s): #%d' % (playnum, label, len(hosts))
|
||||
for host in hosts:
|
||||
print ' %s' % host
|
||||
continue
|
||||
|
||||
if options.syntax:
|
||||
|
|
Loading…
Reference in a new issue