Class: Soloist::Config
- Inherits:
-
Object
- Object
- Soloist::Config
- Defined in:
- lib/soloist/config.rb
Direct Known Subclasses
Instance Attribute Summary collapse
- #node_json_path ⇒ Object
-
#royal_crown ⇒ Object
readonly
Returns the value of attribute royal_crown.
- #solo_rb_path ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #as_node_json ⇒ Object
- #as_solo_rb ⇒ Object
- #chef_cache_path ⇒ Object
- #chef_solo ⇒ Object
- #compiled ⇒ Object
- #cookbook_paths ⇒ Object
- #debug? ⇒ Boolean
-
#initialize(royal_crown) ⇒ Config
constructor
A new instance of Config.
- #log_level ⇒ Object
- #merge!(other) ⇒ Object
- #run_chef ⇒ Object
Constructor Details
#initialize(royal_crown) ⇒ Config
Returns a new instance of Config.
14 15 16 |
# File 'lib/soloist/config.rb', line 14 def initialize(royal_crown) @royal_crown = royal_crown end |
Instance Attribute Details
#node_json_path ⇒ Object
61 62 63 64 65 66 67 |
# 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 |
#royal_crown ⇒ Object (readonly)
Returns the value of attribute royal_crown.
7 8 9 |
# File 'lib/soloist/config.rb', line 7 def royal_crown @royal_crown end |
#solo_rb_path ⇒ Object
53 54 55 56 57 58 59 |
# 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 |
Class Method Details
.from_file(royal_crown_path) ⇒ Object
9 10 11 12 |
# 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 |
Instance Method Details
#as_node_json ⇒ Object
34 35 36 |
# File 'lib/soloist/config.rb', line 34 def as_node_json compiled.node_attributes.to_hash.merge({ "recipes" => compiled.recipes }) end |
#as_solo_rb ⇒ Object
26 27 28 29 30 31 32 |
# 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 ⇒ Object
38 39 40 41 42 43 |
# 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 ⇒ Object
22 23 24 |
# File 'lib/soloist/config.rb', line 22 def chef_solo "chef-solo -c '#{solo_rb_path}' -l '#{log_level}'" end |
#compiled ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/soloist/config.rb', line 76 def compiled @compiled ||= royal_crown.dup.tap do |rc| while rc["env_variable_switches"] rc.delete("env_variable_switches").each do |variable, switch| switch.each do |value, inner| rc.merge!(inner) if ENV[variable] == value end end end end end |
#cookbook_paths ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/soloist/config.rb', line 45 def cookbook_paths ([royal_crown_cookbooks_directory] + compiled.cookbook_paths).map do |path| File.(path, royal_crown_path) end.uniq.select do |path| File.directory?(path) end end |
#debug? ⇒ Boolean
92 93 94 |
# File 'lib/soloist/config.rb', line 92 def debug? log_level == "debug" end |
#log_level ⇒ Object
88 89 90 |
# File 'lib/soloist/config.rb', line 88 def log_level ENV["LOG_LEVEL"] || "info" end |
#merge!(other) ⇒ Object
69 70 71 72 73 74 |
# 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 |
#run_chef ⇒ Object
18 19 20 |
# File 'lib/soloist/config.rb', line 18 def run_chef exec(conditional_sudo("bash -c '#{chef_solo}'")) end |