class Pantry::Chef::ConfigureChef
Public Instance Methods
perform(message)
click to toggle source
# File lib/pantry/chef/configure_chef.rb, line 6 def perform(message) @base_chef_dir = Pantry.root.join("chef") @etc_dir = Pantry.root.join("etc", "chef") create_required_directories write_solo_rb write_node_json # TODO: Error handling response message? true end
Protected Instance Methods
create_required_directories()
click to toggle source
# File lib/pantry/chef/configure_chef.rb, line 18 def create_required_directories FileUtils.mkdir_p(@base_chef_dir.join("cache")) FileUtils.mkdir_p(@base_chef_dir.join("cookbooks")) FileUtils.mkdir_p(@base_chef_dir.join("environments")) FileUtils.mkdir_p(@etc_dir) end
write_node_json()
click to toggle source
# File lib/pantry/chef/configure_chef.rb, line 44 def write_node_json return unless client node_json = @etc_dir.join("node.json") File.open(node_json, "w+") do |file| file.write({ "run_list" => client.roles.map {|r| "role[#{r}]" } }.to_json) end end
write_solo_rb()
click to toggle source
NOTE: Writes out the file every time this command is run.
# File lib/pantry/chef/configure_chef.rb, line 26 def write_solo_rb contents = ["# This file generated by Pantry", ""] if client && client.environment contents << %|environment "#{client.environment}"| end contents << %|file_cache_path "#{@base_chef_dir.join("cache")}"| contents << %|cookbook_path "#{@base_chef_dir.join("cookbooks")}"| contents << %|environment_path "#{@base_chef_dir.join("environments")}"| contents << %|role_path "#{@base_chef_dir.join("roles")}"| contents << %|json_attribs "#{@etc_dir.join("node.json")}"| File.open(@etc_dir.join("solo.rb"), "w+") do |file| file.write(contents.join("\n") + "\n") end end