-
-
Save jcam/2f019bc4e34887f9aefd to your computer and use it in GitHub Desktop.
simple chef template tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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