inserting a fragment of data into a file that changes during runtime

asked 2016-10-13 13:25:27 -0500

I have a file in which the application prepends data to during runtime. There is no Augeas lense for this file. And I need a text block to be inserted into this file. Any ideas?

Here are some of the ideas I've considered;

file_line with a crazy gigantic regex. But there's no way I can think of to remove the file in the case that the regex does not match. Maybe there's a module out there which allows a regex on a file, where I could use an "if" statement to see if my text block exists, and if it doesn't, use a simple file template?

Use an exec statement. Ughh....

edit retag flag offensive close merge delete

Comments

This doesn't sound like a puppet functionality. It is supposed to be used to maintain a state. That being said some type of log rotation type solutions sounds applicable here. perhaps some kind of copy to text to file, copy the original to the end, and rename?

puser gravatar imagepuser ( 2016-10-13 13:50:46 -0500 )edit

I had a similar problem, but fortunately it was an XML file so I could use the xml lens. Other than writing your own custom lens, I don't know of a good way to manage that.

DarylW gravatar imageDarylW ( 2016-10-17 08:59:28 -0500 )edit
1

IF you have a default starting value, and after that point you want to just 'not manage' the content of the file, you can use the replace parameter.. https://docs.puppet.com/puppet/latest/reference/type.html#file-attribute-replace

DarylW gravatar imageDarylW ( 2016-10-17 09:01:10 -0500 )edit

A bit late here... but this is good advice. Initialize it and then leave it. Then we can check in "replace => true" if we need to change something.

luksi1 gravatar imageluksi1 ( 2017-02-10 06:09:36 -0500 )edit