lib/chef/knife/server_bootstrap_standalone.rb in knife-server-1.1.0 vs lib/chef/knife/server_bootstrap_standalone.rb in knife-server-1.2.0
- old
+ new
@@ -1,5 +1,6 @@
+# -*- encoding: utf-8 -*-
#
# Author:: Fletcher Nichol (<fnichol@nichol.ca>)
# Copyright:: Copyright (c) 2012 Fletcher Nichol
# License:: Apache License, Version 2.0
#
@@ -14,77 +15,88 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require 'chef/knife/server_bootstrap_base'
+require "chef/knife/server_bootstrap_base"
class Chef
class Knife
+ # Provisions a standalone server that is reachable on the network and
+ # sets up an Open Source Chef Server.
class ServerBootstrapStandalone < Knife
banner "knife server bootstrap standalone (options)"
include Knife::ServerBootstrapBase
deps do
- require 'knife/server/ssh'
- require 'knife/server/credentials'
- require 'chef/knife/bootstrap'
+ require "knife/server/ssh"
+ require "knife/server/credentials"
+ require "chef/knife/bootstrap"
Chef::Knife::Bootstrap.load_deps
- current_options = self.options
+ current_options = options
self.options = Chef::Knife::Bootstrap.options.dup
- self.options.merge!(current_options)
+ options.merge!(current_options)
end
option :host,
:short => "-H FQDN_OR_IP",
:long => "--host FQDN_OR_IP",
:description => "Hostname or IP address of host to bootstrap"
def run
- validate!
+ super
check_ssh_connection
standalone_bootstrap.run
fetch_validation_key
create_root_client
install_client_key
end
def standalone_bootstrap
- ENV['WEBUI_PASSWORD'] = config_val(:webui_password)
- ENV['AMQP_PASSWORD'] = config_val(:amqp_password)
- ENV['NO_TEST'] = "1" if config[:no_test]
+ setup_environment
bootstrap = Chef::Knife::Bootstrap.new
- bootstrap.name_args = [ config[:host] ]
+ bootstrap.name_args = [config[:host]]
Chef::Knife::Bootstrap.options.keys.each do |attr|
- bootstrap.config[attr] = config_val(attr)
+ val = config_val(attr)
+ next if val.nil?
+
+ bootstrap.config[attr] = val
end
- bootstrap.ui = self.ui
+ bootstrap.ui = ui
bootstrap.config[:distro] = bootstrap_distro
- bootstrap.config[:use_sudo] = true unless config_val(:ssh_user) == "root"
+ bootstrap.config[:use_sudo] = true if config_val(:ssh_user) != "root"
bootstrap
end
private
def validate!
+ super
+
if config[:chef_node_name].nil?
ui.error "You did not provide a valid --node-name value."
exit 1
end
if config[:host].nil?
ui.error "You did not provide a valid --host value."
exit 1
end
end
+ def setup_environment
+ ENV["WEBUI_PASSWORD"] = config_val(:webui_password)
+ ENV["AMQP_PASSWORD"] = config_val(:amqp_password)
+ ENV["NO_TEST"] = "1" if config[:no_test]
+ end
+
def check_ssh_connection
ssh_connection.exec! "hostname -f"
rescue Net::SSH::AuthenticationFailed
- ui.warn("Failed to authenticate #{config_val(:ssh_user)} - " +
- "trying password auth")
+ ui.warn("Failed to authenticate #{config_val(:ssh_user)} - " \
+ "trying password auth")
config[:ssh_password] = ui.ask(
"Enter password for #{config_val(:ssh_user)}@#{config_val(:host)}: "
) { |q| q.echo = false }
end