saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.13k stars 5.47k forks source link

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

Open leifb opened 1 year ago

leifb commented 1 year ago

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
barbaricyawps commented 1 year ago

Great news! We have a community member who is working on improving the file module documentation and is preparing a PR as we speak. I'll make sure it gets seen!