|
# |
|
# Author:: Teemu Matilainen <[email protected]> |
|
# Copyright 2012, Reaktor Innovations Oy |
|
# License:: Apache License, Version 2.0 |
|
# |
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
# you may not use this file except in compliance with the License. |
|
# You may obtain a copy of the License at |
|
# |
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
# |
|
# Unless required by applicable law or agreed to in writing, software |
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
# 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/ec2_server_create' |
|
require 'chef/knife/solo_bootstrap' |
|
require 'knife-solo/kitchen_command' |
|
|
|
class Chef |
|
class Knife |
|
class Ec2ServerCreate |
|
include KnifeSolo::KitchenCommand |
|
|
|
def self.load_deps |
|
super |
|
SoloBootstrap.load_deps |
|
end |
|
|
|
option :solo, |
|
:long => "--solo", |
|
:description => "Bootstrap Chef using knife-solo" |
|
|
|
self.options.merge! SoloBootstrap.options |
|
|
|
# Rename and override knife-ec2 plugin's validate! method |
|
alias_method :orig_validate!, :validate! |
|
|
|
def validate!(*args) |
|
orig_validate!(*args) |
|
validate_kitchen! if config[:solo] |
|
end |
|
|
|
# Rename and override knife-ec2 plugin's bootstrap_for_node method |
|
alias_method :chef_server_bootstrap_for_node, :bootstrap_for_node |
|
|
|
def bootstrap_for_node(server, ssh_host) |
|
if config[:solo] |
|
chef_solo_bootstrap_for_node(server, ssh_host) |
|
else |
|
chef_server_bootstrap_for_node(server, ssh_host) |
|
end |
|
end |
|
|
|
def chef_solo_bootstrap_for_node(server, ssh_host) |
|
bootstrap = SoloBootstrap.new |
|
bootstrap.ui = ui |
|
bootstrap.name_args = ["#{config[:ssh_user]}@#{@ssh_host}"] |
|
bootstrap.config = config |
|
# Modify global configuration state to ensure hint gets set by |
|
# knife-bootstrap |
|
Chef::Config[:knife][:hints] ||= {} |
|
Chef::Config[:knife][:hints]["ec2"] ||= {} |
|
bootstrap |
|
end |
|
end |
|
end |
|
end |
It seems like a better idea to do this one layer lower, on
knife bootstrap
. See gist 4559333.