Skip to content

Instantly share code, notes, and snippets.

@jcam

jcam/cheftest.rb Secret

Created January 6, 2012 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcam/2f019bc4e34887f9aefd to your computer and use it in GitHub Desktop.
Save jcam/2f019bc4e34887f9aefd to your computer and use it in GitHub Desktop.
simple chef template tester
require 'rubygems'
require 'erubis'
#Support the the node attribute as used in Chef
module ChefContext
def node
return @node if @node
raise "Could not find a value for node. Include a node variable in the context if you plan to use it."
end
end
::Erubis::Context.send(:include, ChefContext)
node = {}
node[:fqdn] = "mydomain.com"
node['authorization'] = {}
node['authorization']['sudo'] = {}
node['authorization']['sudo']['groups'] = Array.new
node['authorization']['sudo']['users'] = Array.new
node['authorization']['sudo']['users'] = ["one","flew","over"]
node['authorization']['sudo']['passwordless'] = false
input = File.read('sudoers.erb')
eruby = Erubis::Eruby.new(input)
context = {:node => node,
:sudoers_users => node['authorization']['sudo']['users'],
:sudoers_groups => node['authorization']['sudo']['groups'],
:passwordless => node['authorization']['sudo']['passwordless']}
puts eruby.evaluate(context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment