.. versionadded:: 2019.2.0

    Replace content of the configuration source, delimited by the line markers.

    A block of content delimited by comments can help you manage several lines
    without worrying about old entries removal.

    marker_start
        The line content identifying a line as the start of the content block.
        Note that the whole line containing this marker will be considered,
        so whitespace or extra content before or after the marker is included
        in final output.

    marker_end
        The line content identifying a line as the end of the content block.
        Note that the whole line containing this marker will be considered,
        so whitespace or extra content before or after the marker is included
        in final output.

    content
        The content to be used between the two lines identified by
        ``marker_start`` and ``marker_stop``.

    append_if_not_found: ``False``
        If markers are not found and set to True then, the markers and content
        will be appended to the file.

    prepend_if_not_found: ``False``
        If markers are not found and set to True then, the markers and content
        will be prepended to the file.

    append_newline: ``False``
        Controls whether or not a newline is appended to the content block.
        If the value of this argument is ``True`` then a newline will be added
        to the content block. If it is ``False``, then a newline will not be
        added to the content block. If it is ``None`` then a newline will only
        be added to the content block if it does not already end in a newline.

    show_changes: ``True``
        Controls how changes are presented. If ``True``, this function will
        return the of the changes made.
        If ``False``, then it will return a boolean (``True`` if any changes
        were made, otherwise False).

    source: ``running``
        The configuration source. Choose from: ``running``, ``candidate``, or
        ``startup``. Default: ``running``.

    path: ``None``
        Save the temporary configuration to a specific path, then read from
        there. This argument is optional, can be used when you prefers a
        particular location of the temporary file.

    test: ``False``
        Dry run? If set as ``True``, will apply the config, discard and return
        the changes. Default: ``False`` and will commit the changes on the
        device.

    commit: ``True``
        Commit the configuration changes? Default: ``True``.

    debug: ``False``
        Debug mode. Will insert a new key in the output dictionary, as
        ``loaded_config`` containing the raw configuration loaded on the device.

    replace: ``True``
        Load and replace the configuration. Default: ``True``.

    CLI Example:

    .. code-block:: bash

        salt '*' net.blockreplace 'ntp' 'interface' ''

def blockreplace(marker_start,
                 marker_end,
                 content='',
                 append_if_not_found=False,
                 prepend_if_not_found=False,
                 show_changes=True,
                 append_newline=False,
                 source='running',
                 path=None,
                 test=False,
                 commit=True,
                 debug=False,
                 replace=True):
    '''
    .. versionadded:: 2019.2.0

    Replace content of the configuration source, delimited by the line markers.

    A block of content delimited by comments can help you manage several lines
    without worrying about old entries removal.

    marker_start
        The line content identifying a line as the start of the content block.
        Note that the whole line containing this marker will be considered,
        so whitespace or extra content before or after the marker is included
        in final output.

    marker_end
        The line content identifying a line as the end of the content block.
        Note that the whole line containing this marker will be considered,
        so whitespace or extra content before or after the marker is included
        in final output.

    content
        The content to be used between the two lines identified by
        ``marker_start`` and ``marker_stop``.

    append_if_not_found: ``False``
        If markers are not found and set to True then, the markers and content
        will be appended to the file.

    prepend_if_not_found: ``False``
        If markers are not found and set to True then, the markers and content
        will be prepended to the file.

    append_newline: ``False``
        Controls whether or not a newline is appended to the content block.
        If the value of this argument is ``True`` then a newline will be added
        to the content block. If it is ``False``, then a newline will not be
        added to the content block. If it is ``None`` then a newline will only
        be added to the content block if it does not already end in a newline.

    show_changes: ``True``
        Controls how changes are presented. If ``True``, this function will
        return the of the changes made.
        If ``False``, then it will return a boolean (``True`` if any changes
        were made, otherwise False).

    source: ``running``
        The configuration source. Choose from: ``running``, ``candidate``, or
        ``startup``. Default: ``running``.

    path: ``None``
        Save the temporary configuration to a specific path, then read from
        there. This argument is optional, can be used when you prefers a
        particular location of the temporary file.

    test: ``False``
        Dry run? If set as ``True``, will apply the config, discard and return
        the changes. Default: ``False`` and will commit the changes on the
        device.

    commit: ``True``
        Commit the configuration changes? Default: ``True``.

    debug: ``False``
        Debug mode. Will insert a new key in the output dictionary, as
        ``loaded_config`` containing the raw configuration loaded on the device.

    replace: ``True``
        Load and replace the configuration. Default: ``True``.

    CLI Example:

    .. code-block:: bash

        salt '*' net.blockreplace 'ntp' 'interface' ''
    '''
    config_saved = save_config(source=source, path=path)
    if not config_saved or not config_saved['result']:
        return config_saved
    path = config_saved['out']
    replace_pattern = __salt__['file.blockreplace'](path,
                                                    marker_start=marker_start,
                                                    marker_end=marker_end,
                                                    content=content,
                                                    append_if_not_found=append_if_not_found,
                                                    prepend_if_not_found=prepend_if_not_found,
                                                    show_changes=show_changes,
                                                    append_newline=append_newline)
    with salt.utils.files.fopen(path, 'r') as fh_:
        updated_config = fh_.read()
    return __salt__['net.load_config'](text=updated_config,
                                       test=test,
                                       debug=debug,
                                       replace=replace,
                                       commit=commit)