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

# {{ ansible_managed }}

from __future__ import print_function
from json import load, dumps
import subprocess
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)
    )


password_file = '/etc/snmp/ansible-local-password.json'

output = {'installed': cmd_exists('snmpd')}

if os.path.exists(password_file) and os.path.isfile(password_file):
    try:
        with open(password_file, 'r') as f:
            output.update(load(f))
    except Exception:
        pass

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