def set_value(data, search_key, new_value):
    """Sets a new value for a template key.

    :param data: The data structure to update.
    :type dict
    :param search_key: The key to search and update.
    :param new_value: The new value to set.
    """
    is_set = False
    if isinstance(data, dict):
        bucket = []
        for key, value in data.iteritems():
            if key == search_key:
                data[key] = new_value
                is_set = True
                break
            else:
                bucket.append(value)
        if bucket and not is_set:
            for element in bucket:
                if isinstance(element, list):
                    for element in element:
                        bucket.append(element)
                elif isinstance(element, dict):
                    for key, value in element.iteritems():
                        if key == search_key:
                            element[key] = new_value
                            is_set = True
                            break
                        else:
                            bucket.append(value)
                if is_set:
                    break
