class Soloist::Config
Attributes
node_json_path[W]
royal_crown[R]
solo_rb_path[W]
Public Class Methods
from_file(royal_crown_path)
click to toggle source
# File lib/soloist/config.rb, line 9 def self.from_file(royal_crown_path) rc = Soloist::RoyalCrown.from_file(royal_crown_path) new(rc) end
new(royal_crown)
click to toggle source
# File lib/soloist/config.rb, line 14 def initialize(royal_crown) @royal_crown = royal_crown end
Public Instance Methods
as_node_json()
click to toggle source
# File lib/soloist/config.rb, line 34 def as_node_json compiled.node_attributes.to_hash.merge({ "recipes" => compiled.recipes }) end
as_solo_rb()
click to toggle source
# File lib/soloist/config.rb, line 26 def as_solo_rb <<-SOLO_RB file_cache_path "#{chef_cache_path}" cookbook_path #{cookbook_paths.inspect} json_attribs "#{node_json_path}" SOLO_RB end
chef_cache_path()
click to toggle source
# File lib/soloist/config.rb, line 38 def chef_cache_path "/var/chef/cache".tap do |cache_path| system(conditional_sudo("mkdir -p #{cache_path}")) \ unless File.directory?(cache_path) end end
chef_solo()
click to toggle source
# File lib/soloist/config.rb, line 22 def chef_solo "chef-solo -c '#{solo_rb_path}' -l '#{log_level}'" end
compiled()
click to toggle source
# File lib/soloist/config.rb, line 76 def compiled @compiled ||= royal_crown.dup.tap do |working_royal_crown| while working_royal_crown["env_variable_switches"] working_royal_crown.delete("env_variable_switches").each do |variable, switch| switch.each do |value, inner| working_royal_crown.merge!(inner) if ENV[variable] == value end end end end end
cookbook_paths()
click to toggle source
# File lib/soloist/config.rb, line 45 def cookbook_paths ([royal_crown_cookbooks_directory] + compiled.cookbook_paths).map do |path| File.expand_path(path, royal_crown_path) end.uniq.select do |path| File.directory?(path) end end
debug?()
click to toggle source
# File lib/soloist/config.rb, line 92 def debug? log_level == "debug" end
log_level()
click to toggle source
# File lib/soloist/config.rb, line 88 def log_level ENV["LOG_LEVEL"] || "info" end
merge!(other)
click to toggle source
# File lib/soloist/config.rb, line 69 def merge!(other) royal_crown.recipes += other.royal_crown.recipes royal_crown.cookbook_paths += other.royal_crown.cookbook_paths royal_crown.node_attributes.merge!(other.royal_crown.node_attributes) royal_crown.env_variable_switches.merge!(other.royal_crown.env_variable_switches) end
node_json_path()
click to toggle source
# File lib/soloist/config.rb, line 61 def node_json_path @node_json_path ||= Tempfile.new(["node", ".json"]).tap do |file| puts JSON.pretty_generate(as_node_json) if debug? file.write(JSON.dump(as_node_json)) file.close end.path end
run_chef()
click to toggle source
# File lib/soloist/config.rb, line 18 def run_chef exec(conditional_sudo("bash -c '#{chef_solo}'")) end
solo_rb_path()
click to toggle source
# File lib/soloist/config.rb, line 53 def solo_rb_path @solo_rb_path ||= Tempfile.new(["solo", ".rb"]).tap do |file| puts as_solo_rb if debug? file.write(as_solo_rb) file.close end.path end
Private Instance Methods
conditional_sudo(command)
click to toggle source
# File lib/soloist/config.rb, line 97 def conditional_sudo(command) root? ? command : "sudo -E #{command}" end
root?()
click to toggle source
# File lib/soloist/config.rb, line 101 def root? Process.uid == 0 end
royal_crown_cookbooks_directory()
click to toggle source
# File lib/soloist/config.rb, line 105 def royal_crown_cookbooks_directory File.expand_path("cookbooks", royal_crown_path) end
royal_crown_path()
click to toggle source
# File lib/soloist/config.rb, line 109 def royal_crown_path File.dirname(royal_crown.path) end