lib/soloist/cli.rb in soloist-1.0.0.pre vs lib/soloist/cli.rb in soloist-1.0.0
- old
+ new
@@ -1,83 +1,78 @@
require "librarian/chef/cli"
+require "soloist/remote_config"
require "soloist/spotlight"
-require "soloist/config"
-require "tempfile"
+require "awesome_print"
require "thor"
module Soloist
class CLI < Thor
+ attr_writer :soloist_config
default_task :chef
- desc "chef", "Runs chef-solo like a baws"
+ desc "chef", "Run chef-solo"
+ method_option :remote, :aliases => "-r", :desc => "Run chef-solo on user@host"
+ method_option :identity, :aliases => "-i", :desc => "The SSH identity file"
def chef
- ensure_chef_cache_path
- write_solo_rb
- write_node_json
install_cookbooks if cheffile_exists?
- exec("sudo -E bash -c '#{chef_solo}'")
+ soloist_config.run_chef
end
- desc "run_recipe", "Runs an individual recipe with chef-solo"
- def DO_IT_LIVE(*recipes)
- config.royal_crown.recipes = recipes
+ desc "run_recipe [cookbook::recipe, ...]", "Run individual recipes"
+ method_option :remote, :aliases => "-r", :desc => "Run recipes on user@host"
+ method_option :identity, :aliases => "-i", :desc => "The SSH identity file"
+ def run_recipe(*recipes)
+ soloist_config.royal_crown.recipes = recipes
chef
end
- no_tasks do
- def write_solo_rb
- content = config.as_solo_rb
- content.each{ |line| puts line } if log_level == "debug"
- File.open(solo_rb.path, "w") { |f| f.write(content) }
- end
+ desc "config", "Dumps configuration data for Soloist"
+ def config
+ Kernel.ap(soloist_config.as_node_json)
+ end
- def write_node_json
- content = config.as_json
- puts JSON.pretty_generate(content) if log_level == "debug"
- File.open(node_json.path, "w") { |f| f.write(JSON.dump(content)) }
- end
-
- def ensure_chef_cache_path
- unless File.directory?("/var/chef/cache")
- system("sudo mkdir -p /var/chef/cache")
- end
- end
-
+ no_tasks do
def install_cookbooks
Dir.chdir(File.dirname(rc_path)) do
Librarian::Chef::Cli.with_environment do
Librarian::Chef::Cli.new.install
end
end
end
- def config
- @config ||= Soloist::Config.from_file(rc_path)
+ def soloist_config
+ @soloist_config ||= if options[:remote]
+ Soloist::RemoteConfig.from_file(rc_path, remote)
+ else
+ Soloist::Config.from_file(rc_path)
+ end.tap do |config|
+ config.merge!(rc_local) if rc_local_path
+ end
end
-
- def chef_solo
- "chef-solo -j '#{node_json.path}' -c '#{solo_rb.path}' -l '#{log_level}'"
- end
end
private
- def cheffile_exists?
- File.exists?(File.expand_path("../Cheffile", rc_path))
+ def rc_local
+ Soloist::Config.from_file(rc_local_path)
end
- def log_level
- ENV["LOG_LEVEL"] || "info"
+ def remote
+ @remote ||= if options[:identity]
+ Soloist::Remote.from_uri(options[:remote], options[:identity])
+ else
+ Soloist::Remote.from_uri(options[:remote])
+ end
end
- def solo_rb
- @solo_rb ||= Tempfile.new(["solo", ".rb"])
+ def cheffile_exists?
+ File.exists?(File.expand_path("../Cheffile", rc_path))
end
- def node_json
- @node_json ||= Tempfile.new(["node", ".json"])
- end
-
def rc_path
@rc_path ||= Soloist::Spotlight.find!("soloistrc", ".soloistrc")
+ end
+
+ def rc_local_path
+ @rc_local_path ||= Soloist::Spotlight.find("soloistrc_local", ".soloistrc_local")
end
end
end