Initial Chef repository

This commit is contained in:
Greg Karékinian
2015-07-21 19:45:23 +02:00
parent 7e5401fc71
commit ee4079fa85
1151 changed files with 185163 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
#
# Cookbook Name:: omnibus_updater
# Recipe:: default
#
# Copyright 2014, Heavy Water Ops, LLC
#
# 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.
#
if(node[:omnibus_updater][:disabled])
Chef::Log.warn 'Omnibus updater disabled via `disabled` attribute'
elsif(node[:platform] == 'debian' && Gem::Version.new(node[:platform_version]) < Gem::Version.new('6.0.0'))
Chef::Log.warn 'Omnibus updater does not support Debian 5'
else
include_recipe 'omnibus_updater::downloader'
include_recipe 'omnibus_updater::installer'
end
if(node[:omnibus_updater][:remove_chef_system_gem])
include_recipe 'omnibus_updater::remove_chef_system_gem'
end

View File

@@ -0,0 +1,71 @@
#
# Cookbook Name:: omnibus_updater
# Recipe:: downloader
#
# Copyright 2014, Heavy Water Ops, LLC
#
# 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.
#
# NOTE: This recipe is here for others that just want the
# package, not the actual installation (lxc for example)
if(node[:omnibus_updater][:direct_url])
remote_path = node[:omnibus_updater][:direct_url]
else
version = node[:omnibus_updater][:version] || ''
remote_path = OmnibusTrucker.url(
OmnibusTrucker.build_url(node,
:version => node[:omnibus_updater][:force_latest] ? nil : version.sub(/\-.+$/, ''),
:prerelease => node[:omnibus_updater][:preview]
), node
)
end
if(remote_path)
node.set[:omnibus_updater][:full_url] = remote_path
directory node[:omnibus_updater][:cache_dir] do
recursive true
end
remote_file "omnibus_remote[#{File.basename(remote_path)}]" do
path File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))
source remote_path
backup false
checksum node[:omnibus_updater][:checksum] if node[:omnibus_updater][:checksum]
action :create_if_missing
only_if do
unless(version = node[:omnibus_updater][:version])
version = node[:omnibus_updater][:full_url].scan(%r{chef[_-](\d+\.\d+.\d+)}).flatten.first
end
if(node[:omnibus_updater][:always_download])
# warn if there may be unexpected behavior
node[:omnibus_updater][:prevent_downgrade] &&
Chef::Log.warn("omnibus_updater: prevent_downgrade is ignored when always_download is true")
Chef::Log.debug "Omnibus Updater remote path: #{remote_path}"
true
elsif(node[:omnibus_updater][:prevent_downgrade])
# Return true if the found/specified version is newer
Gem::Version.new(version.to_s.sub(/\-.+$/, '')) > Gem::Version.new(Chef::VERSION)
else
# default is to install if the versions don't match
Chef::VERSION != version.to_s.sub(/\-.+$/, '')
end
end
end
else
Chef::Log.warn 'Failed to retrieve omnibus download URL'
end
include_recipe 'omnibus_updater::old_package_cleaner'

View File

@@ -0,0 +1,70 @@
#
# Cookbook Name:: omnibus_updater
# Recipe:: installer
#
# Copyright 2014, Heavy Water Ops, LLC
#
# 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 'omnibus_updater'
remote_path = node[:omnibus_updater][:full_url].to_s
file '/tmp/nocheck' do
content 'conflict=nocheck\naction=nocheck'
only_if { node['os'] =~ /^solaris/ }
end
service 'chef-client' do
action :nothing
end
ruby_block 'omnibus chef killer' do
block do
raise 'New omnibus chef version installed. Killing Chef run!'
end
action :nothing
only_if do
node[:omnibus_updater][:kill_chef_on_upgrade]
end
end
execute "omnibus_install[#{File.basename(remote_path)}]" do
case File.extname(remote_path)
when '.deb'
command "dpkg -i #{File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))}"
when '.rpm'
command "rpm -Uvh --oldpackage #{File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))}"
when '.sh'
command "/bin/sh #{File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))}"
when '.solaris'
command "pkgadd -n -d #{File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))} -a /tmp/nocheck chef"
else
raise "Unknown package type encountered for install: #{File.extname(remote_path)}"
end
action :nothing
if(node[:omnibus_updater][:restart_chef_service])
notifies :restart, resources(:service => 'chef-client'), :immediately
end
notifies :create, resources(:ruby_block => 'omnibus chef killer'), :immediately
end
ruby_block 'Omnibus Chef install notifier' do
block{ true }
action :nothing
subscribes :create, resources(:remote_file => "omnibus_remote[#{File.basename(remote_path)}]"), :immediately
notifies :run, resources(:execute => "omnibus_install[#{File.basename(remote_path)}]"), :delayed
only_if { node['chef_packages']['chef']['version'] != node['omnibus_updater']['version'] }
end
include_recipe 'omnibus_updater::old_package_cleaner'

View File

@@ -0,0 +1,34 @@
#
# Cookbook Name:: omnibus_updater
# Recipe:: old_package_cleaner
#
# Copyright 2014, Heavy Water Ops, LLC
#
# 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.
#
old_pkgs =
if(::File.exist?(node[:omnibus_updater][:cache_dir]))
Dir.glob(File.join(node[:omnibus_updater][:cache_dir], 'chef_*')).find_all do |file|
!file.include?(node[:omnibus_updater][:version].to_s) && !file.scan(/\.(rpm|deb)$/).empty?
end
else
[]
end
old_pkgs.each do |filename|
file filename do
action :delete
backup 1
end
end

View File

@@ -0,0 +1,29 @@
#
# Cookbook Name:: omnibus_updater
# Recipe:: remove_chef_system_gem
#
# Copyright 2014, Heavy Water Ops, LLC
#
# 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.
#
gem_package 'chef' do
action :purge
only_if do
Chef::Provider::Package::Rubygems.new(
Chef::Resource::GemPackage.new('dummy_package')
).gem_env.gem_paths.detect{|path|
path.start_with?('/opt/omnibus') || path.start_with?('/opt/chef')
}.nil? && node[:omnibus_updater][:remove_chef_system_gem]
end
end