Skip to content

Commit

Permalink
ssh driver support and more smartening
Browse files Browse the repository at this point in the history
  • Loading branch information
double-z committed Aug 23, 2015
1 parent d8c3913 commit d1bd83d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 38 deletions.
6 changes: 3 additions & 3 deletions cookbooks/chef-platform-provision/attributes/chef-platform.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

default['chef_platform']['driver'].tap do |driver|
driver['name'] = 'vagrant'
driver['name'] = 'ssh'
end

default['chef_platform']['chef_server'].tap do |chef_server|
Expand All @@ -9,7 +9,7 @@
chef_server['api_fqdn'] = "chef-server.chefplatform.local"
chef_server['configuration'] = {
"postgresql" => {
"max_connections" => 1501,
"max_connections" => 1500,
"log_min_duration_statement" => 500
},
# "oc_id" => {
Expand Down Expand Up @@ -45,7 +45,7 @@
"prod",
"preprod"
],
"hipchat_room" => 'Chef Notification'
"hipchat_room" => 'Chef Notifications'
}
}
end
Expand Down
9 changes: 9 additions & 0 deletions cookbooks/chef-platform-provision/libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def self.log_all_data(given_platform_spec)

def self.apd(name, data)
upname = name.upcase
puts
puts "=========================================================="
puts
puts "BEGIN #{upname}"
Expand All @@ -164,6 +165,14 @@ def self.apl(data)
}
end

def self.true_false_to_s(tf)
if tf
"true"
else
"false"
end
end

def self.log_test_if(name)
puts "=========================================================="
puts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'cheffish'
require 'chef/provisioning'
require 'chef/provisioning/vagrant_driver'
require 'chef/provisioning/ssh_driver'
require 'chef/provider/lwrp_base'
require 'chef/provider/chef_node'
require 'openssl'
Expand Down Expand Up @@ -43,8 +44,8 @@ def action_handler=(value)
action :nothing
new_platform_spec.all_nodes.each do |server|
machine server['node_name'] do
driver "vagrant"
machine_options vagrant_machine_opts_for(server)
driver "ssh"
machine_options machine_opts_for(server)
converge true
end
end
Expand Down Expand Up @@ -116,8 +117,8 @@ def action_handler=(value)
action :converge
new_platform_spec.all_nodes.each do |server|
machine server['node_name'] do
driver "vagrant"
machine_options vagrant_machine_opts_for(server)
driver "ssh"
machine_options machine_opts_for(server)
files(
'/etc/opscode/chef-server.rb' => local_chef_server_rb_path,
'/etc/opscode-analytics/analytics.rb' => local_analytics_rb_path
Expand Down Expand Up @@ -160,11 +161,25 @@ def action_handler=(value)
@new_resource.updated_by_last_action(mbd.updated_by_last_action?)
end

def machine_opts_for(server)
case new_platform_spec.driver_name
when "ssh"
ssh_machine_opts_for(server)
when "vagrant"
vagrant_machine_opts_for(server)
end
end

def vagrant_machine_opts_for(server)
machine_ops = ::VagrantConfigHelper.generate_config(server)
machine_ops
end

def ssh_machine_opts_for(server)
machine_ops = ::SshConfigHelper.generate_config(server)
machine_ops
end

def machine_options_for(server)
configs = []

Expand Down Expand Up @@ -194,11 +209,12 @@ def machine_options_for(server)
attr_reader :chef_server, :platform_spec, :new_platform_spec, :current_platform_spec, :rollback_platform_spec

def load_current_resource
# apd("Resource Init Time", new_resource.init_time)
apd("Resource Init Time", new_resource.init_time)
@chef_server = new_resource.chef_server
@current_platform_spec = Provisioner::ChefPlatformSpec.current_spec(new_resource.policy_group)
@new_platform_spec = Provisioner::ChefPlatformSpec.new_spec(new_resource.policy_group,
::Provisioner.deep_hashify(new_resource.platform_data))
apd("driver", new_platform_spec.driver_name)
new_platform_spec.nodes = all_ready_nodes if all_nodes_ready?
log_all_data if new_resource.log_all
end
Expand Down Expand Up @@ -335,36 +351,11 @@ def log_all_data
end

def apd(name, data)
upname = name.upcase
puts
puts "=========================================================="
puts
puts "BEGIN #{upname}"
puts
apl(data)
puts
puts "END #{upname}"
puts
puts "=========================================================="
end

def apl(data)
ap data, options = {
:indent => -2,
:index => false,
:color => {
:hash => :pale,
:class => :white
}
}
::Provisioner.apd(name, data)
end

def true_false_to_s(tf)
if tf
"true"
else
"false"
end
::Provisioner.true_false_to_s(tf)
end

end
Expand Down
17 changes: 17 additions & 0 deletions cookbooks/chef-platform-provision/libraries/ssh_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# encoding: utf-8

class SshConfigHelper

def self.generate_config(server)
local_provisioner_options = {
:transport_options => {
'ip_address' => server['machine_options_ipaddress'],
'username' => 'vagrant',
'ssh_options' => {
'password' => 'vagrant'
}
}
}
end

end
6 changes: 3 additions & 3 deletions data_bags/prod/chef_platform.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"id": "chef_platform",
"driver": {
"name": "vagrant"
"name": "ssh"
},
"chef_server": {
"topology": "tier",
"version": "latest",
"api_fqdn": "chef-server.chefplatform.local",
"configuration": {
"postgresql": {
"max_connections": 1501,
"max_connections": 1500,
"log_min_duration_statement": 500
},
"opscode_erchef": {
Expand Down Expand Up @@ -40,7 +40,7 @@
"prod",
"preprod"
],
"hipchat_room": "Chef Notification"
"hipchat_room": "Chef Notifications"
}
}
},
Expand Down

0 comments on commit d1bd83d

Please sign in to comment.