Skip to content

Commit

Permalink
[COOK-3766] Directly use node attributes in templates where possible
Browse files Browse the repository at this point in the history
This fixes an issue (and future potential issues) where users make a single change to an attribute that is passed to a template. In this case, the `ports.conf.erb` template was rendered by multiple recipes, but a Pull Request only added a required template variable to one of the many declarations where this template was generated by other recipes. This isn't something that will show up in a git diff, and it's also not something that tests can easily test. Therefore, the best solution is to move these quasi-calculated attributes out of the recipes and directly into the template itself.
  • Loading branch information
sethvargo committed Oct 8, 2013
1 parent f3daf0e commit 995a3e8
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 14 deletions.
10 changes: 3 additions & 7 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,9 @@
end

template "#{node['apache']['dir']}/ports.conf" do
source 'ports.conf.erb'
owner 'root'
group node['apache']['root_group']
variables(
:apache_listen_addresses => node['apache']['listen_addresses'].uniq,
:apache_listen_ports => node['apache']['listen_ports'].map { |p| p.to_i }.uniq
)
source 'ports.conf.erb'
owner 'root'
group node['apache']['root_group']
mode '0644'
notifies :restart, 'service[apache2]'
end
Expand Down
3 changes: 0 additions & 3 deletions recipes/mod_ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
node.set['apache']['listen_ports'] = node['apache']['listen_ports'] + ['443']
end

ports = node['apache']['listen_ports']

if platform_family?('rhel', 'fedora', 'suse')
package 'mod_ssl' do
notifies :run, 'execute[generate-module-list]', :immediately
Expand All @@ -36,7 +34,6 @@
template "#{node['apache']['dir']}/ports.conf" do
source 'ports.conf.erb'
mode '0644'
variables(:apache_listen_ports => ports.map { |p| p.to_i }.uniq)
notifies :restart, 'service[apache2]'
end

Expand Down
4 changes: 2 additions & 2 deletions templates/default/ports.conf.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This file was generated by Chef for <%= node['fqdn'] %>.
# Do NOT modify this file by hand!

<% @apache_listen_ports.each do |port| -%>
<% @apache_listen_addresses.each do |address| -%>
<% node['apache']['listen_ports'].map(&:to_i).uniq.each do |port| -%>
<% node['apache']['listen_addresses'].uniq.each do |address| -%>
Listen <%= address.length > 0 ? "#{address}:" : '' %><%= port %>
<% end -%>
NameVirtualHost *:<%= port %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@
template "#{node['apache']['dir']}/mods-available/status.conf" do
source "status.conf.erb"
mode "0644"
variables({'remote_host' => node['apache_test']['remote_host_ip']})
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
Order deny,allow
Deny from all
Allow from localhost ip6-localhost
Allow from <%= @remote_host %>
Allow from <%= node['apache_test']['remote_host_ip'] %>
</Location>
</IfModule>

0 comments on commit 995a3e8

Please sign in to comment.