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

# {{ ansible_managed }}

from __future__ import print_function
from json import loads, dumps
import os


def cmd_exists(cmd):
    return any(
        os.access(os.path.join(path, cmd), os.X_OK)
        for path in os.environ["PATH"].split(os.pathsep)
    )


output = loads('''{{ {'installed': False,
                      'directory': tftpd__directory,
                      'upload_directory':
                        (tftpd__directory + "/" + tftpd__upload_directory)
                     } | to_nice_json }}''')

output['installed'] = cmd_exists('in.tftpd')

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