Skip to content

Commit

Permalink
Add 'attributes/customize.rb'.
Browse files Browse the repository at this point in the history
This file is added to enable improved user experience when overriding
attributes. Today customers often override the complete file, which will
back-fire when OpsWorks introduces new attributes.
By moving out customer attribute changes to separate files, we make it
easier for the customer to keep track of their changes. It is also
easier for OpsWorks to improve the cookbooks.

Once agreed, all cookbooks would have a 'attributes/customize.rb'.
  • Loading branch information
jbraeuer authored and Christian Requena committed Mar 4, 2014
1 parent 17104d6 commit fcba313
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 deletions.
30 changes: 29 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#/usr/bin/env rake

require 'fileutils'

Encoding.default_external = Encoding::UTF_8 unless RUBY_VERSION.start_with? "1.8"
Encoding.default_internal = Encoding::UTF_8 unless RUBY_VERSION.start_with? "1.8"

Expand Down Expand Up @@ -100,5 +102,31 @@ task :validate_best_practises do
end
end

desc 'Check that all cookbooks include a customize.rb'
task :validate_customize do
errors = []
Dir.glob("*/attributes/*.rb").map do |file|
next if File.basename(file) == "customize.rb"

found = false
IO.readlines(file).each do |line|
# loads/includes attributes
if line.match(/include_attribute [\'\"](\w+)::(\w+)?[\'\"]/)
if $1 == file.split('/').first && $2 == "customize"
found = true
end
end
end

errors << file unless found
puts "OK: #{file}" if found
end

if errors.any?
errors.each { |e| warn "Does not include customize.rb: #{e}" }
exit 1
end
end

desc 'run all checks'
task :default => [:validate_syntax, :validate_literal_includes, :validate_best_practises, :validate_attribute_dependencies]
task :default => [:validate_syntax, :validate_literal_includes, :validate_best_practises, :validate_attribute_dependencies, :validate_customize]
24 changes: 18 additions & 6 deletions apache2/attributes/apache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,22 @@
# limitations under the License.
#

# Where the various parts of apache are
###
# Do not use this file to override the apache2 cookbook's default
# attributes. Instead, please use the customize.rb attributes file,
# which will keep your adjustments separate from the AWS OpsWorks
# codebase and make it easier to upgrade.
#
# However, you should not edit customize.rb directly. Instead, create
# "apache2/attributes/customize.rb" in your cookbook repository and
# put the overrides in YOUR customize.rb file.
#
# Do NOT create an 'apache2/attributes/apache.rb' in your cookbooks. Doing so
# would completely override this file and might cause upgrade issues.
#
# See also: http://docs.aws.amazon.com/opsworks/latest/userguide/customizing.html
###

case node[:platform]
when 'redhat','centos','fedora','amazon'
default[:apache][:dir] = '/etc/httpd'
Expand Down Expand Up @@ -51,11 +66,6 @@
raise 'Bailing out, unknown platform.'
end

###
# These settings need the unless, since we want them to be tunable,
# and we don't want to override the tunings.
###

# General settings
default[:apache][:listen_ports] = [ '80','443' ]
default[:apache][:contact] = '[email protected]'
Expand Down Expand Up @@ -103,3 +113,5 @@
default[:apache][:logrotate][:mode] = '640'
default[:apache][:logrotate][:owner] = 'root'
default[:apache][:logrotate][:group] = 'adm'

include_attribute 'apache2::customize'
12 changes: 12 additions & 0 deletions apache2/attributes/customize.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
###
# This is the place to override the apache2 cookbook's default attributes.
#
# Do not edit THIS file directly. Instead, create
# "apache2/attributes/customize.rb" in your cookbook repository and
# put the overrides in YOUR customize.rb file.
###

# The following shows how to override the Apache contact and timeout settings:
#
#normal[:apache][:contact] = '[email protected]'
#normal[:apache][:timeout] = 60

0 comments on commit fcba313

Please sign in to comment.