Is there a way to deliver a customized file to a server via puppet
Solution 1:
What you're looking to do is called a template. It's a core feature of Puppet, and very useful. You write a file in eRB format that can use Ruby code and Facter variables to build a file. Here's an example:
file { '/etc/my_config_file':
ensure => present,
owner => 'root',
group => 'root',
mode => 0700,
content => template('module/my_config_file.erb'),
}
Now, in your module hierarchy under templates/
(not files/
), place a file my_config_file.erb
:
this=that
location=<%= LOCATION_NUMBER %>
bananas=tasty
The <%= %>
format says to execute some Ruby code and return the result. In this case, all facts are available as local variables, like ipaddress
, lsbmajdistrelease
or LOCATION_NUMBER
(your custom fact). You can also use any other Ruby code that doesn't directly return a result inside <% %>
, such as if
statements:
<% if LOCATION_NUMBER == 7 %>
custom_config=true
<% else %>
custom_config=false
<% end %>
Edit: As I re-read this answer, I'd like to suggest that you don't use capital letters for your Fact name. In Ruby, a variable that starts with a capital letter is immutable. While I'm not sure this is really an issue, it goes against convention.