Skip to content
This repository has been archived by the owner on Apr 7, 2018. It is now read-only.

Commit

Permalink
Merge pull request #108 from hw-cookbooks/develop
Browse files Browse the repository at this point in the history
Prep 1.1.0 release
  • Loading branch information
cwjohnston committed Mar 10, 2016
2 parents 70fafda + 8439dec commit f2d196e
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 49 deletions.
15 changes: 9 additions & 6 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ platforms:
driver_config:
require_chef_omnibus: '11.14'
box: ubuntu1204
- name: ubuntu-10.04
driver_config:
require_chef_omnibus: '11.14'
box: ubuntu1004
- name: centos-7.0
driver_config:
require_chef_omnibus: '11.14'
Expand All @@ -21,10 +17,17 @@ platforms:
driver_config:
require_chef_omnibus: '11.14'
box: centos64
- name: centos-5.8
- name: centos-5.11
driver_config:
require_chef_omnibus: '11.14'
box: centos511
- name: windows-2012r2
driver_config:
require_chef_omnibus: '11.14'
box: centos58
box: windows-2012r2
attributes:
omnibus_updater:
version: 12.5.1
suites:
- name: default
run_list:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v1.1.0
==========
* Add Windows support (only Chef client versions 12.5.1 and below).
* Improve upgrade behavior on Amazon Linux
* Explicitly require windows testing gems in order to support test-kitchen 1.6.x.

v1.0.6
======
* Get rid of warnings about defined constant
Expand Down
2 changes: 1 addition & 1 deletion Cheffile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
site 'http://community.opscode.com/api/v1'
site 'https://supermarket.chef.io/api/v1'

cookbook 'omnibus_updater', path: './'
cookbook 'omnibus_updater_test', path: './test/kitchen/cookbooks/omnibus_updater_test'
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ group :test do
gem 'vagabond'
gem 'test-kitchen'
gem 'kitchen-vagrant'
gem 'winrm'
gem 'winrm-fs'
end
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Supports
- ubuntu
- mac_os_x
- solaris
- windows

Usage
=====
Expand Down Expand Up @@ -88,11 +89,27 @@ to a role but should then be skipped for example on a Chef server.
Prevent Downgrade
-----------------

If you want to prevent the updater from downgrading chef on a node, you
If you want to prevent the updater from downgrading chef on a node, you
can set the `prevent_downgrade` attribute to true. This can be useful
for testing new versions manually. Note that the `always_download`
for testing new versions manually. Note that the `always_download`
attribute takes precedence if set.

Warnings
========

Windows Support
---------------
Windows support is available in versions 1.0.8 and higher; however, we only support Chef Client versions 12.5.1 and below, due to a [known bug in 12.6.0](https://github.com/chef/chef/issues/4623). This is reflected in the Windows test suite.

If you would like to wrap this cookbook in order to prevent OmnibusUpdater with version 12.6.0 on Windows, you may do something like the following:
```
if((node[:chef_packages][:chef][:version] == '12.6.0') && node[:os].downcase.include?('windows'))
Chef::Log.warn 'Omnibus updater cannot upgrade or downgrade a Windows 12.6.0 installation, skipping'
else
include_recipe 'omnibus_updater'
end
```

Infos
=====

Expand Down
1 change: 1 addition & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@
default[:omnibus_updater][:prevent_downgrade] = false
default[:omnibus_updater][:restart_chef_service] = false
default[:omnibus_updater][:checksum] = nil
default[:omnibus_updater][:addlocal] = 'ChefClientFeature,ChefServiceFeature' #Recommend adding ChefPSModuleFeature for clients 12.4.0 and up on windows platform.
2 changes: 2 additions & 0 deletions libraries/omnitrucker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def collect_attributes(node, args={})
@attrs = {:platform => set[:platform], :platform_version => set[:platform_version].to_i}
elsif(set[:platform_family] == 'mac_os_x')
@attrs = {:platform => set[:platform_family], :platform_version => [set[:platform_version].to_f, 10.7].min}
elsif(set[:platform_family] == 'windows')
@attrs ={:platform => set[:platform], :platform_version => '2008r2'}
else
@attrs = {:platform => set[:platform], :platform_version => set[:platform_version]}
end
Expand Down
7 changes: 5 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
license "Apache 2.0"
description "Chef omnibus package updater and installer"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "1.0.6"
version "1.1.0"

%w(redhat centos amazon scientific oracle debian ubuntu mac_os_x solaris).each do |plat|
%w(redhat centos amazon scientific oracle debian ubuntu mac_os_x solaris windows).each do |plat|
supports plat
end

source_url 'https://github.com/hw-cookbooks/omnibus_updater' if respond_to?(:source_url)
issues_url 'https://github.com/hw-cookbooks/omnibus_updater/issues' if respond_to?(:issues_url)
7 changes: 6 additions & 1 deletion recipes/downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@
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
case node['platform_family']
when 'windows'
version = node[:omnibus_updater][:full_url].scan(%r{chef-windows|client-(\d+\.\d+.\d+)}).flatten.first
else
version = node[:omnibus_updater][:full_url].scan(%r{chef[_-](\d+\.\d+.\d+)}).flatten.first
end
end
if(node[:omnibus_updater][:always_download])
# warn if there may be unexpected behavior
Expand Down
106 changes: 71 additions & 35 deletions recipes/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,87 @@
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!'
if(node[:platform] == 'windows')
version = node[:omnibus_updater][:version] || remote_path.scan(%r{chef-windows|client-(\d+\.\d+.\d+)}).flatten.first
Chef::Recipe.send(:include, Chef::Mixin::ShellOut)
chef_version = shell_out("chef-client -v")
chef_version = chef_version.stdout

if node['chef_packages']['chef']['version'] != node['omnibus_updater']['version']
execute 'chef-uninstall' do
command 'wmic product where "name like \'Chef Client%% %%\'" call uninstall /nointeractive'
action :nothing
end
execute 'chef-install' do
command "msiexec.exe /qn /i #{File.basename(remote_path)} ADDLOCAL=\"#{node[:omnibus_updater][:addlocal]}\""
cwd node[:omnibus_updater][:cache_dir]
action :nothing
end
execute 'chef-service-kill' do
command 'taskkill /F /FI "SERVICES eq chef-client"'
action :nothing
end

ruby_block 'Omnibus Chef Update' do
block {true}
notifies :run, 'execute[chef-service-kill]', :immediately
notifies :run, 'execute[chef-uninstall]', :immediately
notifies :run, 'execute[chef-install]', :immediately
notifies :start, 'service[chef-client]', :immediately if node[:omnibus_updater][:restart_chef_service]
not_if { chef_version == "Chef: #{version}\r\n" }
end
end
action :nothing
only_if do
node[:omnibus_updater][:kill_chef_on_upgrade]
else
file '/tmp/nocheck' do
content 'conflict=nocheck\naction=nocheck'
only_if { node['os'] =~ /^solaris/ }
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)}"
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
action :nothing
if(node[:omnibus_updater][:restart_chef_service])
notifies :restart, resources(:service => 'chef-client'), :immediately

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'
if node['platform'] == 'amazon'
command "rpm -e chef && rpm -Uvh --oldpackage #{File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))}"
else
command "rpm -Uvh --oldpackage #{File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))}"
end
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
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'] }
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
end

include_recipe 'omnibus_updater::old_package_cleaner'
4 changes: 2 additions & 2 deletions recipes/old_package_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

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?
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|msi)$/).empty?
end
else
[]
Expand Down

0 comments on commit f2d196e

Please sign in to comment.