Replace omnibus_updater with chef_client_updater

omnibus_updater is deprecated
This commit is contained in:
Greg Karékinian 2017-05-02 11:53:33 +02:00
parent 030b2501eb
commit 943b4ace1f
23 changed files with 285 additions and 677 deletions

4
Batali
View File

@ -26,13 +26,13 @@ Batali.define do
git: 'https://github.com/phlipper/chef-redis.git', git: 'https://github.com/phlipper/chef-redis.git',
ref: 'v0.5.6' ref: 'v0.5.6'
cookbook 'firewall', '~> 2.6.1' cookbook 'firewall', '~> 2.6.1'
cookbook 'chef_nginx' cookbook 'chef_nginx', '~> 6.0.2'
cookbook 'build-essential' cookbook 'build-essential'
cookbook 'mysql' cookbook 'mysql'
cookbook 'postgresql', '~> 6.1' cookbook 'postgresql', '~> 6.1'
cookbook 'database' cookbook 'database'
cookbook 'mysql2_chef_gem' cookbook 'mysql2_chef_gem'
cookbook 'omnibus_updater' cookbook 'chef_client_updater', '~> 1.0.2'
cookbook 'timezone-ii' cookbook 'timezone-ii'
cookbook 'nodejs', '~> 3.0.0' cookbook 'nodejs', '~> 3.0.0'
cookbook 'ark' cookbook 'ark'

View File

@ -978,15 +978,18 @@
} }
}, },
{ {
"name": "omnibus_updater", "name": "chef_client_updater",
"dependencies": [ "dependencies": [
[
"compat_resource",
">= 12.16.3"
]
], ],
"version": "3.0.2", "version": "1.0.2",
"source": { "source": {
"type": "Batali::Source::Site", "type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/omnibus_updater/versions/3.0.2/download", "url": "https://supermarket.chef.io:443/api/v1/cookbooks/chef_client_updater/versions/1.0.2/download",
"version": "3.0.2" "version": "1.0.2"
} }
}, },
{ {

View File

@ -0,0 +1 @@
~FC016

View File

@ -0,0 +1,16 @@
# chef_client_updater Cookbook CHANGELOG
This file is used to list changes made in each version of the chef_client_updater cookbook.
## 1.0.2 (2017-04-07)
- Fix Chef 13 compatibility by using Kernel.exec not exec
## 1.0.1 (2017-04-07)
- point the URLs at the new project repo
- Add ChefSpec matcher
## 1.0.0
- Initial release of chef_client_updater

View File

@ -0,0 +1,69 @@
# chef_client_updater
[![Build Status](https://travis-ci.org/chef-cookbooks/chef_client_updater.svg?branch=master)](https://travis-ci.org/chef-cookbooks/chef_client_updater) [![Cookbook Version](https://img.shields.io/cookbook/v/chef_client_updater.svg)](https://supermarket.chef.io/cookbooks/chef_client_updater)
This cookbook updates the chef-client
## Requirements
### Platforms
- All platforms with a chef-client package on downloads.chef.io
### Chef
- Chef 12.1+
### Cookbooks
- compat_resource
### Usage
This cookbook provides both a custom resource and a default recipe. The default recipe simply uses the custom resource with a set of attributes. You can add chef_client_updater::default to your run list or use the custom resource in a wrapper cookbook.
### chef_client_updater
Installs the mixlib-install/mixlib-install gems and upgrades the chef-client.
#### properties
- `channel` - The chef channel you fetch the chef client from. `stable` contains all officially released chef-client builds where as `current` contains unreleased builds. Default: `stable`
- `prevent_downgrade` - Don't allow this cookbook to downgrade the chef-client version. Default: true
- `version` - The version of the chef-client to install. Default :latest
- `post_install_action` - After installing the chef-client what should we do. `exec` to exec the new client or `kill` to kill the client and rely on the init system to start up the new version. Default: `exec`
- `exec_command` - The chef-client command. default: $PROGRAM_NAME.split(' ').first
- `exec_args` - An array of arguments to exec the chef-client with. default: ARGV
#### examples
```ruby
chef_client_updater 'Install latest'
```
```ruby
chef_client_updater 'Install 12.13.36 and kill' do
version '12.13.36'
post_install_action 'kill'
end
```
## License & Authors
- Author: Tim Smith ([tsmith@chef.io](mailto:tsmith@chef.io))
```text
Copyright:: 2016-2017, Chef Software, 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.
```

View File

@ -0,0 +1,29 @@
#
# Cookbook:: chef_client_updater
# Attributes:: default
#
# Copyright:: 2016-2017, Chef Software, 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.
# stable or current channel
default['chef_client_updater']['channel'] = 'stable'
# prevent a newer client "updating" to an older client
default['chef_client_updater']['prevent_downgrade'] = true
# the version to install (ex: '12.12.13') or 'latest'
default['chef_client_updater']['version'] = 'latest'
# kill the client post install or exec the client post install for non-service based installs
default['chef_client_updater']['post_install_action'] = 'kill'

View File

@ -0,0 +1,7 @@
if defined?(ChefSpec)
ChefSpec.define_matcher(:chef_client_updater)
def update_chef_client_updater(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:chef_client_updater, :update, resource_name)
end
end

View File

@ -0,0 +1 @@
{"name":"chef_client_updater","version":"1.0.2","description":"Upgrades chef-client to specified releases","long_description":"Upgrades chef-client to specified releases","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache-2.0","platforms":{"amazon":">= 0.0.0","centos":">= 0.0.0","debian":">= 0.0.0","mac_os_x":">= 0.0.0","opensuse":">= 0.0.0","opensuseleap":">= 0.0.0","oracle":">= 0.0.0","redhat":">= 0.0.0","scientific":">= 0.0.0","solaris":">= 0.0.0","suse":">= 0.0.0","ubuntu":">= 0.0.0","windows":">= 0.0.0","aix":">= 0.0.0"},"dependencies":{"compat_resource":">= 12.16.3"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/chef-cookbooks/chef_client_updater","issues_url":"https://github.com/chef-cookbooks/chef_client_updater/issues","chef_version":[[">= 12.1"]],"ohai_version":[]}

View File

@ -1,30 +1,25 @@
# #
# Cookbook:: omnibus_updater # Author:: Tim Smith (<tsmith@chef.io>)
# Library:: omnibuschecker # Cookbook:: chef_client_updater
# Recipe:: default
# #
# Copyright:: 2014-2017, Heavy Water Ops, LLC # Copyright:: 2016-2017, Chef Software, Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
#
module OmnibusChecker chef_client_updater 'update chef-client' do
def is_omnibus? channel node['chef_client_updater']['channel']
Gem.bindir =~ %r{/opt/(opscode|chef)/} version node['chef_client_updater']['version']
end prevent_downgrade node['chef_client_updater']['prevent_downgrade']
end post_install_action node['chef_client_updater']['post_install_action']
OmnibusChecker.send(:extend, OmnibusChecker)
unless Chef::Recipe.instance_methods.include?(:is_omnibus?)
Chef::Recipe.send(:include, OmnibusChecker)
end end

View File

@ -0,0 +1,136 @@
#
# Cookbook:: chef_client_updater
# Resource:: updater
#
# Copyright:: 2016-2017, Will Jordan
# Copyright:: 2016-2017, Chef Software, 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.
#
provides 'chef_client_updater'
property :channel, [String, Symbol], default: :stable
property :prevent_downgrade, [true, false], default: false
property :version, [String, Symbol], default: :latest
property :post_install_action, String, default: 'exec'
property :exec_command, String, default: $PROGRAM_NAME.split(' ').first
property :exec_args, Array, default: ARGV
action :update do
if update_necessary? # ~FC023
converge_by "Upgraded chef-client #{current_version} to #{desired_version}" do
upgrade_command = Mixlib::ShellOut.new(mixlib_install.install_command)
upgrade_command.run_command
run_post_install_action
end
end
end
action_class.class_eval do
def load_mixlib_install
require 'mixlib/install'
rescue LoadError
Chef::Log.info('mixlib-install gem not found. Installing now')
chef_gem 'mixlib-install' do
compile_time true if respond_to?(:compile_time)
end
require 'mixlib/install'
end
def load_mixlib_versioning
require 'mixlib/versioning'
rescue LoadError
Chef::Log.info('mixlib-versioning gem not found. Installing now')
chef_gem 'mixlib-versioning' do
compile_time true if respond_to?(:compile_time)
end
require 'mixlib/versioning'
end
def mixlib_install
load_mixlib_install
options = {
product_name: 'chef',
platform_version_compatibility_mode: true,
channel: new_resource.channel.to_sym,
product_version: new_resource.version == 'latest' ? :latest : new_resource.version,
}
Mixlib::Install.new(options)
end
# why would we use this when mixlib-install has a current_version method?
# well mixlib-version parses the manifest JSON, which might not be there.
# ohai handles this better IMO
def current_version
node['chef_packages']['chef']['version']
end
def desired_version
new_resource.version == 'latest' ? mixlib_install.available_versions.last : new_resource.version
end
# why wouldn't we use the built in update_available? method in mixlib-install?
# well that would use current_version from mixlib-install and it has no
# concept or preventing downgrades
def update_necessary?
load_mixlib_versioning
cur_version = Mixlib::Versioning.parse(current_version)
des_version = Mixlib::Versioning.parse(desired_version)
new_resource.prevent_downgrade ? (des_version > cur_version) : (des_version != cur_version)
end
def eval_post_install_action
return unless new_resource.post_install_action == 'exec'
if Chef::Config[:interval]
Chef::Log.warn 'post_install_action "exec" not supported for long-running client process -- changing to "kill".'
new_resource.post_install_action = 'kill'
end
return if Process.respond_to?(:exec)
Chef::Log.warn 'post_install_action Process.exec not available -- changing to "kill".'
new_resource.post_install_action = 'kill'
end
def run_post_install_action
# make sure the passed action will actually work
eval_post_install_action
case new_resource.post_install_action
when 'exec'
if Chef::Config[:local_mode]
Chef::Log.info 'Shutting down local-mode server.'
if Chef::Application.respond_to?(:destroy_server_connectivity)
Chef::Application.destroy_server_connectivity
elsif defined?(Chef::LocalMode) && Chef::LocalMode.respond_to?(:destroy_server_connectivity)
Chef::LocalMode.destroy_server_connectivity
end
end
Chef::Log.warn 'Replacing ourselves with the new version of Chef to continue the run.'
Kernel.exec(new_resource.exec_command, *new_resource.exec_args)
when 'kill'
if Chef::Config[:client_fork] && Process.ppid != 1
Chef::Log.warn 'Chef client is defined for forked runs. Sending TERM to parent process!'
Process.kill('TERM', Process.ppid)
end
Chef::Log.warn 'New chef-client installed. Forcing chef exit!'
exit(213)
else
raise "Unexpected post_install_action behavior: #{new_resource.post_install_action}"
end
end
end

View File

@ -1,149 +0,0 @@
# omnibus_updater Cookbook CHANGELOG
This file is used to list changes made in each version of the omnibus_updater cookbook.
## 3.0.2 (2017-03-07)
- Fix version detection for macOS systems
- Test with Local Delivery instead of Rake
## 3.0.1 (2017-01-05)
- Remove the remaining system gem reference
## 3.0.0 (2017-01-05)
- Added support for the new upgrade exit code (213) introduced with RFC062 and first shipped in chef 12.15.19
- Fix support for upgrading Windows client 12.6 and later by first moving the install directory
- Remove the recipe to cleanup system ruby chef installs. We should assume everyone is on Omnibus installs at this point and this same functionality can be easily implemented in your own recipes
- Added suse, opensuse, and opensuseleap to the metadata
## 2.0.0 (2016-08-19)
- Hard fail on unsupported platforms now
- Add suse support
- Add additional chefspec tests
## 1.2.1 (2016-08-19)
- Use the improved rakefile
- Fix github URLs in the metadata
- Add testing on additional platforms to kitchen config
- fix 1.2.0 no implicit conversion of nil to string. fixes #123
## 1.2.0 (2016-08-18)
- Add OS X DMG Support and fix Mac OS X Version Determination
- Add a potential Restart Fix
- Add chef_version metadata to the metadata.rb file
- Change maintainership to Chef and add standard Chef contributing, test, and maintainer docs
- Renamed the test recipe for consistency and removed the use of minitest
- Swapped Librarian for Berkshelf
- Added testing in Travis CI using ChefDK
- Resolved Foodcritic FC001/FC043 warnings
- Resolved all Cookstyle warnings
- Identify Fedora to be EL7 not EL6
- Avoid a node.set deprecation warning
- No need to warn on Debian 5\. No one should be on this now.
- Add a test for the standard flows
# 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
- update Chef download url
- Updates supported versions
- require chef/rest
- use Chef::Mash explicitly
- Define the Chef::Mash constant if not provided by chef
- add test suites for ubuntu 14.04 and centos 7
# v1.0.4
- file_cache_path path to store chef-client
- Avoid deleting chef-server packages if using the same cache dir
- Only backup the last old chef client file
- make sure directory exists before trying to write to it
# v1.0.2
- Maintenance updates
- Support for Fedora
- omnitrucker solaris update
- bug fixes
# v1.0.0
- Breaking change: `:always_download` is now defaulted to false
- Add solaris package install support (#37 thanks @jtimberman)
- Update notifies/subscribes usage to support older Chefs (#38 thanks @spheromak)
# v0.2.8
- Always download the package (thanks @miketheman for swiftly pointing out the issue!)
# v0.2.6
- Work with amazon linux (thanks @thommay)
- Disable updates on debian 5 (thanks @ianand0204)
- Only use major version on debian systems (thanks @kvs)
- Allow prevention of downgrades (thanks @buysse)
- Add support for restarting chef service after upgrade (thanks @andrewfraley)
# v0.2.4
- Only download omnibus package if version difference detected (#20 #22 #23)
- Provide attribute for always downloading package even if version matches
# v0.2.3
- Use chef internals for interactions with omnitruck to provide proper proxy support (#19)
# v0.2.0
- Use omnitruck client for url generation for package fetching
- Use `prerelease` in favor of `allow_release_clients`
# v0.1.2
- Fix regression on debian package path construction (thanks [ashmere](https://github.com/ashmere))
# v0.1.1
- Search for proper version suffix if not provided (removes default '-1')
- Do not allow release clients by default when version search is enabled
- Push omnibus package installation to the end of run (reduces issue described in #10)
- Allow updater to be disabled via attribute (thanks [Teemu Matilainen](https://github.com/tmatilai))
# v0.1.0
- Fix redhat related versioning issues
- Remove requirement for '-1' suffix on versions
- Initial support for automatic latest version install
# v0.0.5
- Add support for Ubuntu 12.10
- Path fixes for non-64 bit packages (thanks [ashmere](https://github.com/ashmere))
# v0.0.4
- Use new aws bucket by default
- Update file key building
# v0.0.3
- Path fix for debian omnibus packages (thanks [ashmere](https://github.com/ashmere))
# v0.0.2
- Add robust check when uninstalling chef gem to prevent removal from omnibus
# v0.0.1
- Initial release

View File

@ -1,101 +0,0 @@
# omnibus_updater cookbook
[![Build Status](https://travis-ci.org/chef-cookbooks/omnibus_updater.svg?branch=master)](http://travis-ci.org/chef-cookbooks/omnibus_updater) [![Cookbook Version](https://img.shields.io/cookbook/v/omnibus_updater.svg)](https://supermarket.chef.io/cookbooks/omnibus_updater)
This cookbook allows you to upgrade the omnibus based Chef install package via Chef. You can run either latest or pin to specific version.
## Requirements
### Platforms
- Debian / Ubuntu
- Mac OS X
- RHEL (redhat, centos, amazon, scientific, oracle)
- Solaris
- SLES / openSUSE
- Windows
### Chef
- Chef 11+
### Cookbooks
- none
## Usage
Add the recipe to your run list and specify what version should be installed on the node:
`knife node run_list add recipe[omnibus_updater]`
In your role you'll likely want to set the version. It defaults to nothing, and will install the latest..
```ruby
override_attributes(
:omnibus_updater => {
:version => '11.4.0'
}
)
```
## Features
### Latest Version
Force installation of the latest version regardless of value stored in version attribute by setting the `force_latest` attribute.
### Chef Killing
By default the omnibus updater will kill the chef instance by raising an exception. You can turn this off using the `kill_chef_on_upgrade` attribute. It is not recommended to turn this off. Internal chef libraries may change, move, or no longer exist. The currently running instance can encounter unexpected states because of this. To prevent this, the updater will attempt to kill the Chef instance so that it can be restarted in a normal state.
When `kill_chef_on_upgrade` is true Test-kitchen's converge stage will fail. To avoid this and attempt a second converge after the initial converge aborts, you can configure `.kitchen.yml` to retry a converge given a specific exit code from `node['omnibus_updater']['kill_chef_on_upgrade_exit_code']`. The second converge should pick up the new chef-client version and exit without error. The following is how to accomplish this:
```yaml
provisioner:
retry_on_exit_code:
- 213
max_retries: 1
wait_for_retry: 1
client_rb:
exit_status: :enabled
client_fork: false
```
Exit code 213 is a special designation for Chef Client Upgrade and only exists in Chef Client >= 12.15.19\. If using an older client, you can replace exit code 213 (Chef upgrade) with 3 (SIGTERM recvd) as a workaround. Exit codes are documented here: <https://github.com/chef/chef-rfc/blob/master/rfc062-exit-status.md>
## Restart chef-client Service
Use the `restart_chef_service` attribute to restart chef-client if you have it running as a service.
### Prerelease
Prereleases can be installed via the auto-installation using `prerelease` attribute.
### Disable
If you want to disable the updater you can set the `disabled` attribute to true. This might be useful if the cookbook is added 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 can set the `prevent_downgrade` attribute to true. This can be useful for testing new versions manually. Note that the `always_download` attribute takes precedence if set.
## License & Authors
- Author: Chris Roberts ([chrisroberts.code@gmail.com](mailto:chrisroberts.code@gmail.com))
```text
Copyright:: 2010-2016, Chef Software, 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.
```

View File

@ -1,32 +0,0 @@
#
# Cookbook:: omnibus_updater
# Attributes:: default
#
# Copyright:: 2014-2017, 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.
#
default['omnibus_updater']['version'] = nil
default['omnibus_updater']['force_latest'] = false
default['omnibus_updater']['cache_dir'] = "#{Chef::Config[:file_cache_path]}/omnibus_updater"
default['omnibus_updater']['cache_omnibus_installer'] = false
default['omnibus_updater']['prerelease'] = false
default['omnibus_updater']['disabled'] = false
default['omnibus_updater']['kill_chef_on_upgrade'] = true
default['omnibus_updater']['kill_chef_on_upgrade_exit_code'] = 213
default['omnibus_updater']['always_download'] = false
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.

View File

@ -1,102 +0,0 @@
#
# Cookbook:: omnibus_updater
# Library:: omnitrucker
#
# Copyright:: 2014-2017, 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.
#
require 'chef/rest'
require 'chef/mash'
require 'net/http'
Chef::Mash = Mash unless Chef.constants.include?(:Mash)
module OmnibusTrucker
class << self
URL_MAP = {
p: :platform, pv: :platform_version, m: :machine,
v: :version, prerelease: :prerelease,
nightlies: :nightlies
}.freeze unless defined?(URL_MAP)
def build_url(*opts)
args = node = nil
opts.each do |o|
if o.is_a?(Hash)
args = o
elsif o.is_a?(Chef::Node)
node = o
else
raise ArgumentError.new "Provided argument is not allowed: #{o.class}"
end
end
args ||= {}
args = collect_attributes(node).merge(args) if node
url = args[:url] || "http://www.chef.io/chef/download#{'-server' if args[:server]}"
u_args = URL_MAP.map do |u_k, a_k|
"#{u_k}=#{args[a_k]}" unless args[a_k].nil?
end.compact
"#{url}?#{u_args.join('&')}"
end
def collect_attributes(node, args = {})
set = Chef::Mash[
%w(platform_family platform platform_version).map do |k|
[k, args[k] || node[k]]
end
]
unless @attrs
if set['platform'] == 'amazon'
@attrs = { platform: 'el', platform_version: 6 }
elsif set['platform_family'] == 'fedora'
@attrs = { platform: 'el', platform_version: 7 }
elsif set['platform_family'] == 'rhel'
@attrs = { platform: 'el', platform_version: set['platform_version'].to_i }
elsif set['platform'] == 'debian'
@attrs = { platform: set['platform'], platform_version: set['platform_version'].to_i }
elsif set['platform'] =~ /opensuse/
@attrs = { platform: 'suse', platform_version: 13 }
elsif set['platform_family'] == 'suse'
@attrs = { platform: 'sles', platform_version: 12 }
elsif set['platform_family'] == 'mac_os_x'
major, minor, _patch = set['platform_version'].split('.').map { |v| String(v) }
minor = [minor.to_i, 11].min # this is somewhat of a hack, we need to prevent this recipe to construct links for 10.12 for which there is no download yet...
@attrs = { platform: set['platform_family'], platform_version: [[major, minor].join('.'), '10.7'].max { |x, y| Gem::Version.new(x) <=> Gem::Version.new(y) } }
elsif set['platform_family'] == 'windows'
@attrs = { platform: set['platform'], platform_version: '2008r2' }
else
@attrs = { platform: set['platform'], platform_version: set['platform_version'] }
end
@attrs[:machine] = args[:machine] || node['kernel']['machine']
@attrs[:machine] = 'i386' if set['platform_family'] == 'solaris2' && @attrs[:machine] == 'i86pc'
end
@attrs
end
def url(url_or_node, node = nil)
if url_or_node.is_a?(Chef::Node)
url = build_url(url_or_node)
node = url_or_node
else
url = url_or_node
raise 'Node instance is required for Omnitruck.url!' unless node
end
Chef::Log.info("Using URL '#{url}' for chef-download") unless url.nil?
request = Chef::REST::RESTRequest.new(:head, URI.parse(url), nil)
result = request.call
result['location'] if result.is_a?(Net::HTTPRedirection)
end
end
end

View File

@ -1 +0,0 @@
{"name":"omnibus_updater","version":"3.0.2","description":"Chef omnibus package updater and installer","long_description":"# omnibus_updater cookbook\n\n[![Build Status](https://travis-ci.org/chef-cookbooks/omnibus_updater.svg?branch=master)](http://travis-ci.org/chef-cookbooks/omnibus_updater) [![Cookbook Version](https://img.shields.io/cookbook/v/omnibus_updater.svg)](https://supermarket.chef.io/cookbooks/omnibus_updater)\n\nThis cookbook allows you to upgrade the omnibus based Chef install package via Chef. You can run either latest or pin to specific version.\n\n## Requirements\n\n### Platforms\n\n- Debian / Ubuntu\n- Mac OS X\n- RHEL (redhat, centos, amazon, scientific, oracle)\n- Solaris\n- SLES / openSUSE\n- Windows\n\n### Chef\n\n- Chef 11+\n\n### Cookbooks\n\n- none\n\n## Usage\n\nAdd the recipe to your run list and specify what version should be installed on the node:\n\n`knife node run_list add recipe[omnibus_updater]`\n\nIn your role you'll likely want to set the version. It defaults to nothing, and will install the latest..\n\n```ruby\noverride_attributes(\n :omnibus_updater => {\n :version => '11.4.0'\n }\n)\n```\n\n## Features\n\n### Latest Version\n\nForce installation of the latest version regardless of value stored in version attribute by setting the `force_latest` attribute.\n\n### Chef Killing\n\nBy default the omnibus updater will kill the chef instance by raising an exception. You can turn this off using the `kill_chef_on_upgrade` attribute. It is not recommended to turn this off. Internal chef libraries may change, move, or no longer exist. The currently running instance can encounter unexpected states because of this. To prevent this, the updater will attempt to kill the Chef instance so that it can be restarted in a normal state.\n\nWhen `kill_chef_on_upgrade` is true Test-kitchen's converge stage will fail. To avoid this and attempt a second converge after the initial converge aborts, you can configure `.kitchen.yml` to retry a converge given a specific exit code from `node['omnibus_updater']['kill_chef_on_upgrade_exit_code']`. The second converge should pick up the new chef-client version and exit without error. The following is how to accomplish this:\n\n```yaml\nprovisioner:\n retry_on_exit_code:\n - 213\n max_retries: 1\n wait_for_retry: 1\n client_rb:\n exit_status: :enabled\n client_fork: false\n```\n\nExit code 213 is a special designation for Chef Client Upgrade and only exists in Chef Client >= 12.15.19\\. If using an older client, you can replace exit code 213 (Chef upgrade) with 3 (SIGTERM recvd) as a workaround. Exit codes are documented here: <https://github.com/chef/chef-rfc/blob/master/rfc062-exit-status.md>\n\n## Restart chef-client Service\n\nUse the `restart_chef_service` attribute to restart chef-client if you have it running as a service.\n\n### Prerelease\n\nPrereleases can be installed via the auto-installation using `prerelease` attribute.\n\n### Disable\n\nIf you want to disable the updater you can set the `disabled` attribute to true. This might be useful if the cookbook is added to a role but should then be skipped for example on a Chef server.\n\n### Prevent Downgrade\n\nIf 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` attribute takes precedence if set.\n\n## License & Authors\n\n- Author: Chris Roberts ([chrisroberts.code@gmail.com](mailto:chrisroberts.code@gmail.com))\n\n```text\nCopyright:: 2010-2016, Chef Software, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"amazon":">= 0.0.0","centos":">= 0.0.0","debian":">= 0.0.0","mac_os_x":">= 0.0.0","opensuse":">= 0.0.0","opensuseleap":">= 0.0.0","oracle":">= 0.0.0","redhat":">= 0.0.0","scientific":">= 0.0.0","solaris":">= 0.0.0","suse":">= 0.0.0","ubuntu":">= 0.0.0","windows":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{}}

View File

@ -1,31 +0,0 @@
#
# Cookbook:: omnibus_updater
# Recipe:: default
#
# Copyright:: 2014-2017, 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.
#
# fail hard if we're on an unsupported platform
# feel free to open PRs to add additional platforms
unless platform_family?('debian', 'fedora', 'mac_os_x', 'rhel', 'solaris2', 'windows', 'suse')
Chef::Application.fatal! "Omnibus updater does not support the #{node['platform']} platform"
end
if node['omnibus_updater']['disabled']
Chef::Log.warn 'Omnibus updater disabled via `disabled` attribute'
else
include_recipe 'omnibus_updater::downloader'
include_recipe 'omnibus_updater::installer'
end

View File

@ -1,77 +0,0 @@
#
# Cookbook:: omnibus_updater
# Recipe:: downloader
#
# Copyright:: 2014-2017, 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
)
raise 'Could not construct URL for chef-download' if remote_path.nil?
end
if remote_path
node.normal['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 = case node['platform_family']
when 'windows'
node['omnibus_updater']['full_url'].scan(/chef-windows|client-(\d+\.\d+.\d+)/).flatten.first
else
node['omnibus_updater']['full_url'].scan(/chef[_-](\d+\.\d+.\d+)/).flatten.first
end
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

@ -1,124 +0,0 @@
#
# Cookbook:: omnibus_updater
# Recipe:: installer
#
# Copyright:: 2014-2017, 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']
service 'chef-client-omnibus' do
service_name 'chef-client'
supports status: true, restart: true
action :nothing
end
if platform?('windows')
version = node['omnibus_updater']['version'] || remote_path.scan(/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
# clean up previous upgrades
directory 'c:/opscode/chef.upgrade' do
action :delete
recursive true
end
if node['chef_packages']['chef']['version'] != node['omnibus_updater']['version']
execute 'chef-move' do
command 'move c:/opscode/chef c:/opscode/chef.upgrade'
action :nothing
end
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-move]', :immediately
notifies :run, 'execute[chef-uninstall]', :immediately
notifies :run, 'execute[chef-install]', :immediately
notifies :start, 'service[chef-client-omnibus]', :immediately if node['omnibus_updater']['restart_chef_service']
not_if { chef_version == "Chef: #{version}\r\n" }
end
end
else
file '/tmp/nocheck' do
content 'conflict=nocheck\naction=nocheck'
only_if { node['os'] =~ /^solaris/ }
end
ruby_block 'omnibus chef killer' do
block do
Chef::Application.fatal!('New omnibus chef version installed. Killing Chef run!', node['omnibus_updater']['kill_chef_on_upgrade_exit_code'])
end
action :nothing
only_if { node['omnibus_updater']['kill_chef_on_upgrade'] }
end
execute "omnibus_install[#{File.basename(remote_path)}]" do # ~FC009
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"
when '.dmg'
command <<-EOF
hdiutil detach "/Volumes/chef_software" >/dev/null 2>&1 || true
hdiutil attach "#{File.join(node['omnibus_updater']['cache_dir'], File.basename(remote_path))}" -mountpoint "/Volumes/chef_software"
cd / && /usr/sbin/installer -pkg `find "/Volumes/chef_software" -name \*.pkg` -target /
hdiutil detach "/Volumes/chef_software"
EOF
else
raise "Unknown package type encountered for install: #{File.extname(remote_path)}"
end
action :nothing
if node['omnibus_updater']['restart_chef_service']
notifies :restart, 'service[chef-client-omnibus]', :immediately
end
notifies :create, 'ruby_block[omnibus chef killer]', :immediately
end
ruby_block 'Omnibus Chef install notifier' do
block { true }
action :nothing
subscribes :create, "remote_file[omnibus_remote[#{File.basename(remote_path)}]]", :immediately
notifies :run, "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'

View File

@ -1,34 +0,0 @@
#
# Cookbook:: omnibus_updater
# Recipe:: old_package_cleaner
#
# Copyright:: 2014-2017, 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|msi|dmg)$/).empty?
end
else
[]
end
old_pkgs.each do |filename|
file filename do
action :delete
backup 1
end
end

View File

@ -12,5 +12,5 @@ depends 'sudo'
depends 'kosmos-postfix' depends 'kosmos-postfix'
depends 'hostname' depends 'hostname'
depends 'firewall' depends 'firewall'
depends 'omnibus_updater' depends 'chef_client_updater'
depends 'timezone-ii' depends 'timezone-ii'

View File

@ -9,9 +9,11 @@
include_recipe 'timezone-ii' include_recipe 'timezone-ii'
node.override['omnibus_updater']['version'] = '12.19.36' # Update chef to the chosen version
node.override['omnibus_updater']['kill_chef_on_upgrade'] = false chef_version = '12.19.36'
include_recipe 'omnibus_updater' chef_client_updater "Install #{chef_version}" do
version chef_version
end
package 'mailutils' package 'mailutils'
node.override['unattended-upgrades']['admin_email'] = 'ops@5apps.com' node.override['unattended-upgrades']['admin_email'] = 'ops@5apps.com'