Change config file by puppet – depend hostname

puppetpuppetmaster

I want to push some config file to my all servers by puppet. File is almost the same for all servers, but there is one change – hostname.

I've created module in puppet with manifest and temp-conf-file. I include to all node. All is fine.

My question is: how can i push that file to all server with change one/two lines in that file. But i don't want to set config file in modules for all. I want to use one file and during the push change in side two lines.

Thank you for help.

Best,

Rafal

Best Answer

I would use a template. Set your file resource to use content instead of source:

content => template("mymodule/temp-conf-file.erb"),

Then have the template substitute the hostname. The template would be located in the templates subdirectory of your module:

# This file is managed by puppet
... random config stuff ...
hostname = <%= hostname %>

You can also use fqdn or something else.

Official documentation: https://puppet.com/docs/puppet/latest/lang_template.html