Dynamic file content?

30 views
Skip to first unread message

Dave F

unread,
Nov 17, 2017, 10:16:40 AM11/17/17
to Puppet Users
Hi, 

I'm fairly new to puppet and am working my way through various approaches to problems - probably doing them in all the worst possible ways...

One thing I'm currently trying to do is configure an application using heira and puppet. The application comes with a selection of default template configuration files which I'm using Augeas in Puppet to configure with the valies from heira as required. 

Essentially my class is doing the following:

file{'config.file': 
  source=> "file://src/template.xml",
  path => "$destfolder/template.xml"
} -> 
augeas {"config.file_aug":
lens => "xml.lns",
incl => "$destfolder/template.xml",
changes => [ "setm... "]
}

Now, this is working... but what of course what's happening is that every time puppet runs, the first file resource replaces the template.xml with the original copy, then the augeas re-edits it to match the file that was just replaced. 

I could make sure the file resource doesn't replace the new one with 'replace -> false', but then if unwanted changes occur, we'd never know. 

How can I combine a the required augeas changes to the xml template file before it's checked?  

Should I use puppet to construct the new version in a temporary folder, and the do a final file resource to compare the constructed version with the live version?

Thanks in advance,
Dave

Chris Denneen

unread,
Nov 18, 2017, 9:07:41 AM11/18/17
to Puppet Users
Can you use an ERB template to construct the changes you require rather than augeas?
If not another suggestion would be 1 file resource from src to temp location, which only gets updated when src changes. An Exec that is refreshonly that copies from temp to dest (which is notified by file resource) and finally Augeas that updates dest file.
The template is obviously your most efficient method using a single resource.

Martin Alfke

unread,
Nov 18, 2017, 9:40:11 AM11/18/17
to puppet...@googlegroups.com
Hi Chris,

> On 18 Nov 2017, at 15:07, Chris Denneen <cden...@gmail.com> wrote:
>
> Can you use an ERB template to construct the changes you require rather than augeas?

There is a new template engine since Puppet 4: EPP (Embedded Puppet)
This prevents people from doing weird ruby stuff in a file.
Templates should be used to only present data.

> If not another suggestion would be 1 file resource from src to temp location, which only gets updated when src changes. An Exec that is refreshonly that copies from temp to dest (which is notified by file resource) and finally Augeas that updates dest file.

No no no. Please don’t do a tempfile and an exec resource. Use a template instead.


> The template is obviously your most efficient method using a single resource.
Yes!

Chris Denneen

unread,
Nov 19, 2017, 11:38:05 PM11/19/17
to Puppet Users
Martin,
Obviously with templates being my first and last recommendation the Exec wasn’t my choice either but there are always different ways to skin a cat and not knowing why the OP hasn’t used them could be because they aren’t an option, I obviously hope not but without knowing background I was just providing options.

Chris

Martin Alfke

unread,
Nov 20, 2017, 7:28:42 AM11/20/17
to puppet...@googlegroups.com
Hi Chris,

no worries, I hope that I didn’t offend you.
Usually I try to tell people the best solution first and go for hacks afterwards.
This allows them to first learn about the concepts.

Best,
Martin
> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/0b417cbc-531c-4357-bd50-4f1f485fc238%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages