Skip to content

[DOCS] In file.blockreplace "marker_end" cannot contain "marker_start" #64075

@leifb

Description

@leifb

Description
When using file.blockreplace, the end marker cannot contain the whole start marker. Example:

~/myfile:
  file.blockreplace:
    - marker_start: "# MARKER"
    - marker_end: "# MARKER END"

When doing so, salt will fail with the following error:

Encountered error managing block: Unterminated marked block. End of file reached before marker_end.. See the log for details.

I assume the problem is that the second occurrence (end marker) will be matched when looking for the start marker.

When using in combination with append_if_not_found: true, the error will only appear after the second run.

Suggested Fix
In the documentation, this is technically covered where it says that the whole line containing the start marker will be used.
But i feel like there should be an extra mention that the two markers have to be differ.

Add something like this:

The markers cannot be the same or contain each other.

Maybe the state should also check for this and display a better error message.

Type of documentation
Salt state module for file

Location or format of documentation
salt.states.file.blockreplace

Additional context
Example sls:

Create file:
  file.managed:
    - name: ~/test_blockreplace
    - replace: False

Test blockreplace:
  file.blockreplace:
    - name: ~/test_blockreplace
    - content: "My content"
    - marker_start: "# MARKER"
    - marker_end: "# MARKER END"
    - append_if_not_found: true

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions