1- #! /usr/bin/env bash
2- # this is a very crude hack and can be removed once we have no more python2 systems
3- # that need to run this code
4- " exec" " $( command -v python3 || command -v python) " " $0 " " $@ "
1+ #!/usr/bin/env python3
52# Adapted from Mark Mandel's implementation
63# https://github.com/ansible/ansible/blob/devel/plugins/inventory/vagrant.py
74import argparse
85import json
9- import os
106import subprocess
117import sys
128import yaml
139
14- try:
15- from StringIO import StringIO # pyright: reportMissingImports=false
16- except ImportError:
17- from io import StringIO # pyright: reportMissingImports=false
18-
1910from collections import defaultdict
2011
2112
22- try:
23- DEVNULL = subprocess.DEVNULL
24- except AttributeError:
25- DEVNULL = open(os.devnull, ' w' )
26-
27-
2813def parse_args ():
2914 parser = argparse .ArgumentParser (description = "Vagrant inventory script" )
3015 group = parser .add_mutually_exclusive_group (required = True )
@@ -36,7 +21,7 @@ def parse_args():
3621
3722def get_running_hosts ():
3823 try :
39- subprocess.check_call([" which" , " vagrant" ], stdout=DEVNULL)
24+ subprocess .check_call (["which" , "vagrant" ], stdout = subprocess . DEVNULL )
4025 except subprocess .CalledProcessError :
4126 return
4227
@@ -70,7 +55,7 @@ def list_running_hosts():
7055def get_ssh_configs (hosts ):
7156 cmd = ['vagrant' , 'ssh-config' ] + hosts
7257 try :
73- output = subprocess.check_output(cmd, universal_newlines=True, stderr=DEVNULL)
58+ output = subprocess .check_output (cmd , universal_newlines = True , stderr = subprocess . DEVNULL )
7459 except subprocess .CalledProcessError :
7560 return None
7661
0 commit comments