moved from callback_output to popen to keep 2.6 compat

pull/10138/head
Brian Coca 10 years ago
parent 368285b351
commit d4a89c8ead

@ -16,7 +16,7 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import sys import sys
from subprocess import check_output from subprocess import Popen,PIPE
try: try:
import json import json
@ -32,17 +32,17 @@ def get_hosts(host=None):
returned = {} returned = {}
try: try:
if host: if host:
results = check_output([VBOX, 'showvminfo', host]) p = Popen([VBOX, 'showvminfo', host], stdout=PIPE)
else: else:
returned = { 'all': set(), '_metadata': {} } returned = { 'all': set(), '_metadata': {} }
results = check_output([VBOX, 'list', '-l', 'vms']) p = Popen([VBOX, 'list', '-l', 'vms'], stdout=PIPE)
except: except:
sys.exit(1) sys.exit(1)
hostvars = {} hostvars = {}
prevkey = pref_k = '' prevkey = pref_k = ''
for line in results.splitlines(): for line in p.stdout.readlines():
try: try:
k,v = line.split(':',1) k,v = line.split(':',1)
@ -58,9 +58,10 @@ def get_hosts(host=None):
curname = v curname = v
hostvars[curname] = {} hostvars[curname] = {}
try: # try to get network info try: # try to get network info
ip_info = check_output([VBOX, 'guestproperty', 'get', curname,"/VirtualBox/GuestInfo/Net/0/V4/IP"]) x = Popen([VBOX, 'guestproperty', 'get', curname,"/VirtualBox/GuestInfo/Net/0/V4/IP"],stdout=PIPE)
if 'Value' in ip_info: ipinfo = x.stdout.read()
a,ip = ip_info.split(':',1) if 'Value' in ipinfo:
a,ip = ipinfo.split(':',1)
hostvars[curname]['ansible_ssh_host'] = ip.strip() hostvars[curname]['ansible_ssh_host'] = ip.strip()
except: except:
pass pass

Loading…
Cancel
Save