lib/capstrap/cli.rb in capstrap-0.3.3 vs lib/capstrap/cli.rb in capstrap-0.4.0

- old
+ new

@@ -66,10 +66,14 @@ :aliases => "-f" method_option "ruby", :for => task, :type => :string, :desc => "Version of ruby to install.", :default => "ree-1.8.7" + + method_option "hostname", :for => task, :type => :string, + :desc => "Desired name of host.", + :aliases => "-h" end [:chef, :solo, :execute, :update].each do |task| method_option "cookbooks-path", :for => task, :type => :string, :desc => "Install path to chef cookbooks git repository.", @@ -112,43 +116,56 @@ abort ">> --config-repo=<git_url> must be set" end end def exec_ruby + exec_hostname unless @ran_exec_hostname config.find_and_execute_task "rvm:install:#{config.fetch(:ruby)}" config.find_and_execute_task "rvm:default:#{config.fetch(:ruby)}" end def exec_chef + exec_hostname unless @ran_exec_hostname exec_ruby config.find_and_execute_task "chef:install:lib" end def exec_solo + exec_hostname unless @ran_exec_hostname exec_chef config.find_and_execute_task "chef:install:cookbooks" config.find_and_execute_task "chef:install:config" end def exec_execute + exec_hostname unless @ran_exec_hostname exec_solo config.find_and_execute_task "chef:execute:solo" end def exec_update + exec_hostname unless @ran_exec_hostname config.find_and_execute_task "chef:execute:update" end + + def exec_hostname + if config.exists?(:host_name) + config.find_and_execute_task "hostname:set_hostname" + end + @ran_exec_hostname = true + end def config @config ||= prep_config end def prep_config config = Capistrano::Configuration.new config.logger.level = Capistrano::Logger::TRACE config.role(:remote_host, @ssh_host) + Capstrap::Hostname.load_into(config) Capstrap::Apt.load_into(config) Capstrap::Core.load_into(config) Capstrap::RVM.load_into(config) Capstrap::Chef.load_into(config) @@ -156,10 +173,11 @@ end def setup_config(cli_options) abort ">> HOST must be set" unless @ssh_host + @ran_exec_hostname = false options = Hash.new options.merge!(cli_options) if File.exists?(options["config"]) options.merge!(YAML::load_file(options["config"])) end @@ -167,10 +185,11 @@ [ {:sym => :ruby, :opt => "ruby"}, {:sym => :cookbooks_repo, :opt => "cookbooks-repo"}, {:sym => :cookbooks_path, :opt => "cookbooks-path"}, {:sym => :config_repo, :opt => "config-repo"}, - {:sym => :config_path, :opt => "config-path"} + {:sym => :config_path, :opt => "config-path"}, + {:sym => :host_name, :opt => "hostname"} ].each do |var| config.set(var[:sym], options[var[:opt]]) if options[var[:opt]] end # booleans