#!{{ 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 = {'installed': cmd_exists('rsnapshot'),
          'ssh_identities': {}}

try:
    for filename in os.listdir('/root/.ssh'):
        if filename.endswith('.pub'):
            with open('/root/.ssh/' + filename, 'r') as f:
                for line in f:
                    output['ssh_identities'].update({
                        filename.rstrip('.pub'): line})

except Exception:
    pass

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