Commit ae325896 authored by Victor Penso's avatar Victor Penso
Browse files

Add support for templates

parent 725f2f5b
......@@ -26,6 +26,7 @@
directory
file
link
template
execute
bash
service
......@@ -51,24 +52,43 @@
case key
when 'content'
if resource.eql? 'file'
value = "
#
# DO NOT CHANGE THIS FILE MANUALLY!
#
# This file is managed by the Chef configuration management system
#
#{value}
"
# Disable the header comment by attribute
banner = if not node[resource][name].has_key? 'banner'
true
else
node[resource][name]['banner']
end
# Add a banner to indicate that the written file is
# managed by Chef
if banner
value = "
#
# DO NOT CHANGE THIS FILE MANUALLY!
#
# This file is managed by the Chef configuration management system
#
#{value}
"
end
end
value = value.gsub(/^ */,'')
value = value.split("\n")
value = value[1..-1] if value[0] =~ /^$/
value = value.join("\n") << "\n"
send(key,value)
when 'notifies','subscribes'
when 'notifies','subscribes','template'
send(key, *value)
# Ignore the following keys...
when 'banner'
next
# Pass all attributes as resource properties by default
else
send(key,value)
end
......
name 'template'
description 'Template configuration for testing'
run_list( 'recipe[base]' )
default_attributes(
directory: {
'/var/cache/chef': { recursive: true }
},
file: {
# Write a template file
#
'/var/cache/chef/template.erb': {
content: '
This is some text <%= @one %> <%= @two %>
',
banner: false
}
},
# Render an ERB template from a local file
template: {
'/tmp/template.txt': {
local: true,
source: '/var/cache/chef/template.erb',
variables: {
one: 'hello',
two: 'world'
}
}
}
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment