<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def alias_exists(alias, keystore_path=None, keystore_password='changeit'):
 """Checks if an alias already exists in a keystore :param alias: :param keystore_path: :param keystore_password: :return: (bool) True when the alias already exists in the keystore :raises: OSError """

    log = logging.getLogger(mod_logger + '.alias_exists')
    if not isinstance(alias, basestring):
        msg = 'alias arg must be a string'
        log.error(msg)
        raise OSError(msg)

    # Ensure JAVA_HOME is set
    log.debug('Determining JAVA_HOME...')
    try:
        java_home = os.environ['JAVA_HOME']
    except KeyError:
        msg = 'JAVA_HOME is required but not set'
        log.error(msg)
        raise OSError(msg)

    # Ensure keytool can be found
    keytool = os.path.join(java_home, 'bin', 'keytool')
    if not os.path.isfile(keytool):
        msg = 'keytool file not found: {f}'.format(f=keytool)
        log.error(msg)
        raise OSError(msg)

    # Find the cacerts file
    if keystore_path is None:
        keystore_path = os.path.join(java_home, 'lib', 'security', 'cacerts')

        # If the JRE cacerts location is not found, look for the JDK cacerts
        if not os.path .isfile(keystore_path):
            keystore_path = os.path.join(java_home, 'jre', 'lib', 'security', 'cacerts')
            if not os.path.isfile(keystore_path):
                msg = 'Unable to file cacerts file'
                log.error(msg)
                raise OSError(msg)

    log.info('Checking keystore {k} for alias: {a}...'.format(k=keystore_path, a=alias))

    # Build the keytool command
    command = [keytool, '-keystore', keystore_path, '-storepass', keystore_password, '-list']

    # Running the keytool list command
    log.debug('Running the keytool list command...')
    try:
        result = run_command(command)
    except CommandError:
        _, ex, trace = sys.exc_info()
        msg = 'There was a problem running keytool on keystore: {k}\n{e}'.format(k=keystore_path, e=str(ex))
        log.error(msg)
        raise OSError, msg, trace
    if result['code'] != 0:
        msg = 'keytool command exited with a non-zero code: {c}, and produced output: {o}'.format(
            c=result['code'], o=result['output'])
        log.error(msg)
        raise OSError(msg)

    # Check for the alias in the output
    if alias in result['output']:
        log.info('Found alias {a} in keystore: {k}'.format(a=alias, k=keystore_path))
        return True
    else:
        log.info('Alias {a} was not found in keystore: {k}'.format(a=alias, k=keystore_path))
        return False