def METHOD_NAME(template_text, file_path):
    variable_matches = re.findall(GLOBAL_PATTERN, template_text)
    if not variable_matches:
        return 0, template_text
    for var_name in variable_matches:
        text_to_replace = '__ENV_[' + var_name + ']__'
        try:
            var_value = os.environ[var_name]
        except KeyError:
            sys.stderr.write(
                'Variable {} in {} could not be replaced, '
                ' because the env var {} is unset'.format(
                    text_to_replace, file_path, var_name))
            sys.exit(1)
        logging.info(REPLACE_LOGTEXT.format(text_to_replace,
                                            var_value,
                                            file_path))
        template_text = template_text.replace(text_to_replace, var_value)
    return len(variable_matches), template_text