#!{{ ansible_python['executable'] }}

# {{ ansible_managed }}

from __future__ import print_function
from json import dumps
import subprocess

output = {"installed": True}

try:
    java_version_output = subprocess.check_output(
        ['java', '-version'],
        stderr=subprocess.STDOUT).decode('utf-8').split('\n')

except subprocess.CalledProcessError:
    pass

if java_version_output:
    for line in java_version_output:
        if 'version' in line:
            output['version'] = line.split()[2].strip('"').split('_')[0]

print(dumps(output, sort_keys=True, indent=4))
