[kwlug-disc] Saltstack multi-line replace

Mikalai Birukou mb at 3nsoft.com
Fri Apr 3 18:02:18 EDT 2020


I haven't used it, but reading 
https://docs.saltstack.com/en/latest/ref/states/all/salt.states.file.html#salt.states.file.line

suggests that there are before and after arguments. Can you try after = 
"video_resolution:" and some before, that should be present in the file. 
may be like comment "#end of video_resolution"?

And then mode arg should be chosen: ensure sounds appropriate to keep 
certain value.

My two cents :)

On 2020-04-03 5:42 p.m., Paul Nijjar via kwlug-disc wrote:
> As I have been learning Salt I have been figuring out different idioms
> for editing files. One way is to take control of the entire file
> (file.managed). Another is to edit line by line, using regexps to find
> the lines (file.line) . Now I am in a situation where there is a file
> I would prefer not to manage fully, but for which I cannot figure out
> how to edit lines because there is not enough context.
>
>
> The file is YAML, and looks something like this:
>
> video_resolution:
>    high:
>      - fooblaz: xyz
>      - quality: 200
>    medium:
>      - fooblaz: xyz
>      - quality: 100
>    low:
>      - fooblaz: zyy
>      - quality: 75
>
>
> Each of these elements has a "quality" element I would like to
> twiddle. I do not want all of the elements to be the same, and I want
> to twiddle them independently.
>
> file.managed would work but then I have to control a big file that
> might be changing in other ways.
>
> I cannot figure out how to use file.line .
>
> Are there other options?
>
> - Paul




More information about the kwlug-disc mailing list