Skip to content

Instantly share code, notes, and snippets.

@gswallow
Last active January 4, 2016 07:19
Show Gist options
  • Save gswallow/8588328 to your computer and use it in GitHub Desktop.
Save gswallow/8588328 to your computer and use it in GitHub Desktop.
In a ruby block I try to create a template:
def create_runcontext
@events = Chef::EventDispatch::Dispatcher.new
# Load the ascent-compute cookbook.
cb_list = Chef::CookbookLoader.new(Chef::Config[:cookbook_path])
cb_list.load_cookbook("ascent-compute")
# Create a cookbook collection object for use later, in a run context
cookbook_collection = Chef::CookbookCollection.new(cb_list)
rc = Chef::RunContext.new(node, cookbook_collection, @events)
end
def create_production_json(customer, assay, mongo_uris, general_config)
rc = create_runcontext
t = Chef::Resource::Template.new("/var/scripts/assays/#{customer}/current/#{assay}/production.json", rc)
t.cookbook("ascent-compute")
t.source("production.json.erb")
t.owner(general_config["web"]["deployment_user"])
t.group(general_config["web"]["deployment_group"])
t.mode("0600")
t.variables(
:hosts => mongo_uris,
:site => customer
)
t.action(:create)
t.run_context=(rc)
t.run_action("create")
end
But the template is never downloaded. I have to force it to download before the ruby block is created:
+# Hack. Juke Chef into downloading *.json.erb from the Chef server.
+%w(production rest).each do |t|
+ template "/tmp/#{t}.json" do
+ source "#{t}.json.erb"
+ variables(
+ :hosts => [ "blah" ],
+ :site => "blah",
+ :username => "blah",
+ :password => "blah"
+ )
+ end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment