Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[COOK-3155] Be able to install chef-client from omnibus packages #102

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions attributes/install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
default['chef-client']['version'] = :latest
default['chef-client']['install_method'] = "omnibus"
7 changes: 7 additions & 0 deletions attributes/install_omnibus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include_attribute "chef-client::install"

default['chef-client']['omnibus']['version'] = node['chef-client']['version']
default['chef-client']['omnibus']['prereleases'] = false
default['chef-client']['omnibus']['nightlies'] = false
default['chef-client']['omnibus']['package_file'] = nil
default['chef-client']['omnibus']['package_checksum'] = nil
62 changes: 62 additions & 0 deletions libraries/omnitruck_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# Copyright:: Copyright (c) 2012 Opscode, Inc.
# 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 'uri'

class OmnitruckClientClient

attr_reader :platform, :platform_version, :machine_architecture

def initialize(node)
@platform = node['platform_family'] == "rhel" ? "el" : node['platform']
@platform_version = node['platform_family'] == "rhel" ? node['platform_version'].to_i : node['platform_version']
@machine_architecture = node['kernel']['machine']
end

def package_for_version(version, prerelease=false, nightly=false)
url = "http://www.opscode.com/chef/download"
url << "?p=#{platform}"
url << "&pv=#{platform_version}"
url << "&m=#{machine_architecture}"
url << "&v=#{version}" if version
url << "&prerelease=#{prerelease}"
url << "&nightlies=#{nightly}"
Chef::Log.info("Omnitruck download-clien request: #{url}")
target = redirect_target(url)
Chef::Log.info("Downloading chef-client package from: #{target}") if target
target
end

private

def redirect_target(url)
url = URI.parse(url)
http = Net::HTTP.new(url.host, url.port)
if url.scheme == "https"
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
response = http.get(url.request_uri, {})
case response
when Net::HTTPRedirection
response['location']
else
nil
end
end

end
20 changes: 20 additions & 0 deletions recipes/install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Cookbook Name:: chef-client
# Recipe:: install
#
# Copyright 2010, Opscode, Inc.
#
# 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.
#

include_recipe "chef-client::install_#{node['chef-client']['install_method']}"
65 changes: 65 additions & 0 deletions recipes/install_omnibus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#
# Cookbook Name:: chef-client
# Recipe:: install_omnibus
#
# Copyright 2010, Opscode, Inc.
#
# 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.
#

# Acquire the chef-client Omnibus package
if node['chef-client']['package_file'].nil? || node['chef-client']['package_file'].empty?
omnibus_package = OmnitruckClientClient.new(node).package_for_version(node['chef-client']['version'],
node['chef-client']['prereleases'],
node['chef-client']['nightlies'])
unless omnibus_package
err_msg = "Could not locate chef-client"
err_msg << " pre-release" if node['chef-client']['prereleases']
err_msg << " nightly" if node['chef-client']['nightlies']
err_msg << " package matching version '#{node['chef-client']['version']}' for node."
raise err_msg
end
else
omnibus_package = node['chef-client']['package_file']
end

package_name = ::File.basename(omnibus_package)
package_local_path = "#{Chef::Config[:file_cache_path]}/#{package_name}"

# omnibus_package is remote (ie a URI) let's download it
if ::URI.parse(omnibus_package).absolute?
remote_file package_local_path do
source omnibus_package
if node['chef-client']['package_checksum']
checksum node['chef-client']['package_checksum'] if node['chef-client']['package_checksum']
action :create
else
action :create_if_missing
end
end
# else we assume it's on the local machine
else
package_local_path = omnibus_package
end

# install the platform package
package package_name do
source package_local_path
provider case node["platform_family"]
when "debian"; Chef::Provider::Package::Dpkg
when "rhel"; Chef::Provider::Package::Rpm
else
raise RuntimeError("I don't know how to install chef-client packages for platform family '#{node["platform_family"]}'!")
end
action :install
end