Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to substitute a string in a file using puppet

Tags:

puppet

I need help replacing a word in an apache Vhost's file using Puppet. My Vhost file looks like:

<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>

Now I want to substitute the * with the $fqdn facter variable on the first line. I don't want to use the apache module from Puppet Forge. I found file_line from the stdlib module but it is not able to substitute with a facter variable.

I could use the exec resource type which will run a sed command to replace * with the hostname, but I want to avoid doing that. Is there any other way to do this?

like image 779
Rohan Dsouza Avatar asked Oct 21 '25 23:10

Rohan Dsouza


1 Answers

You can in fact use file_line here:

include stdlib
$fqdn = $facts['fqdn']
file_line { 'virtual_host':
  ensure => present,
  path   => '/path/to/httpd.conf',
  line   => "<VirtualHost ${fqdn}:80>",
  match  => '<VirtualHost \*:80>',
}
like image 89
Alex Harvey Avatar answered Oct 23 '25 14:10

Alex Harvey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!