Parsing template

def _parse_environment(env_str):
    '''
    Parsing template
    '''
    try:
        env = salt.utils.yaml.safe_load(env_str)
    except salt.utils.yaml.YAMLError as exc:
        raise ValueError(six.text_type(exc))
    else:
        if env is None:
            env = {}
        elif not isinstance(env, dict):
            raise ValueError(
                'The environment is not a valid YAML mapping data type.'
            )

    for param in env:
        if param not in SECTIONS:
            raise ValueError('environment has wrong section "{0}"'.format(param))

    return env