I am using chef 12 version trying to overwriting an apache2 template using a wrapper cookbook. My chef-client does not fail but it doesn’t add the application_name = testcom. How do I add that application_name in the param in my template wrapper? If I remove @application_name and change it to @params[:name] it does what I want it to do, is there a better way to do it without modifying the wrapper template?
My wrapper template:
<%- if node['apache']['version'] == '2.4' -%>
LogLevel info rewrite:trace1
<%- else -%>
LogLevel info
RewriteLog <%= node['apache']['log_dir'] %>/<%= @application_name %>-rewrite.log
# RewriteLog <%= node['apache']['log_dir'] %>/<%= @params[:name] %>-rewrite.log
RewriteLogLevel 0
<% end -%>
This is the apache2, Definition web_app community cookbook
define :web_app, :template => 'web_app.conf.erb', :local => false, :enable => true, :server_port => 80 do
application_name = params[:name]
include_recipe 'apache2::default'
include_recipe 'apache2::mod_rewrite'
include_recipe 'apache2::mod_deflate'
include_recipe 'apache2::mod_headers'
template "#{node['apache']['dir']}/sites-available/#{application_name}.conf" do
source params[:template]
local params[:local]
owner 'root'
group node['apache']['root_group']
mode '0644'
cookbook params[:cookbook] if params[:cookbook]
variables(
:application_name => application_name,
:params => params
)
if ::File.exist?("#{node['apache']['dir']}/sites-enabled/#{application_name}.conf")
notifies :reload, 'service[apache2]', :delayed
end
end
site_enabled = params[:enable]
apache_site params[:name] do
enable site_enabled
end
The output from the chef-client run doesn’t give an error but removes the testcom (-rewrite.log) in line 4
Recipe: ehis_icfolson_dispatcher::default
* template[/etc/httpd/sites-available/ehicom.conf] action create
- update content in file /etc/httpd/sites-available/ehicom.conf from 1e5226 to 1c027b
--- /etc/httpd/sites-available/ehicom.conf 2018-05-08 13:15:46.548810281 -0500
+++ /etc/httpd/sites-available/.chef-ehicom20180508-18013-bcrkd8.conf 2018-05-08 13:15:48.204736945 -0500
@@ -37,7 +37,7 @@
1 RewriteEngine On
2 LogLevel info
3 - RewriteLog /var/log/httpd/testcom-rewrite.log
4 + RewriteLog /var/log/httpd/-rewrite.log
5 # RewriteLog /var/log/httpd/testcom-rewrite.log
6 RewriteLogLevel 0
- restore selinux security context
my wrapper recipe:
include_recipe 'core_dispatcher::default'
edit_resource(:template, '/etc/httpd/sites-available/testcom.conf') do
source 'dispatcher-vhost.conf.erb'
cookbook 'client_dispatcher'
variables(:params => {:server_port => 80, :name => node['apache']['name'], :docroot => node['apache']['docroot'], :server_name => node['apache']['server_name'], :server_aliases => node['apache']['server_aliases']})
end
my wrapper attributes:
default['apache']['name'] = 'testcom'
default['apache']['docroot'] = "#{node['adobe']['dispatcher']['cache_root']}/#{node['apache']['name']}"
default['apache']['server_name'] = "dev-testcom.something.com"
default['apache']['server_aliases'] = ["#{node['apache']['server_name']}"]