Reputation: 101
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?
Upvotes: 3
Views: 9816
Reputation: 9
Ok, so I found my answer:
append_on_no_match => false,
Added that to the match statement; seems to prevent appending if no match is found.
Upvotes: 1
Reputation: 9
The problem with this answer, is that if puppet doesn't match a string it still appends, and this cannot always happen, in fact, it often cannot happen.
I don't have an answer, but perhaps someone else might. I would prefer a puppet answer vs me writing a script (with sed or perl).
Sincerely,
Some puppet user....
Upvotes: -1
Reputation: 15472
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>',
}
Upvotes: 4