[kwlug-disc] Saltstack multi-line replace
Paul Nijjar
paul_nijjar at yahoo.ca
Fri Apr 3 18:14:45 EDT 2020
That is only for insert or ensure. I would need replace. I have used
before and after before, but I am not sure they refer to a search
range.
file.blockreplace could work if I can figure out how to comment the
original block.
Another very bad idea might be to change "video_resolution" to
"video_resolution_bad". That should change the underlying dictionary,
and then I can use file.blockreplace to insert the new block that I
want. That is still not ideal but it might work better than
controlling the entire file. Hopefully the underlying application
consuming the YAML will just ignore the parts it does not recognise...
- Paul
On Fri, Apr 03, 2020 at 06:02:18PM -0400, Mikalai Birukou via kwlug-disc wrote:
> 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
>
> _______________________________________________
> kwlug-disc mailing list
> kwlug-disc at kwlug.org
> https://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org
--
Events: https://feeds.off-topic.kwlug.org
Blog: http://pnijjar.freeshell.org
More information about the kwlug-disc
mailing list