Update cookbooks for Ubuntu 16.04 TLS
This commit is contained in:
parent
6430d71006
commit
8923d0d7ef
12
Batali
12
Batali
@ -6,9 +6,6 @@ Batali.define do
|
||||
cookbook 'mediawiki',
|
||||
git: 'https://github.com/67P/mediawiki-cookbook.git',
|
||||
ref: 'nginx'
|
||||
cookbook 'php-fpm',
|
||||
git: 'https://github.com/67P/cookbook-php-fpm.git',
|
||||
ref: 'ubuntu_systemd'
|
||||
cookbook 'wordpress',
|
||||
git: 'https://github.com/67P/wordpress-cookbook.git',
|
||||
ref: 'relax_dependencies'
|
||||
@ -17,7 +14,9 @@ Batali.define do
|
||||
cookbook 'application_nodejs',
|
||||
git: 'https://github.com/67p/application_nodejs.git',
|
||||
ref: 'master'
|
||||
cookbook 'php-fpm', '0.7.8'
|
||||
cookbook 'application', '4.1.6'
|
||||
cookbook 'php', '~> 3.0.0'
|
||||
cookbook 'users'
|
||||
cookbook 'sudo'
|
||||
cookbook 'hostname'
|
||||
@ -28,13 +27,16 @@ Batali.define do
|
||||
cookbook 'firewall'
|
||||
cookbook 'nginx'
|
||||
cookbook 'build-essential'
|
||||
cookbook 'mysql'
|
||||
cookbook 'mysql', '~> 8.3.0'
|
||||
cookbook 'database'
|
||||
cookbook 'mysql2_chef_gem'
|
||||
cookbook 'mysql2_chef_gem', '~> 2.0.1'
|
||||
cookbook 'omnibus_updater'
|
||||
cookbook 'timezone-ii'
|
||||
cookbook 'nodejs', '~> 3.0.0'
|
||||
cookbook 'ark'
|
||||
cookbook 'logrotate'
|
||||
|
||||
# Unused
|
||||
cookbook "yum-epel", '0.3.6'
|
||||
end
|
||||
|
||||
|
137
batali.manifest
137
batali.manifest
@ -36,7 +36,7 @@
|
||||
"version": "0.2.0",
|
||||
"source": {
|
||||
"url": "https://github.com/67P/mediawiki-cookbook.git",
|
||||
"ref": "b76104ab975ed95e238c10ae49722f0dacd7c0b2",
|
||||
"ref": "41d3c5129b5a6cd9c473e99339885bc1feac5d57",
|
||||
"type": "Batali::Source::Git",
|
||||
"subdirectory": null
|
||||
}
|
||||
@ -73,19 +73,19 @@
|
||||
">= 0.0.0"
|
||||
],
|
||||
[
|
||||
"windows",
|
||||
"iis",
|
||||
">= 0.0.0"
|
||||
],
|
||||
[
|
||||
"iis",
|
||||
"windows",
|
||||
">= 0.0.0"
|
||||
]
|
||||
],
|
||||
"version": "1.7.2",
|
||||
"version": "3.0.0",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/php/versions/1.7.2/download",
|
||||
"version": "1.7.2"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/php/versions/3.0.0/download",
|
||||
"version": "3.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -198,35 +198,28 @@
|
||||
{
|
||||
"name": "mysql",
|
||||
"dependencies": [
|
||||
[
|
||||
"yum-mysql-community",
|
||||
">= 0.0.0"
|
||||
|
||||
],
|
||||
[
|
||||
"smf",
|
||||
">= 0.0.0"
|
||||
]
|
||||
],
|
||||
"version": "6.1.3",
|
||||
"version": "8.3.0",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/mysql/versions/6.1.3/download",
|
||||
"version": "6.1.3"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/mysql/versions/8.3.0/download",
|
||||
"version": "8.3.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "yum-mysql-community",
|
||||
"name": "yum-epel",
|
||||
"dependencies": [
|
||||
[
|
||||
"yum",
|
||||
">= 3.2"
|
||||
"~> 3.0"
|
||||
]
|
||||
],
|
||||
"version": "0.1.21",
|
||||
"version": "0.3.6",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum-mysql-community/versions/0.1.21/download",
|
||||
"version": "0.1.21"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum-epel/versions/0.3.6/download",
|
||||
"version": "0.3.6"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -234,65 +227,11 @@
|
||||
"dependencies": [
|
||||
|
||||
],
|
||||
"version": "5.0.0",
|
||||
"version": "3.13.0",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum/versions/5.0.0/download",
|
||||
"version": "5.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "smf",
|
||||
"dependencies": [
|
||||
[
|
||||
"rbac",
|
||||
">= 1.0.1"
|
||||
]
|
||||
],
|
||||
"version": "2.2.8",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/smf/versions/2.2.8/download",
|
||||
"version": "2.2.8"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "rbac",
|
||||
"dependencies": [
|
||||
|
||||
],
|
||||
"version": "1.0.3",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/rbac/versions/1.0.3/download",
|
||||
"version": "1.0.3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "yum-epel",
|
||||
"dependencies": [
|
||||
[
|
||||
"compat_resource",
|
||||
">= 12.16.3"
|
||||
]
|
||||
],
|
||||
"version": "2.1.1",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum-epel/versions/2.1.1/download",
|
||||
"version": "2.1.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "compat_resource",
|
||||
"dependencies": [
|
||||
|
||||
],
|
||||
"version": "12.16.3",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/compat_resource/versions/12.16.3/download",
|
||||
"version": "12.16.3"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum/versions/3.13.0/download",
|
||||
"version": "3.13.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -506,42 +445,27 @@
|
||||
"version": "0.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "yum-epel",
|
||||
"dependencies": [
|
||||
[
|
||||
"yum",
|
||||
">= 3.6.3"
|
||||
]
|
||||
],
|
||||
"version": "0.7.1",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum-epel/versions/0.7.1/download",
|
||||
"version": "0.7.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "mysql2_chef_gem",
|
||||
"dependencies": [
|
||||
[
|
||||
"build-essential",
|
||||
">= 0.0.0"
|
||||
">= 2.4.0"
|
||||
],
|
||||
[
|
||||
"mysql",
|
||||
"~> 6.0"
|
||||
">= 8.2.0"
|
||||
],
|
||||
[
|
||||
"mariadb",
|
||||
">= 0.0.0"
|
||||
]
|
||||
],
|
||||
"version": "1.0.2",
|
||||
"version": "2.0.1",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/mysql2_chef_gem/versions/1.0.2/download",
|
||||
"version": "1.0.2"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/mysql2_chef_gem/versions/2.0.1/download",
|
||||
"version": "2.0.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -572,19 +496,18 @@
|
||||
"dependencies": [
|
||||
[
|
||||
"apt",
|
||||
"> 0"
|
||||
">= 0.0.0"
|
||||
],
|
||||
[
|
||||
"yum",
|
||||
">= 3.0"
|
||||
]
|
||||
],
|
||||
"version": "0.7.5",
|
||||
"version": "0.7.8",
|
||||
"source": {
|
||||
"url": "https://github.com/67P/cookbook-php-fpm.git",
|
||||
"ref": "00ae43a225cf23fd3ed937f27ab25aba8d812db9",
|
||||
"type": "Batali::Source::Git",
|
||||
"subdirectory": null
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/php-fpm/versions/0.7.8/download",
|
||||
"version": "0.7.8"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -612,7 +535,7 @@
|
||||
],
|
||||
[
|
||||
"mysql2_chef_gem",
|
||||
"~> 1.0.1"
|
||||
">= 1.0.1"
|
||||
],
|
||||
[
|
||||
"build-essential",
|
||||
@ -642,7 +565,7 @@
|
||||
"version": "3.0.0",
|
||||
"source": {
|
||||
"url": "https://github.com/67P/wordpress-cookbook.git",
|
||||
"ref": "bc6a108fcfb05c3fafd903bcf81ac33617e6cef9",
|
||||
"ref": "d6401db517476e6f3ab36aa92dfc0f5ed6a8a264",
|
||||
"type": "Batali::Source::Git",
|
||||
"subdirectory": null
|
||||
}
|
||||
|
@ -1,48 +0,0 @@
|
||||
# compat_resource Cookbook CHANGELOG
|
||||
|
||||
This file is used to list changes made in each version of the compat_resource cookbook.
|
||||
|
||||
## 12.16.2 (2016-11-09)
|
||||
|
||||
- Sync chef-client changes from Chef 12.16.42
|
||||
|
||||
## 12.16.1 (2016-10-20)
|
||||
|
||||
- add delayed_action helper
|
||||
|
||||
## 12.16.0 (2016-10-19)
|
||||
|
||||
- Sync chef-client changes from Chef 12.16.14
|
||||
|
||||
## 12.14.7 (2016-09-26)
|
||||
|
||||
- Update to 12.14.89 Chef
|
||||
- Fix autoload by applying fix from #106
|
||||
|
||||
## 12.14.6 (2016-09-20)
|
||||
|
||||
- Update backported codebase to Chef 12.14.77 which brings in yum_repository updates and why-run enabled by default in custom resources
|
||||
|
||||
## 12.14.5 (2016-09-19)
|
||||
|
||||
- Prevent spamming messages in Chefspec runs for cookbooks that depend on compat_resource
|
||||
|
||||
## 12.14.4 (2016-09-19)
|
||||
|
||||
- Fix delayed notifications cloning
|
||||
|
||||
## 12.14.3 (2016-09-12)
|
||||
|
||||
- Fix subscribes notifications
|
||||
|
||||
## 12.14.2 (2016-09-09)
|
||||
|
||||
- Improve documentation
|
||||
- keep ChefCompat::Resource defined even if we don't load
|
||||
|
||||
## 12.14.1 (2016-09-07)
|
||||
|
||||
- add yum_repository resource from Chef 12.14
|
||||
- Update the minimum chef version in the metadata to 12.1
|
||||
- Added maintainers files
|
||||
- suppress constant redef warnings when running chefspec
|
@ -1,60 +0,0 @@
|
||||
# compat_resource cookbook
|
||||
|
||||
[](https://travis-ci.org/chef-cookbooks/compat_resource) [](https://supermarket.chef.io/cookbooks/compat_resource)
|
||||
|
||||
This cookbook backports functionality introduced in the latest chef-client releases to any chef-client from 12.1 onwards. This includes [Custom Resource](https://docs.chef.io/custom_resources.html) functionality, notification improvements, as well as new resources added to core chef. It allows for the usage of these new resources in cookbooks without requiring the very latest Chef client release.
|
||||
|
||||
## Backported functionality
|
||||
|
||||
- [Custom Resources](https://docs.chef.io/custom_resources.html)
|
||||
- [apt_repository](https://docs.chef.io/resource_apt_repository.html)
|
||||
- [apt_update](https://docs.chef.io/resource_apt_update.html)
|
||||
- [systemd_unit](https://docs.chef.io/resource_systemd_unit.html)
|
||||
- [yum_repository](https://docs.chef.io/resource_yum_repository.html)
|
||||
- [:before notifications](https://docs.chef.io/resources.html#timers)
|
||||
|
||||
## Requirements
|
||||
|
||||
### Platforms
|
||||
|
||||
- All platforms supported by Chef
|
||||
|
||||
### Chef
|
||||
|
||||
- Chef 12.1+
|
||||
|
||||
### Cookbooks
|
||||
|
||||
- none
|
||||
|
||||
## Usage
|
||||
|
||||
To use this cookbook, put `depends 'compat_resource'` in the metadata.rb of your cookbook. Once this is done, you can use all the new custom resource features to define resources. It Just Works.
|
||||
|
||||
## Custom Resources?
|
||||
|
||||
Curious about how to use custom resources?
|
||||
|
||||
- Docs: <https://docs.chef.io/custom_resources.html>
|
||||
- Slides: <https://docs.chef.io/decks/custom_resources.html>
|
||||
|
||||
## License & Authors
|
||||
|
||||
- Author:: Lamont Granquist ([lamont@chef.io](mailto:lamont@chef.io))
|
||||
- Author:: John Keiser ([jkeiser@chef.io](mailto:jkeiser@chef.io))
|
||||
|
||||
```text
|
||||
Copyright:: 2015-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.
|
||||
```
|
@ -1,29 +0,0 @@
|
||||
module ChefCompat
|
||||
module CopiedFromChef
|
||||
def self.extend_chef_module(chef_module, target)
|
||||
target.instance_eval do
|
||||
include chef_module
|
||||
@chef_module = chef_module
|
||||
def self.method_missing(name, *args, &block)
|
||||
@chef_module.send(name, *args, &block)
|
||||
end
|
||||
def self.const_missing(name)
|
||||
@chef_module.const_get(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# This patch to CopiedFromChef's ActionClass is necessary for the include to work
|
||||
require 'chef/resource'
|
||||
class Chef < ::Chef
|
||||
class Resource < ::Chef::Resource
|
||||
module ActionClass
|
||||
def self.use_inline_resources
|
||||
end
|
||||
def self.include_resource_dsl(include_resource_dsl)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,47 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/constants'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: John Keiser <jkeiser@chef.io>
|
||||
# Copyright:: Copyright 2015-2016, Chef Software 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.
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
NOT_PASSED = Object.new
|
||||
def NOT_PASSED.to_s
|
||||
"NOT_PASSED"
|
||||
end
|
||||
|
||||
def NOT_PASSED.inspect
|
||||
to_s
|
||||
end
|
||||
NOT_PASSED.freeze
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,40 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/delayed_evaluator'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: John Keiser <jkeiser@chef.io>
|
||||
# Copyright:: Copyright 2015-2016, Chef Software 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.
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class DelayedEvaluator < (defined?(::Chef::DelayedEvaluator) ? ::Chef::DelayedEvaluator : Proc)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,73 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/dsl/core'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#--
|
||||
# Author:: Adam Jacob (<adam@chef.io>)
|
||||
# Author:: Christopher Walters (<cw@chef.io>)
|
||||
# Copyright:: Copyright 2008-2016 Chef Software, 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 "chef_compat/copied_from_chef/chef/dsl/declare_resource"
|
||||
require "chef_compat/copied_from_chef/chef/dsl/universal"
|
||||
require "chef_compat/copied_from_chef/chef/mixin/notifying_block"
|
||||
require "chef_compat/copied_from_chef/chef/mixin/lazy_module_include"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module DSL
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL, self) if defined?(::Chef::DSL)
|
||||
# Part of a family of DSL mixins.
|
||||
#
|
||||
# Chef::DSL::Recipe mixes into Recipes and LWRP Providers.
|
||||
# - this does not target core chef resources and providers.
|
||||
# - this is restricted to recipe/resource/provider context where a resource collection exists.
|
||||
# - cookbook authors should typically include modules into here.
|
||||
#
|
||||
# Chef::DSL::Core mixes into Recipes, LWRP Providers and Core Providers
|
||||
# - this adds cores providers on top of the Recipe DSL.
|
||||
# - this is restricted to recipe/resource/provider context where a resource collection exists.
|
||||
# - core chef authors should typically include modules into here.
|
||||
#
|
||||
# Chef::DSL::Universal mixes into Recipes, LWRP Resources+Providers, Core Resources+Providers, and Attributes files.
|
||||
# - this adds resources and attributes files.
|
||||
# - do not add helpers which manipulate the resource collection.
|
||||
# - this is for general-purpose stuff that is useful nearly everywhere.
|
||||
# - it also pollutes the namespace of nearly every context, watch out.
|
||||
#
|
||||
module Core
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL::Core, self) if defined?(::Chef::DSL::Core)
|
||||
include Chef::DSL::Universal
|
||||
include Chef::DSL::DeclareResource
|
||||
include Chef::Mixin::NotifyingBlock
|
||||
extend Chef::Mixin::LazyModuleInclude
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,315 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/dsl/declare_resource'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#--
|
||||
# Author:: Adam Jacob (<adam@chef.io>)
|
||||
# Author:: Christopher Walters
|
||||
# Copyright:: Copyright 2008-2016 Chef Software, 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.
|
||||
#
|
||||
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module DSL
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL, self) if defined?(::Chef::DSL)
|
||||
module DeclareResource
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL::DeclareResource, self) if defined?(::Chef::DSL::DeclareResource)
|
||||
|
||||
# Helper for switching run_contexts. Allows for using :parent or :root in place of
|
||||
# passing the run_context. Executes the block in the run_context. Returns the return
|
||||
# value of the passed block.
|
||||
#
|
||||
# @param rc [Chef::RunContext,Symbol] Either :root, :parent or a Chef::RunContext
|
||||
#
|
||||
# @return return value of the block
|
||||
#
|
||||
# @example
|
||||
# # creates/returns a 'service[foo]' resource in the root run_context
|
||||
# resource = with_run_context(:root)
|
||||
# edit_resource(:service, "foo") do
|
||||
# action :nothing
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def with_run_context(rc)
|
||||
raise ArgumentError, "with_run_context is useless without a block" unless block_given?
|
||||
old_run_context = @run_context
|
||||
@run_context =
|
||||
case rc
|
||||
when Chef::RunContext
|
||||
rc
|
||||
when :root
|
||||
run_context.root_run_context
|
||||
when :parent
|
||||
run_context.parent_run_context
|
||||
else
|
||||
raise ArgumentError, "bad argument to run_context helper, must be :root, :parent, or a Chef::RunContext"
|
||||
end
|
||||
yield
|
||||
ensure
|
||||
@run_context = old_run_context
|
||||
end
|
||||
|
||||
# Lookup a resource in the resource collection by name and delete it. This
|
||||
# will raise Chef::Exceptions::ResourceNotFound if the resource is not found.
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
#
|
||||
# @return [Chef::Resource] The resource
|
||||
#
|
||||
# @example
|
||||
# delete_resource!(:template, '/x/y.txy')
|
||||
#
|
||||
def delete_resource!(type, name, run_context: self.run_context)
|
||||
run_context.resource_collection.delete("#{type}[#{name}]").tap do |resource|
|
||||
# Purge any pending notifications too. This will not raise an exception
|
||||
# if there are no notifications.
|
||||
if resource
|
||||
run_context.before_notification_collection.delete(resource.declared_key)
|
||||
run_context.immediate_notification_collection.delete(resource.declared_key)
|
||||
run_context.delayed_notification_collection.delete(resource.declared_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Lookup a resource in the resource collection by name and delete it. Returns
|
||||
# nil if the resource is not found and should not fail.
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
#
|
||||
# @return [Chef::Resource] The resource
|
||||
#
|
||||
# @example
|
||||
# delete_resource(:template, '/x/y.txy')
|
||||
#
|
||||
def delete_resource(type, name, run_context: self.run_context)
|
||||
delete_resource!(type, name, run_context: run_context)
|
||||
rescue Chef::Exceptions::ResourceNotFound
|
||||
nil
|
||||
end
|
||||
|
||||
# Lookup a resource in the resource collection by name and edit the resource. If the resource is not
|
||||
# found this will raise Chef::Exceptions::ResourceNotFound. This is the correct API to use for
|
||||
# "chef_rewind" functionality.
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
# @param resource_attrs_block A block that lets you set attributes of the
|
||||
# resource (it is instance_eval'd on the resource instance).
|
||||
#
|
||||
# @return [Chef::Resource] The updated resource
|
||||
#
|
||||
# @example
|
||||
# edit_resource!(:template, '/x/y.txy') do
|
||||
# cookbook_name: cookbook_name
|
||||
# end
|
||||
#
|
||||
def edit_resource!(type, name, created_at = nil, run_context: self.run_context, &resource_attrs_block)
|
||||
resource = find_resource!(type, name, run_context: run_context)
|
||||
if resource_attrs_block
|
||||
if defined?(new_resource)
|
||||
resource.instance_exec(new_resource, &resource_attrs_block)
|
||||
else
|
||||
resource.instance_exec(&resource_attrs_block)
|
||||
end
|
||||
end
|
||||
resource
|
||||
end
|
||||
|
||||
# Lookup a resource in the resource collection by name. If it exists,
|
||||
# return it. If it does not exist, create it. This is a useful function
|
||||
# for accumulator patterns. In CRUD terminology this is an "upsert" operation and is
|
||||
# used to assert that the resource must exist with the specified properties.
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param created_at [String] The caller of the resource. Use `caller[0]`
|
||||
# to get the caller of your function. Defaults to the caller of this
|
||||
# function.
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
# @param resource_attrs_block A block that lets you set attributes of the
|
||||
# resource (it is instance_eval'd on the resource instance).
|
||||
#
|
||||
# @return [Chef::Resource] The updated or created resource
|
||||
#
|
||||
# @example
|
||||
# resource = edit_resource(:template, '/x/y.txy') do
|
||||
# source "y.txy.erb"
|
||||
# variables {}
|
||||
# end
|
||||
# resource.variables.merge!({ home: "/home/klowns" })
|
||||
#
|
||||
def edit_resource(type, name, created_at = nil, run_context: self.run_context, &resource_attrs_block)
|
||||
edit_resource!(type, name, created_at, run_context: run_context, &resource_attrs_block)
|
||||
rescue Chef::Exceptions::ResourceNotFound
|
||||
declare_resource(type, name, created_at, run_context: run_context, &resource_attrs_block)
|
||||
end
|
||||
|
||||
# Lookup a resource in the resource collection by name. If the resource is not
|
||||
# found this will raise Chef::Exceptions::ResourceNotFound. This API is identical to the
|
||||
# resources() call and while it is a synonym it is not intended to deprecate that call.
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
#
|
||||
# @return [Chef::Resource] The updated resource
|
||||
#
|
||||
# @example
|
||||
# resource = find_resource!(:template, '/x/y.txy')
|
||||
#
|
||||
def find_resource!(type, name, run_context: self.run_context)
|
||||
raise ArgumentError, "find_resource! does not take a block" if block_given?
|
||||
run_context.resource_collection.find(type => name)
|
||||
end
|
||||
|
||||
# Lookup a resource in the resource collection by name. If the resource is not found
|
||||
# the will be no exception raised and the call will return nil. If a block is given and
|
||||
# no resource is found it will create the resource using the block, if the resource is
|
||||
# found then the block will not be applied. The block version is similar to create_if_missing
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
#
|
||||
# @return [Chef::Resource] The updated resource
|
||||
#
|
||||
# @example
|
||||
# if ( find_resource(:template, '/x/y.txy') )
|
||||
# # do something
|
||||
# else
|
||||
# # don't worry about the error
|
||||
# end
|
||||
#
|
||||
# @example
|
||||
# # this API can be used to return a resource from an outer run context, and will only create
|
||||
# # an action :nothing service if one does not already exist.
|
||||
# resource = with_run_context(:root) do
|
||||
# find_resource(:service, 'whatever') do
|
||||
# action :nothing
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def find_resource(type, name, created_at: nil, run_context: self.run_context, &resource_attrs_block)
|
||||
find_resource!(type, name, run_context: run_context)
|
||||
rescue Chef::Exceptions::ResourceNotFound
|
||||
if resource_attrs_block
|
||||
declare_resource(type, name, created_at, run_context: run_context, &resource_attrs_block)
|
||||
end # returns nil otherwise
|
||||
end
|
||||
|
||||
# Instantiates a resource (via #build_resource), then adds it to the
|
||||
# resource collection. Note that resource classes are looked up directly,
|
||||
# so this will create the resource you intended even if the method name
|
||||
# corresponding to that resource has been overridden.
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param created_at [String] The caller of the resource. Use `caller[0]`
|
||||
# to get the caller of your function. Defaults to the caller of this
|
||||
# function.
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
# @param resource_attrs_block A block that lets you set attributes of the
|
||||
# resource (it is instance_eval'd on the resource instance).
|
||||
#
|
||||
# @return [Chef::Resource] The new resource.
|
||||
#
|
||||
# @example
|
||||
# declare_resource(:file, '/x/y.txy', caller[0]) do
|
||||
# action :delete
|
||||
# end
|
||||
# # Equivalent to
|
||||
# file '/x/y.txt' do
|
||||
# action :delete
|
||||
# end
|
||||
#
|
||||
def declare_resource(type, name, created_at = nil, run_context: self.run_context, create_if_missing: false, &resource_attrs_block)
|
||||
created_at ||= caller[0]
|
||||
|
||||
if create_if_missing
|
||||
Chef::Log.deprecation "build_resource with a create_if_missing flag is deprecated, use edit_resource instead"
|
||||
# midly goofy since we call edit_resource only to re-call ourselves, but that's why its deprecated...
|
||||
return edit_resource(type, name, created_at, run_context: run_context, &resource_attrs_block)
|
||||
end
|
||||
|
||||
resource = build_resource(type, name, created_at, &resource_attrs_block)
|
||||
|
||||
run_context.resource_collection.insert(resource, resource_type: type, instance_name: name)
|
||||
resource
|
||||
end
|
||||
|
||||
# Instantiate a resource of the given +type+ with the given +name+ and
|
||||
# attributes as given in the +resource_attrs_block+.
|
||||
#
|
||||
# The resource is NOT added to the resource collection.
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param created_at [String] The caller of the resource. Use `caller[0]`
|
||||
# to get the caller of your function. Defaults to the caller of this
|
||||
# function.
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
# @param resource_attrs_block A block that lets you set attributes of the
|
||||
# resource (it is instance_eval'd on the resource instance).
|
||||
#
|
||||
# @return [Chef::Resource] The new resource.
|
||||
#
|
||||
# @example
|
||||
# build_resource(:file, '/x/y.txy', caller[0]) do
|
||||
# action :delete
|
||||
# end
|
||||
#
|
||||
def build_resource(type, name, created_at = nil, run_context: self.run_context, &resource_attrs_block)
|
||||
created_at ||= caller[0]
|
||||
|
||||
# this needs to be lazy in order to avoid circular dependencies since ResourceBuilder
|
||||
# will requires the entire provider+resolver universe
|
||||
require "chef_compat/copied_from_chef/chef/resource_builder" unless defined?(Chef::ResourceBuilder)
|
||||
|
||||
Chef::ResourceBuilder.new(
|
||||
type: type,
|
||||
name: name,
|
||||
created_at: created_at,
|
||||
params: @params,
|
||||
run_context: run_context,
|
||||
cookbook_name: cookbook_name,
|
||||
recipe_name: recipe_name,
|
||||
enclosing_provider: self.is_a?(Chef::Provider) ? self : nil
|
||||
).build(&resource_attrs_block)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,292 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/dsl/platform_introspection'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Adam Jacob (<adam@chef.io>)
|
||||
# Copyright:: Copyright 2008-2016, Chef Software 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.
|
||||
#
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module DSL
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL, self) if defined?(::Chef::DSL)
|
||||
|
||||
# == Chef::DSL::PlatformIntrospection
|
||||
# Provides the DSL for platform-dependent switch logic, such as
|
||||
# #value_for_platform.
|
||||
module PlatformIntrospection
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL::PlatformIntrospection, self) if defined?(::Chef::DSL::PlatformIntrospection)
|
||||
|
||||
# Implementation class for determining platform dependent values
|
||||
class PlatformDependentValue < (defined?(::Chef::DSL::PlatformIntrospection::PlatformDependentValue) ? ::Chef::DSL::PlatformIntrospection::PlatformDependentValue : Object)
|
||||
|
||||
# Create a platform dependent value object.
|
||||
# === Arguments
|
||||
# platform_hash (Hash) a hash of the same structure as Chef::Platform,
|
||||
# like this:
|
||||
# {
|
||||
# :debian => {:default => 'the value for all debian'}
|
||||
# [:centos, :redhat, :fedora] => {:default => "value for all EL variants"}
|
||||
# :ubuntu => { :default => "default for ubuntu", '10.04' => "value for 10.04 only"},
|
||||
# :default => "the default when nothing else matches"
|
||||
# }
|
||||
# * platforms can be specified as Symbols or Strings
|
||||
# * multiple platforms can be grouped by using an Array as the key
|
||||
# * values for platforms need to be Hashes of the form:
|
||||
# {platform_version => value_for_that_version}
|
||||
# * the exception to the above is the default value, which is given as
|
||||
# :default => default_value
|
||||
def initialize(platform_hash)
|
||||
super if defined?(::Chef::DSL::PlatformIntrospection::PlatformDependentValue)
|
||||
@values = {}
|
||||
platform_hash.each { |platforms, value| set(platforms, value) }
|
||||
end
|
||||
|
||||
def value_for_node(node)
|
||||
platform, version = node[:platform].to_s, node[:platform_version].to_s
|
||||
# Check if we match a version constraint via Chef::VersionConstraint::Platform and Chef::Version::Platform
|
||||
matched_value = match_versions(node)
|
||||
if @values.key?(platform) && @values[platform].key?(version)
|
||||
@values[platform][version]
|
||||
elsif matched_value
|
||||
matched_value
|
||||
elsif @values.key?(platform) && @values[platform].key?("default")
|
||||
@values[platform]["default"]
|
||||
elsif @values.key?("default")
|
||||
@values["default"]
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def match_versions(node)
|
||||
begin
|
||||
platform, version = node[:platform].to_s, node[:platform_version].to_s
|
||||
return nil unless @values.key?(platform)
|
||||
node_version = Chef::Version::Platform.new(version)
|
||||
key_matches = []
|
||||
keys = @values[platform].keys
|
||||
keys.each do |k|
|
||||
begin
|
||||
if Chef::VersionConstraint::Platform.new(k).include?(node_version)
|
||||
key_matches << k
|
||||
end
|
||||
rescue Chef::Exceptions::InvalidVersionConstraint => e
|
||||
Chef::Log.debug "Caught InvalidVersionConstraint. This means that a key in value_for_platform cannot be interpreted as a Chef::VersionConstraint::Platform."
|
||||
Chef::Log.debug(e)
|
||||
end
|
||||
end
|
||||
return @values[platform][version] if key_matches.include?(version)
|
||||
case key_matches.length
|
||||
when 0
|
||||
return nil
|
||||
when 1
|
||||
return @values[platform][key_matches.first]
|
||||
else
|
||||
raise "Multiple matches detected for #{platform} with values #{@values}. The matches are: #{key_matches}"
|
||||
end
|
||||
rescue Chef::Exceptions::InvalidCookbookVersion => e
|
||||
# Lets not break because someone passes a weird string like 'default' :)
|
||||
Chef::Log.debug(e)
|
||||
Chef::Log.debug "InvalidCookbookVersion exceptions are common and expected here: the generic constraint matcher attempted to match something which is not a constraint. Moving on to next version or constraint"
|
||||
return nil
|
||||
rescue Chef::Exceptions::InvalidPlatformVersion => e
|
||||
Chef::Log.debug "Caught InvalidPlatformVersion, this means that Chef::Version::Platform does not know how to turn #{node_version} into an x.y.z format"
|
||||
Chef::Log.debug(e)
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def set(platforms, value)
|
||||
if platforms.to_s == "default"
|
||||
@values["default"] = value
|
||||
else
|
||||
assert_valid_platform_values!(platforms, value)
|
||||
Array(platforms).each { |platform| @values[platform.to_s] = normalize_keys(value) }
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
def normalize_keys(hash)
|
||||
hash.inject({}) do |h, key_value|
|
||||
keys, value = *key_value
|
||||
Array(keys).each do |key|
|
||||
h[key.to_s] = value
|
||||
end
|
||||
h
|
||||
end
|
||||
end
|
||||
|
||||
def assert_valid_platform_values!(platforms, value)
|
||||
unless value.kind_of?(Hash)
|
||||
msg = "platform dependent values must be specified in the format :platform => {:version => value} "
|
||||
msg << "you gave a value #{value.inspect} for platform(s) #{platforms}"
|
||||
raise ArgumentError, msg
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Given a hash similar to the one we use for Platforms, select a value from the hash. Supports
|
||||
# per platform defaults, along with a single base default. Arrays may be passed as hash keys and
|
||||
# will be expanded.
|
||||
#
|
||||
# === Parameters
|
||||
# platform_hash:: A platform-style hash.
|
||||
#
|
||||
# === Returns
|
||||
# value:: Whatever the most specific value of the hash is.
|
||||
def value_for_platform(platform_hash)
|
||||
PlatformDependentValue.new(platform_hash).value_for_node(node)
|
||||
end
|
||||
|
||||
# Given a list of platforms, returns true if the current recipe is being run on a node with
|
||||
# that platform, false otherwise.
|
||||
#
|
||||
# === Parameters
|
||||
# args:: A list of platforms. Each platform can be in string or symbol format.
|
||||
#
|
||||
# === Returns
|
||||
# true:: If the current platform is in the list
|
||||
# false:: If the current platform is not in the list
|
||||
def platform?(*args)
|
||||
has_platform = false
|
||||
|
||||
args.flatten.each do |platform|
|
||||
has_platform = true if platform.to_s == node[:platform]
|
||||
end
|
||||
|
||||
has_platform
|
||||
end
|
||||
|
||||
# Implementation class for determining platform family dependent values
|
||||
class PlatformFamilyDependentValue < (defined?(::Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue) ? ::Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue : Object)
|
||||
|
||||
# Create a platform family dependent value object.
|
||||
# === Arguments
|
||||
# platform_family_hash (Hash) a map of platform families to values.
|
||||
# like this:
|
||||
# {
|
||||
# :rhel => "value for all EL variants"
|
||||
# :fedora => "value for fedora variants fedora and amazon" ,
|
||||
# [:fedora, :rhel] => "value for all known redhat variants"
|
||||
# :debian => "value for debian variants including debian, ubuntu, mint" ,
|
||||
# :default => "the default when nothing else matches"
|
||||
# }
|
||||
# * platform families can be specified as Symbols or Strings
|
||||
# * multiple platform families can be grouped by using an Array as the key
|
||||
# * values for platform families can be any object, with no restrictions. Some examples:
|
||||
# - [:stop, :start]
|
||||
# - "mysql-devel"
|
||||
# - { :key => "value" }
|
||||
def initialize(platform_family_hash)
|
||||
super if defined?(::Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue)
|
||||
@values = {}
|
||||
@values["default"] = nil
|
||||
platform_family_hash.each { |platform_families, value| set(platform_families, value) }
|
||||
end
|
||||
|
||||
def value_for_node(node)
|
||||
if node.key?(:platform_family)
|
||||
platform_family = node[:platform_family].to_s
|
||||
if @values.key?(platform_family)
|
||||
@values[platform_family]
|
||||
else
|
||||
@values["default"]
|
||||
end
|
||||
else
|
||||
@values["default"]
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set(platform_family, value)
|
||||
if platform_family.to_s == "default"
|
||||
@values["default"] = value
|
||||
else
|
||||
Array(platform_family).each { |family| @values[family.to_s] = value }
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Given a hash mapping platform families to values, select a value from the hash. Supports a single
|
||||
# base default if platform family is not in the map. Arrays may be passed as hash keys and will be
|
||||
# expanded
|
||||
#
|
||||
# === Parameters
|
||||
# platform_family_hash:: A hash in the form { platform_family_name => value }
|
||||
#
|
||||
# === Returns
|
||||
# value:: Whatever the most specific value of the hash is.
|
||||
def value_for_platform_family(platform_family_hash)
|
||||
PlatformFamilyDependentValue.new(platform_family_hash).value_for_node(node)
|
||||
end
|
||||
|
||||
# Given a list of platform families, returns true if the current recipe is being run on a
|
||||
# node within that platform family, false otherwise.
|
||||
#
|
||||
# === Parameters
|
||||
# args:: A list of platform families. Each platform family can be in string or symbol format.
|
||||
#
|
||||
# === Returns
|
||||
# true:: if the current node platform family is in the list.
|
||||
# false:: if the current node platform family is not in the list.
|
||||
def platform_family?(*args)
|
||||
args.flatten.any? do |platform_family|
|
||||
platform_family.to_s == node[:platform_family]
|
||||
end
|
||||
end
|
||||
|
||||
# Shamelessly stolen from https://github.com/sethvargo/chef-sugar/blob/master/lib/chef/sugar/docker.rb
|
||||
# Given a node object, returns whether the node is a docker container.
|
||||
#
|
||||
# === Parameters
|
||||
# node:: [Chef::Node] The node to check.
|
||||
#
|
||||
# === Returns
|
||||
# true:: if the current node is a docker container
|
||||
# false:: if the current node is not a docker container
|
||||
def docker?(node = run_context.nil? ? nil : run_context.node)
|
||||
# Using "File.exist?('/.dockerinit') || File.exist?('/.dockerenv')" makes Travis sad,
|
||||
# and that makes us sad too.
|
||||
node && node[:virtualization] && node[:virtualization][:systems] &&
|
||||
node[:virtualization][:systems][:docker] && node[:virtualization][:systems][:docker] == "guest"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# **DEPRECATED**
|
||||
# This used to be part of chef/mixin/language. Load the file to activate the deprecation code.
|
||||
end
|
||||
end
|
||||
end
|
@ -1,37 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/dsl/recipe'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
require "chef_compat/copied_from_chef/chef/dsl/core"
|
||||
require "chef_compat/copied_from_chef/chef/mixin/lazy_module_include"
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module DSL
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL, self) if defined?(::Chef::DSL)
|
||||
module Recipe
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL::Recipe, self) if defined?(::Chef::DSL::Recipe)
|
||||
include Chef::DSL::Core
|
||||
extend Chef::Mixin::LazyModuleInclude
|
||||
module FullDSL
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL::Recipe::FullDSL, self) if defined?(::Chef::DSL::Recipe::FullDSL)
|
||||
include Chef::DSL::Recipe
|
||||
extend Chef::Mixin::LazyModuleInclude
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
require "chef_compat/copied_from_chef/chef/resource"
|
||||
end
|
||||
end
|
||||
end
|
@ -1,70 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/dsl/universal'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#--
|
||||
# Author:: Adam Jacob (<adam@chef.io>)
|
||||
# Author:: Christopher Walters (<cw@chef.io>)
|
||||
# Copyright:: Copyright 2008-2016 Chef Software, 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 "chef_compat/copied_from_chef/chef/dsl/platform_introspection"
|
||||
require "chef_compat/copied_from_chef/chef/mixin/powershell_out"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module DSL
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL, self) if defined?(::Chef::DSL)
|
||||
# Part of a family of DSL mixins.
|
||||
#
|
||||
# Chef::DSL::Recipe mixes into Recipes and LWRP Providers.
|
||||
# - this does not target core chef resources and providers.
|
||||
# - this is restricted to recipe/resource/provider context where a resource collection exists.
|
||||
# - cookbook authors should typically include modules into here.
|
||||
#
|
||||
# Chef::DSL::Core mixes into Recipes, LWRP Providers and Core Providers
|
||||
# - this adds cores providers on top of the Recipe DSL.
|
||||
# - this is restricted to recipe/resource/provider context where a resource collection exists.
|
||||
# - core chef authors should typically include modules into here.
|
||||
#
|
||||
# Chef::DSL::Universal mixes into Recipes, LWRP Resources+Providers, Core Resources+Providers, and Attributes files.
|
||||
# - this adds resources and attributes files.
|
||||
# - do not add helpers which manipulate the resource collection.
|
||||
# - this is for general-purpose stuff that is useful nearly everywhere.
|
||||
# - it also pollutes the namespace of nearly every context, watch out.
|
||||
#
|
||||
module Universal
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL::Universal, self) if defined?(::Chef::DSL::Universal)
|
||||
include Chef::DSL::PlatformIntrospection
|
||||
include Chef::Mixin::PowershellOut
|
||||
include Chef::Mixin::ShellOut
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,98 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/mixin/lazy_module_include'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Copyright:: Copyright 2011-2016, Chef Software 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.
|
||||
#
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module Mixin
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin, self) if defined?(::Chef::Mixin)
|
||||
# If you have:
|
||||
#
|
||||
# module A
|
||||
# extend LazyModuleInclude
|
||||
# end
|
||||
#
|
||||
# module B
|
||||
# include A
|
||||
# end
|
||||
#
|
||||
# module C
|
||||
# include B
|
||||
# end
|
||||
#
|
||||
# module Monkeypatches
|
||||
# def monkey
|
||||
# puts "monkey!"
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# A.send(:include, Monkeypatches)
|
||||
#
|
||||
# Then B and C and any classes that they're included in will also get the #monkey method patched into them.
|
||||
#
|
||||
module LazyModuleInclude
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin::LazyModuleInclude, self) if defined?(::Chef::Mixin::LazyModuleInclude)
|
||||
|
||||
# Most of the magick is in this hook which creates a closure over the parent class and then builds an
|
||||
# "infector" module which infects all descendants and which is responsible for updating the list of
|
||||
# descendants in the parent class.
|
||||
def included(klass)
|
||||
super
|
||||
parent_klass = self
|
||||
infector = Module.new do
|
||||
define_method(:included) do |subklass|
|
||||
super(subklass)
|
||||
subklass.extend(infector)
|
||||
parent_klass.descendants.push(subklass)
|
||||
end
|
||||
end
|
||||
klass.extend(infector)
|
||||
parent_klass.descendants.push(klass)
|
||||
end
|
||||
|
||||
def descendants
|
||||
@descendants ||= []
|
||||
end
|
||||
|
||||
def include(*classes)
|
||||
super
|
||||
classes.each do |klass|
|
||||
descendants.each do |descendant|
|
||||
descendant.send(:include, klass)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,74 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/mixin/notifying_block'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#--
|
||||
# Author:: Lamont Granquist <lamont@chef.io>
|
||||
# Copyright:: Copyright 2010-2016, Chef Software 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.
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module Mixin
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin, self) if defined?(::Chef::Mixin)
|
||||
module NotifyingBlock
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin::NotifyingBlock, self) if defined?(::Chef::Mixin::NotifyingBlock)
|
||||
|
||||
def notifying_block(&block)
|
||||
begin
|
||||
subcontext = subcontext_block(&block)
|
||||
Chef::Runner.new(subcontext).converge
|
||||
ensure
|
||||
# recipes don't have a new_resource
|
||||
if respond_to?(:new_resource)
|
||||
if subcontext && subcontext.resource_collection.any?(&:updated?)
|
||||
new_resource.updated_by_last_action(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def subcontext_block(parent_context = nil, &block)
|
||||
parent_context ||= @run_context
|
||||
sub_run_context = parent_context.create_child
|
||||
|
||||
begin
|
||||
outer_run_context = @run_context
|
||||
@run_context = sub_run_context
|
||||
instance_eval(&block)
|
||||
ensure
|
||||
@run_context = outer_run_context
|
||||
end
|
||||
|
||||
sub_run_context
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,510 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/mixin/params_validate'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Adam Jacob (<adam@chef.io>)
|
||||
# Copyright:: Copyright 2008-2016, Chef Software 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 "chef_compat/copied_from_chef/chef/constants"
|
||||
require "chef_compat/copied_from_chef/chef/property"
|
||||
require "chef_compat/copied_from_chef/chef/delayed_evaluator"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module Mixin
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin, self) if defined?(::Chef::Mixin)
|
||||
module ParamsValidate
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin::ParamsValidate, self) if defined?(::Chef::Mixin::ParamsValidate)
|
||||
# Takes a hash of options, along with a map to validate them. Returns the original
|
||||
# options hash, plus any changes that might have been made (through things like setting
|
||||
# default values in the validation map)
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
# validate({ :one => "neat" }, { :one => { :kind_of => String }})
|
||||
#
|
||||
# Would raise an exception if the value of :one above is not a kind_of? string. Valid
|
||||
# map options are:
|
||||
#
|
||||
# @param opts [Hash<Symbol,Object>] Validation opts.
|
||||
# @option opts [Object,Array] :is An object, or list of
|
||||
# objects, that must match the value using Ruby's `===` operator
|
||||
# (`opts[:is].any? { |v| v === value }`). (See #_pv_is.)
|
||||
# @option opts [Object,Array] :equal_to An object, or list
|
||||
# of objects, that must be equal to the value using Ruby's `==`
|
||||
# operator (`opts[:is].any? { |v| v == value }`) (See #_pv_equal_to.)
|
||||
# @option opts [Regexp,Array<Regexp>] :regex An object, or
|
||||
# list of objects, that must match the value with `regex.match(value)`.
|
||||
# (See #_pv_regex)
|
||||
# @option opts [Class,Array<Class>] :kind_of A class, or
|
||||
# list of classes, that the value must be an instance of. (See
|
||||
# #_pv_kind_of.)
|
||||
# @option opts [Hash<String,Proc>] :callbacks A hash of
|
||||
# messages -> procs, all of which match the value. The proc must
|
||||
# return a truthy or falsey value (true means it matches). (See
|
||||
# #_pv_callbacks.)
|
||||
# @option opts [Symbol,Array<Symbol>] :respond_to A method
|
||||
# name, or list of method names, the value must respond to. (See
|
||||
# #_pv_respond_to.)
|
||||
# @option opts [Symbol,Array<Symbol>] :cannot_be A property,
|
||||
# or a list of properties, that the value cannot have (such as `:nil` or
|
||||
# `:empty`). The method with a questionmark at the end is called on the
|
||||
# value (e.g. `value.empty?`). If the value does not have this method,
|
||||
# it is considered valid (i.e. if you don't respond to `empty?` we
|
||||
# assume you are not empty). (See #_pv_cannot_be.)
|
||||
# @option opts [Proc] :coerce A proc which will be called to
|
||||
# transform the user input to canonical form. The value is passed in,
|
||||
# and the transformed value returned as output. Lazy values will *not*
|
||||
# be passed to this method until after they are evaluated. Called in the
|
||||
# context of the resource (meaning you can access other properties).
|
||||
# (See #_pv_coerce.) (See #_pv_coerce.)
|
||||
# @option opts [Boolean] :required `true` if this property
|
||||
# must be present and not `nil`; `false` otherwise. This is checked
|
||||
# after the resource is fully initialized. (See #_pv_required.)
|
||||
# @option opts [Boolean] :name_property `true` if this
|
||||
# property defaults to the same value as `name`. Equivalent to
|
||||
# `default: lazy { name }`, except that #property_is_set? will
|
||||
# return `true` if the property is set *or* if `name` is set. (See
|
||||
# #_pv_name_property.)
|
||||
# @option opts [Boolean] :name_attribute Same as `name_property`.
|
||||
# @option opts [Object] :default The value this property
|
||||
# will return if the user does not set one. If this is `lazy`, it will
|
||||
# be run in the context of the instance (and able to access other
|
||||
# properties). (See #_pv_default.)
|
||||
#
|
||||
def validate(opts, map)
|
||||
map = map.validation_options if map.is_a?(Property)
|
||||
|
||||
#--
|
||||
# validate works by taking the keys in the validation map, assuming it's a hash, and
|
||||
# looking for _pv_:symbol as methods. Assuming it find them, it calls the right
|
||||
# one.
|
||||
#++
|
||||
raise ArgumentError, "Options must be a hash" unless opts.kind_of?(Hash)
|
||||
raise ArgumentError, "Validation Map must be a hash" unless map.kind_of?(Hash)
|
||||
|
||||
map.each do |key, validation|
|
||||
unless key.kind_of?(Symbol) || key.kind_of?(String)
|
||||
raise ArgumentError, "Validation map keys must be symbols or strings!"
|
||||
end
|
||||
case validation
|
||||
when true
|
||||
_pv_required(opts, key)
|
||||
when false
|
||||
true
|
||||
when Hash
|
||||
validation.each do |check, carg|
|
||||
check_method = "_pv_#{check}"
|
||||
if self.respond_to?(check_method, true)
|
||||
self.send(check_method, opts, key, carg)
|
||||
else
|
||||
raise ArgumentError, "Validation map has unknown check: #{check}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
opts
|
||||
end
|
||||
|
||||
def lazy(&block)
|
||||
DelayedEvaluator.new(&block)
|
||||
end
|
||||
|
||||
def set_or_return(symbol, value, validation)
|
||||
property = SetOrReturnProperty.new(name: symbol, **validation)
|
||||
property.call(self, value)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def explicitly_allows_nil?(key, validation)
|
||||
validation.has_key?(:is) && _pv_is({ key => nil }, key, validation[:is], raise_error: false)
|
||||
end
|
||||
|
||||
# Return the value of a parameter, or nil if it doesn't exist.
|
||||
def _pv_opts_lookup(opts, key)
|
||||
if opts.has_key?(key.to_s)
|
||||
opts[key.to_s]
|
||||
elsif opts.has_key?(key.to_sym)
|
||||
opts[key.to_sym]
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
# Raise an exception if the parameter is not found.
|
||||
def _pv_required(opts, key, is_required = true, explicitly_allows_nil = false)
|
||||
if is_required
|
||||
return true if opts.has_key?(key.to_s) && (explicitly_allows_nil || !opts[key.to_s].nil?)
|
||||
return true if opts.has_key?(key.to_sym) && (explicitly_allows_nil || !opts[key.to_sym].nil?)
|
||||
raise Exceptions::ValidationFailed, "Required argument #{key.inspect} is missing!"
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
#
|
||||
# List of things values must be equal to.
|
||||
#
|
||||
# Uses Ruby's `==` to evaluate (equal_to == value). At least one must
|
||||
# match for the value to be valid.
|
||||
#
|
||||
# `nil` passes this validation automatically.
|
||||
#
|
||||
# @return [Array,nil] List of things values must be equal to, or nil if
|
||||
# equal_to is unspecified.
|
||||
#
|
||||
def _pv_equal_to(opts, key, to_be)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
unless value.nil?
|
||||
to_be = Array(to_be)
|
||||
to_be.each do |tb|
|
||||
return true if value == tb
|
||||
end
|
||||
raise Exceptions::ValidationFailed, "Option #{key} must be equal to one of: #{to_be.join(", ")}! You passed #{value.inspect}."
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# List of things values must be instances of.
|
||||
#
|
||||
# Uses value.kind_of?(kind_of) to evaluate. At least one must match for
|
||||
# the value to be valid.
|
||||
#
|
||||
# `nil` automatically passes this validation.
|
||||
#
|
||||
def _pv_kind_of(opts, key, to_be)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
unless value.nil?
|
||||
to_be = Array(to_be)
|
||||
to_be.each do |tb|
|
||||
return true if value.kind_of?(tb)
|
||||
end
|
||||
raise Exceptions::ValidationFailed, "Option #{key} must be a kind of #{to_be}! You passed #{value.inspect}."
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# List of method names values must respond to.
|
||||
#
|
||||
# Uses value.respond_to?(respond_to) to evaluate. At least one must match
|
||||
# for the value to be valid.
|
||||
#
|
||||
def _pv_respond_to(opts, key, method_name_list)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
unless value.nil?
|
||||
Array(method_name_list).each do |method_name|
|
||||
unless value.respond_to?(method_name)
|
||||
raise Exceptions::ValidationFailed, "Option #{key} must have a #{method_name} method!"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# List of things that must not be true about the value.
|
||||
#
|
||||
# Calls `value.<thing>?` All responses must be false for the value to be
|
||||
# valid.
|
||||
# Values which do not respond to <thing>? are considered valid (because if
|
||||
# a value doesn't respond to `:readable?`, then it probably isn't
|
||||
# readable.)
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x, cannot_be: [ :nil, :empty ]
|
||||
# x [ 1, 2 ] #=> valid
|
||||
# x 1 #=> valid
|
||||
# x [] #=> invalid
|
||||
# x nil #=> invalid
|
||||
# ```
|
||||
#
|
||||
def _pv_cannot_be(opts, key, predicate_method_base_name)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
if !value.nil?
|
||||
Array(predicate_method_base_name).each do |method_name|
|
||||
predicate_method = :"#{method_name}?"
|
||||
|
||||
if value.respond_to?(predicate_method)
|
||||
if value.send(predicate_method)
|
||||
raise Exceptions::ValidationFailed, "Option #{key} cannot be #{predicate_method_base_name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# The default value for a property.
|
||||
#
|
||||
# When the property is not assigned, this will be used.
|
||||
#
|
||||
# If this is a lazy value, it will either be passed the resource as a value,
|
||||
# or if the lazy proc does not take parameters, it will be run in the
|
||||
# context of the instance with instance_eval.
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x, default: 10
|
||||
# ```
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x
|
||||
# property :y, default: lazy { x+2 }
|
||||
# ```
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x
|
||||
# property :y, default: lazy { |r| r.x+2 }
|
||||
# ```
|
||||
#
|
||||
def _pv_default(opts, key, default_value)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
if value.nil?
|
||||
default_value = default_value.freeze if !default_value.is_a?(DelayedEvaluator)
|
||||
opts[key] = default_value
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# List of regexes values that must match.
|
||||
#
|
||||
# Uses regex.match() to evaluate. At least one must match for the value to
|
||||
# be valid.
|
||||
#
|
||||
# `nil` passes regex validation automatically.
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x, regex: [ /abc/, /xyz/ ]
|
||||
# ```
|
||||
#
|
||||
def _pv_regex(opts, key, regex)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
if !value.nil?
|
||||
Array(regex).flatten.each do |r|
|
||||
return true if r.match(value.to_s)
|
||||
end
|
||||
raise Exceptions::ValidationFailed, "Option #{key}'s value #{value} does not match regular expression #{regex.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# List of procs we pass the value to.
|
||||
#
|
||||
# All procs must return true for the value to be valid. If any procs do
|
||||
# not return true, the key will be used for the message: `"Property x's
|
||||
# value :y <message>"`.
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x, callbacks: { "is bigger than 10" => proc { |v| v <= 10 }, "is not awesome" => proc { |v| !v.awesome }}
|
||||
# ```
|
||||
#
|
||||
def _pv_callbacks(opts, key, callbacks)
|
||||
raise ArgumentError, "Callback list must be a hash!" unless callbacks.kind_of?(Hash)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
if !value.nil?
|
||||
callbacks.each do |message, zeproc|
|
||||
unless zeproc.call(value)
|
||||
raise Exceptions::ValidationFailed, "Option #{key}'s value #{value} #{message}!"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Allows a parameter to default to the value of the resource name.
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x, name_property: true
|
||||
# ```
|
||||
#
|
||||
def _pv_name_property(opts, key, is_name_property = true)
|
||||
if is_name_property
|
||||
if opts[key].nil?
|
||||
raise CannotValidateStaticallyError, "name_property cannot be evaluated without a resource." if self == Chef::Mixin::ParamsValidate
|
||||
opts[key] = self.instance_variable_get(:"@name")
|
||||
end
|
||||
end
|
||||
end
|
||||
alias :_pv_name_attribute :_pv_name_property
|
||||
|
||||
#
|
||||
# List of valid things values can be.
|
||||
#
|
||||
# Uses Ruby's `===` to evaluate (is === value). At least one must match
|
||||
# for the value to be valid.
|
||||
#
|
||||
# If a proc is passed, it is instance_eval'd in the resource, passed the
|
||||
# value, and must return a truthy or falsey value.
|
||||
#
|
||||
# @example Class
|
||||
# ```ruby
|
||||
# property :x, String
|
||||
# x 'valid' #=> valid
|
||||
# x 1 #=> invalid
|
||||
# x nil #=> invalid
|
||||
#
|
||||
# @example Value
|
||||
# ```ruby
|
||||
# property :x, [ :a, :b, :c, nil ]
|
||||
# x :a #=> valid
|
||||
# x nil #=> valid
|
||||
# ```
|
||||
#
|
||||
# @example Regex
|
||||
# ```ruby
|
||||
# property :x, /bar/
|
||||
# x 'foobar' #=> valid
|
||||
# x 'foo' #=> invalid
|
||||
# x nil #=> invalid
|
||||
# ```
|
||||
#
|
||||
# @example Proc
|
||||
# ```ruby
|
||||
# property :x, proc { |x| x > y }
|
||||
# property :y, default: 2
|
||||
# x 3 #=> valid
|
||||
# x 1 #=> invalid
|
||||
# ```
|
||||
#
|
||||
# @example Property
|
||||
# ```ruby
|
||||
# type = Property.new(is: String)
|
||||
# property :x, type
|
||||
# x 'foo' #=> valid
|
||||
# x 1 #=> invalid
|
||||
# x nil #=> invalid
|
||||
# ```
|
||||
#
|
||||
# @example RSpec Matcher
|
||||
# ```ruby
|
||||
# include RSpec::Matchers
|
||||
# property :x, a_string_matching /bar/
|
||||
# x 'foobar' #=> valid
|
||||
# x 'foo' #=> invalid
|
||||
# x nil #=> invalid
|
||||
# ```
|
||||
#
|
||||
def _pv_is(opts, key, to_be, raise_error: true)
|
||||
return true if !opts.has_key?(key.to_s) && !opts.has_key?(key.to_sym)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
to_be = [ to_be ].flatten(1)
|
||||
errors = []
|
||||
passed = to_be.any? do |tb|
|
||||
case tb
|
||||
when Proc
|
||||
raise CannotValidateStaticallyError, "is: proc { } must be evaluated once for each resource" if self == Chef::Mixin::ParamsValidate
|
||||
instance_exec(value, &tb)
|
||||
when Property
|
||||
begin
|
||||
validate(opts, { key => tb.validation_options })
|
||||
true
|
||||
rescue Exceptions::ValidationFailed
|
||||
# re-raise immediately if there is only one "is" so we get a better stack
|
||||
raise if to_be.size == 1
|
||||
errors << $!
|
||||
false
|
||||
end
|
||||
else
|
||||
tb === value
|
||||
end
|
||||
end
|
||||
if passed
|
||||
true
|
||||
else
|
||||
message = "Property #{key} must be one of: #{to_be.map { |v| v.inspect }.join(", ")}! You passed #{value.inspect}."
|
||||
unless errors.empty?
|
||||
message << " Errors:\n#{errors.map { |m| "- #{m}" }.join("\n")}"
|
||||
end
|
||||
raise Exceptions::ValidationFailed, message
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Method to mess with a value before it is validated and stored.
|
||||
#
|
||||
# Allows you to transform values into a canonical form that is easy to
|
||||
# work with.
|
||||
#
|
||||
# This is passed the value to transform, and is run in the context of the
|
||||
# instance (so it has access to other resource properties). It must return
|
||||
# the value that will be stored in the instance.
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x, Integer, coerce: { |v| v.to_i }
|
||||
# ```
|
||||
#
|
||||
def _pv_coerce(opts, key, coercer)
|
||||
if opts.has_key?(key.to_s)
|
||||
raise CannotValidateStaticallyError, "coerce must be evaluated for each resource." if self == Chef::Mixin::ParamsValidate
|
||||
opts[key.to_s] = instance_exec(opts[key], &coercer)
|
||||
elsif opts.has_key?(key.to_sym)
|
||||
raise CannotValidateStaticallyError, "coerce must be evaluated for each resource." if self == Chef::Mixin::ParamsValidate
|
||||
opts[key.to_sym] = instance_exec(opts[key], &coercer)
|
||||
end
|
||||
end
|
||||
|
||||
# We allow Chef::Mixin::ParamsValidate.validate(), but we will raise an
|
||||
# error if you try to do anything requiring there to be an actual resource.
|
||||
# This way, you can statically validate things if you have constant validation
|
||||
# (which is the norm).
|
||||
extend self
|
||||
|
||||
# Used by #set_or_return to avoid emitting a deprecation warning for
|
||||
# "value nil" and to keep default stickiness working exactly the same
|
||||
# @api private
|
||||
class SetOrReturnProperty < (defined?(::Chef::Mixin::ParamsValidate::SetOrReturnProperty) ? ::Chef::Mixin::ParamsValidate::SetOrReturnProperty : Chef::Property)
|
||||
def get(resource, nil_set: false)
|
||||
value = super
|
||||
# All values are sticky, frozen or not
|
||||
if !is_set?(resource)
|
||||
set_value(resource, value)
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
def call(resource, value = NOT_PASSED)
|
||||
# setting to nil does a get
|
||||
if value.nil? && !explicitly_accepts_nil?(resource)
|
||||
get(resource, nil_set: true)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,117 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/mixin/powershell_out'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#--
|
||||
# Copyright:: Copyright 2015-2016, Chef Software, 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.
|
||||
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module Mixin
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin, self) if defined?(::Chef::Mixin)
|
||||
module PowershellOut
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin::PowershellOut, self) if defined?(::Chef::Mixin::PowershellOut)
|
||||
include Chef::Mixin::ShellOut
|
||||
include Chef::Mixin::WindowsArchitectureHelper
|
||||
|
||||
# Run a command under powershell with the same API as shell_out. The
|
||||
# options hash is extended to take an "architecture" flag which
|
||||
# can be set to :i386 or :x86_64 to force the windows architecture.
|
||||
#
|
||||
# @param script [String] script to run
|
||||
# @param options [Hash] options hash
|
||||
# @return [Mixlib::Shellout] mixlib-shellout object
|
||||
def powershell_out(*command_args)
|
||||
script = command_args.first
|
||||
options = command_args.last.is_a?(Hash) ? command_args.last : nil
|
||||
|
||||
run_command_with_os_architecture(script, options)
|
||||
end
|
||||
|
||||
# Run a command under powershell with the same API as shell_out!
|
||||
# (raises exceptions on errors)
|
||||
#
|
||||
# @param script [String] script to run
|
||||
# @param options [Hash] options hash
|
||||
# @return [Mixlib::Shellout] mixlib-shellout object
|
||||
def powershell_out!(*command_args)
|
||||
cmd = powershell_out(*command_args)
|
||||
cmd.error!
|
||||
cmd
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Helper function to run shell_out and wrap it with the correct
|
||||
# flags to possibly disable WOW64 redirection (which we often need
|
||||
# because chef-client runs as a 32-bit app on 64-bit windows).
|
||||
#
|
||||
# @param script [String] script to run
|
||||
# @param options [Hash] options hash
|
||||
# @return [Mixlib::Shellout] mixlib-shellout object
|
||||
def run_command_with_os_architecture(script, options)
|
||||
options ||= {}
|
||||
options = options.dup
|
||||
arch = options.delete(:architecture)
|
||||
|
||||
with_os_architecture(nil, architecture: arch) do
|
||||
shell_out(
|
||||
build_powershell_command(script),
|
||||
options
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# Helper to build a powershell command around the script to run.
|
||||
#
|
||||
# @param script [String] script to run
|
||||
# @retrurn [String] powershell command to execute
|
||||
def build_powershell_command(script)
|
||||
flags = [
|
||||
# Hides the copyright banner at startup.
|
||||
"-NoLogo",
|
||||
# Does not present an interactive prompt to the user.
|
||||
"-NonInteractive",
|
||||
# Does not load the Windows PowerShell profile.
|
||||
"-NoProfile",
|
||||
# always set the ExecutionPolicy flag
|
||||
# see http://technet.microsoft.com/en-us/library/ee176961.aspx
|
||||
"-ExecutionPolicy Unrestricted",
|
||||
# Powershell will hang if STDIN is redirected
|
||||
# http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected
|
||||
"-InputFormat None",
|
||||
]
|
||||
|
||||
"powershell.exe #{flags.join(' ')} -Command \"#{script.gsub('"', '\"')}\""
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,328 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/mixin/properties'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
require "chef_compat/copied_from_chef/chef/delayed_evaluator"
|
||||
require "chef_compat/copied_from_chef/chef/mixin/params_validate"
|
||||
require "chef_compat/copied_from_chef/chef/property"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module Mixin
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin, self) if defined?(::Chef::Mixin)
|
||||
module Properties
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin::Properties, self) if defined?(::Chef::Mixin::Properties)
|
||||
module ClassMethods
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin::Properties::ClassMethods, self) if defined?(::Chef::Mixin::Properties::ClassMethods)
|
||||
#
|
||||
# The list of properties defined on this resource.
|
||||
#
|
||||
# Everything defined with `property` is in this list.
|
||||
#
|
||||
# @param include_superclass [Boolean] `true` to include properties defined
|
||||
# on superclasses; `false` or `nil` to return the list of properties
|
||||
# directly on this class.
|
||||
#
|
||||
# @return [Hash<Symbol,Property>] The list of property names and types.
|
||||
#
|
||||
def properties(include_superclass = true)
|
||||
if include_superclass
|
||||
result = {}
|
||||
ancestors.reverse_each { |c| result.merge!(c.properties(false)) if c.respond_to?(:properties) }
|
||||
result
|
||||
else
|
||||
@properties ||= {}
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Create a property on this resource class.
|
||||
#
|
||||
# If a superclass has this property, or if this property has already been
|
||||
# defined by this resource, this will *override* the previous value.
|
||||
#
|
||||
# @param name [Symbol] The name of the property.
|
||||
# @param type [Object,Array<Object>] The type(s) of this property.
|
||||
# If present, this is prepended to the `is` validation option.
|
||||
# @param options [Hash<Symbol,Object>] Validation options.
|
||||
# @option options [Object,Array] :is An object, or list of
|
||||
# objects, that must match the value using Ruby's `===` operator
|
||||
# (`options[:is].any? { |v| v === value }`).
|
||||
# @option options [Object,Array] :equal_to An object, or list
|
||||
# of objects, that must be equal to the value using Ruby's `==`
|
||||
# operator (`options[:is].any? { |v| v == value }`)
|
||||
# @option options [Regexp,Array<Regexp>] :regex An object, or
|
||||
# list of objects, that must match the value with `regex.match(value)`.
|
||||
# @option options [Class,Array<Class>] :kind_of A class, or
|
||||
# list of classes, that the value must be an instance of.
|
||||
# @option options [Hash<String,Proc>] :callbacks A hash of
|
||||
# messages -> procs, all of which match the value. The proc must
|
||||
# return a truthy or falsey value (true means it matches).
|
||||
# @option options [Symbol,Array<Symbol>] :respond_to A method
|
||||
# name, or list of method names, the value must respond to.
|
||||
# @option options [Symbol,Array<Symbol>] :cannot_be A property,
|
||||
# or a list of properties, that the value cannot have (such as `:nil` or
|
||||
# `:empty`). The method with a questionmark at the end is called on the
|
||||
# value (e.g. `value.empty?`). If the value does not have this method,
|
||||
# it is considered valid (i.e. if you don't respond to `empty?` we
|
||||
# assume you are not empty).
|
||||
# @option options [Proc] :coerce A proc which will be called to
|
||||
# transform the user input to canonical form. The value is passed in,
|
||||
# and the transformed value returned as output. Lazy values will *not*
|
||||
# be passed to this method until after they are evaluated. Called in the
|
||||
# context of the resource (meaning you can access other properties).
|
||||
# @option options [Boolean] :required `true` if this property
|
||||
# must be present; `false` otherwise. This is checked after the resource
|
||||
# is fully initialized.
|
||||
# @option options [Boolean] :name_property `true` if this
|
||||
# property defaults to the same value as `name`. Equivalent to
|
||||
# `default: lazy { name }`, except that #property_is_set? will
|
||||
# return `true` if the property is set *or* if `name` is set.
|
||||
# @option options [Boolean] :name_attribute Same as `name_property`.
|
||||
# @option options [Object] :default The value this property
|
||||
# will return if the user does not set one. If this is `lazy`, it will
|
||||
# be run in the context of the instance (and able to access other
|
||||
# properties).
|
||||
# @option options [Boolean] :desired_state `true` if this property is
|
||||
# part of desired state. Defaults to `true`.
|
||||
# @option options [Boolean] :identity `true` if this property
|
||||
# is part of object identity. Defaults to `false`.
|
||||
# @option options [Boolean] :sensitive `true` if this property could
|
||||
# contain sensitive information and whose value should be redacted
|
||||
# in any resource reporting / auditing output. Defaults to `false`.
|
||||
#
|
||||
# @example Bare property
|
||||
# property :x
|
||||
#
|
||||
# @example With just a type
|
||||
# property :x, String
|
||||
#
|
||||
# @example With just options
|
||||
# property :x, default: 'hi'
|
||||
#
|
||||
# @example With type and options
|
||||
# property :x, String, default: 'hi'
|
||||
#
|
||||
def property(name, type = NOT_PASSED, **options)
|
||||
name = name.to_sym
|
||||
|
||||
options = options.inject({}) { |memo, (key, value)| memo[key.to_sym] = value; memo }
|
||||
|
||||
options[:instance_variable_name] = :"@#{name}" if !options.has_key?(:instance_variable_name)
|
||||
options[:name] = name
|
||||
options[:declared_in] = self
|
||||
|
||||
if type == NOT_PASSED
|
||||
# If a type is not passed, the property derives from the
|
||||
# superclass property (if any)
|
||||
if properties.has_key?(name)
|
||||
property = properties[name].derive(**options)
|
||||
else
|
||||
property = property_type(**options)
|
||||
end
|
||||
|
||||
# If a Property is specified, derive a new one from that.
|
||||
elsif type.is_a?(Property) || (type.is_a?(Class) && type <= Property)
|
||||
property = type.derive(**options)
|
||||
|
||||
# If a primitive type was passed, combine it with "is"
|
||||
else
|
||||
if options[:is]
|
||||
options[:is] = ([ type ] + [ options[:is] ]).flatten(1)
|
||||
else
|
||||
options[:is] = type
|
||||
end
|
||||
property = property_type(**options)
|
||||
end
|
||||
|
||||
local_properties = properties(false)
|
||||
local_properties[name] = property
|
||||
|
||||
property.emit_dsl
|
||||
end
|
||||
|
||||
#
|
||||
# Create a reusable property type that can be used in multiple properties
|
||||
# in different resources.
|
||||
#
|
||||
# @param options [Hash<Symbol,Object>] Validation options. see #property for
|
||||
# the list of options.
|
||||
#
|
||||
# @example
|
||||
# property_type(default: 'hi')
|
||||
#
|
||||
def property_type(**options)
|
||||
Property.derive(**options)
|
||||
end
|
||||
|
||||
#
|
||||
# Create a lazy value for assignment to a default value.
|
||||
#
|
||||
# @param block The block to run when the value is retrieved.
|
||||
#
|
||||
# @return [Chef::DelayedEvaluator] The lazy value
|
||||
#
|
||||
def lazy(&block)
|
||||
DelayedEvaluator.new(&block)
|
||||
end
|
||||
|
||||
#
|
||||
# Get or set the list of desired state properties for this resource.
|
||||
#
|
||||
# State properties are properties that describe the desired state
|
||||
# of the system, such as file permissions or ownership.
|
||||
# In general, state properties are properties that could be populated by
|
||||
# examining the state of the system (e.g., File.stat can tell you the
|
||||
# permissions on an existing file). Contrarily, properties that are not
|
||||
# "state properties" usually modify the way Chef itself behaves, for example
|
||||
# by providing additional options for a package manager to use when
|
||||
# installing a package.
|
||||
#
|
||||
# This list is used by the Chef client auditing system to extract
|
||||
# information from resources to describe changes made to the system.
|
||||
#
|
||||
# This method is unnecessary when declaring properties with `property`;
|
||||
# properties are added to state_properties by default, and can be turned off
|
||||
# with `desired_state: false`.
|
||||
#
|
||||
# ```ruby
|
||||
# property :x # part of desired state
|
||||
# property :y, desired_state: false # not part of desired state
|
||||
# ```
|
||||
#
|
||||
# @param names [Array<Symbol>] A list of property names to set as desired
|
||||
# state.
|
||||
#
|
||||
# @return [Array<Property>] All properties in desired state.
|
||||
#
|
||||
def state_properties(*names)
|
||||
if !names.empty?
|
||||
names = names.map { |name| name.to_sym }.uniq
|
||||
|
||||
local_properties = properties(false)
|
||||
# Add new properties to the list.
|
||||
names.each do |name|
|
||||
property = properties[name]
|
||||
if !property
|
||||
self.property name, instance_variable_name: false, desired_state: true
|
||||
elsif !property.desired_state?
|
||||
self.property name, desired_state: true
|
||||
end
|
||||
end
|
||||
|
||||
# If state_attrs *excludes* something which is currently desired state,
|
||||
# mark it as desired_state: false.
|
||||
local_properties.each do |name, property|
|
||||
if property.desired_state? && !names.include?(name)
|
||||
self.property name, desired_state: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
properties.values.select { |property| property.desired_state? }
|
||||
end
|
||||
|
||||
#
|
||||
# Set the identity of this resource to a particular set of properties.
|
||||
#
|
||||
# This drives #identity, which returns data that uniquely refers to a given
|
||||
# resource on the given node (in such a way that it can be correlated
|
||||
# across Chef runs).
|
||||
#
|
||||
# This method is unnecessary when declaring properties with `property`;
|
||||
# properties can be added to identity during declaration with
|
||||
# `identity: true`.
|
||||
#
|
||||
# ```ruby
|
||||
# property :x, identity: true # part of identity
|
||||
# property :y # not part of identity
|
||||
# ```
|
||||
#
|
||||
# If no properties are marked as identity, "name" is considered the identity.
|
||||
#
|
||||
# @param names [Array<Symbol>] A list of property names to set as the identity.
|
||||
#
|
||||
# @return [Array<Property>] All identity properties.
|
||||
#
|
||||
def identity_properties(*names)
|
||||
if !names.empty?
|
||||
names = names.map { |name| name.to_sym }
|
||||
|
||||
# Add or change properties that are not part of the identity.
|
||||
names.each do |name|
|
||||
property = properties[name]
|
||||
if !property
|
||||
self.property name, instance_variable_name: false, identity: true
|
||||
elsif !property.identity?
|
||||
self.property name, identity: true
|
||||
end
|
||||
end
|
||||
|
||||
# If identity_properties *excludes* something which is currently part of
|
||||
# the identity, mark it as identity: false.
|
||||
properties.each do |name, property|
|
||||
if property.identity? && !names.include?(name)
|
||||
|
||||
self.property name, identity: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
result = properties.values.select { |property| property.identity? }
|
||||
result = [ properties[:name] ] if result.empty?
|
||||
result
|
||||
end
|
||||
|
||||
def included(other)
|
||||
other.extend ClassMethods
|
||||
end
|
||||
end
|
||||
|
||||
def self.included(other)
|
||||
other.extend ClassMethods
|
||||
end
|
||||
|
||||
include Chef::Mixin::ParamsValidate
|
||||
|
||||
#
|
||||
# Whether this property has been set (or whether it has a default that has
|
||||
# been retrieved).
|
||||
#
|
||||
# @param name [Symbol] The name of the property.
|
||||
# @return [Boolean] `true` if the property has been set.
|
||||
#
|
||||
def property_is_set?(name)
|
||||
property = self.class.properties[name.to_sym]
|
||||
raise ArgumentError, "Property #{name} is not defined in class #{self}" if !property
|
||||
property.is_set?(self)
|
||||
end
|
||||
|
||||
#
|
||||
# Clear this property as if it had never been set. It will thereafter return
|
||||
# the default.
|
||||
# been retrieved).
|
||||
#
|
||||
# @param name [Symbol] The name of the property.
|
||||
#
|
||||
def reset_property(name)
|
||||
property = self.class.properties[name.to_sym]
|
||||
raise ArgumentError, "Property #{name} is not defined in class #{self}" if !property
|
||||
property.reset(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,713 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/property'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: John Keiser <jkeiser@chef.io>
|
||||
# Copyright:: Copyright 2015-2016, John Keiser.
|
||||
# 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 "chef_compat/copied_from_chef/chef/delayed_evaluator"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
#
|
||||
# Type and validation information for a property on a resource.
|
||||
#
|
||||
# A property named "x" manipulates the "@x" instance variable on a
|
||||
# resource. The *presence* of the variable (`instance_variable_defined?(@x)`)
|
||||
# tells whether the variable is defined; it may have any actual value,
|
||||
# constrained only by validation.
|
||||
#
|
||||
# Properties may have validation, defaults, and coercion, and have full
|
||||
# support for lazy values.
|
||||
#
|
||||
# @see Chef::Resource.property
|
||||
# @see Chef::DelayedEvaluator
|
||||
#
|
||||
class Property < (defined?(::Chef::Property) ? ::Chef::Property : Object)
|
||||
#
|
||||
# Create a reusable property type that can be used in multiple properties
|
||||
# in different resources.
|
||||
#
|
||||
# @param options [Hash<Symbol,Object>] Validation options. See Chef::Resource.property for
|
||||
# the list of options.
|
||||
#
|
||||
# @example
|
||||
# Property.derive(default: 'hi')
|
||||
#
|
||||
def self.derive(**options)
|
||||
new(**options)
|
||||
end
|
||||
|
||||
#
|
||||
# Create a new property.
|
||||
#
|
||||
# @param options [Hash<Symbol,Object>] Property options, including
|
||||
# control options here, as well as validation options (see
|
||||
# Chef::Mixin::ParamsValidate#validate for a description of validation
|
||||
# options).
|
||||
# @option options [Symbol] :name The name of this property.
|
||||
# @option options [Class] :declared_in The class this property comes from.
|
||||
# @option options [Symbol] :instance_variable_name The instance variable
|
||||
# tied to this property. Must include a leading `@`. Defaults to `@<name>`.
|
||||
# `nil` means the property is opaque and not tied to a specific instance
|
||||
# variable.
|
||||
# @option options [Boolean] :desired_state `true` if this property is part of desired
|
||||
# state. Defaults to `true`.
|
||||
# @option options [Boolean] :identity `true` if this property is part of object
|
||||
# identity. Defaults to `false`.
|
||||
# @option options [Boolean] :name_property `true` if this
|
||||
# property defaults to the same value as `name`. Equivalent to
|
||||
# `default: lazy { name }`, except that #property_is_set? will
|
||||
# return `true` if the property is set *or* if `name` is set.
|
||||
# @option options [Boolean] :nillable `true` opt-in to Chef-13 style behavior where
|
||||
# attempting to set a nil value will really set a nil value instead of issuing
|
||||
# a warning and operating like a getter
|
||||
# @option options [Object] :default The value this property
|
||||
# will return if the user does not set one. If this is `lazy`, it will
|
||||
# be run in the context of the instance (and able to access other
|
||||
# properties) and cached. If not, the value will be frozen with Object#freeze
|
||||
# to prevent users from modifying it in an instance.
|
||||
# @option options [Proc] :coerce A proc which will be called to
|
||||
# transform the user input to canonical form. The value is passed in,
|
||||
# and the transformed value returned as output. Lazy values will *not*
|
||||
# be passed to this method until after they are evaluated. Called in the
|
||||
# context of the resource (meaning you can access other properties).
|
||||
# @option options [Boolean] :required `true` if this property
|
||||
# must be present; `false` otherwise. This is checked after the resource
|
||||
# is fully initialized.
|
||||
#
|
||||
def initialize(**options)
|
||||
super if defined?(::Chef::Property)
|
||||
options = options.inject({}) { |memo, (key, value)| memo[key.to_sym] = value; memo }
|
||||
@options = options
|
||||
options[:name] = options[:name].to_sym if options[:name]
|
||||
options[:instance_variable_name] = options[:instance_variable_name].to_sym if options[:instance_variable_name]
|
||||
|
||||
# Replace name_attribute with name_property
|
||||
if options.has_key?(:name_attribute)
|
||||
# If we have both name_attribute and name_property and they differ, raise an error
|
||||
if options.has_key?(:name_property)
|
||||
raise ArgumentError, "Cannot specify both name_property and name_attribute together on property #{self}."
|
||||
end
|
||||
# replace name_property with name_attribute in place
|
||||
options = Hash[options.map { |k, v| k == :name_attribute ? [ :name_property, v ] : [ k, v ] }]
|
||||
@options = options
|
||||
end
|
||||
|
||||
# Only pick the first of :default, :name_property and :name_attribute if
|
||||
# more than one is specified.
|
||||
if options.has_key?(:default) && options[:name_property]
|
||||
if options[:default].nil? || options.keys.index(:name_property) < options.keys.index(:default)
|
||||
options.delete(:default)
|
||||
preferred_default = :name_property
|
||||
else
|
||||
options.delete(:name_property)
|
||||
preferred_default = :default
|
||||
end
|
||||
Chef.log_deprecation("Cannot specify both default and name_property together on property #{self}. Only one (#{preferred_default}) will be obeyed. In Chef 13, this will become an error. Please remove one or the other from the property.")
|
||||
end
|
||||
|
||||
# Validate the default early, so the user gets a good error message, and
|
||||
# cache it so we don't do it again if so
|
||||
begin
|
||||
# If we can validate it all the way to output, do it.
|
||||
@stored_default = input_to_stored_value(nil, default, is_default: true)
|
||||
rescue Chef::Exceptions::CannotValidateStaticallyError
|
||||
# If the validation is not static (i.e. has procs), we will have to
|
||||
# coerce and validate the default each time we run
|
||||
end
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{name || "<property type>"}#{declared_in ? " of resource #{declared_in.resource_name}" : ""}"
|
||||
end
|
||||
|
||||
#
|
||||
# The name of this property.
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
def name
|
||||
options[:name]
|
||||
end
|
||||
|
||||
#
|
||||
# The class this property was defined in.
|
||||
#
|
||||
# @return [Class]
|
||||
#
|
||||
def declared_in
|
||||
options[:declared_in]
|
||||
end
|
||||
|
||||
#
|
||||
# The instance variable associated with this property.
|
||||
#
|
||||
# Defaults to `@<name>`
|
||||
#
|
||||
# @return [Symbol]
|
||||
#
|
||||
def instance_variable_name
|
||||
if options.has_key?(:instance_variable_name)
|
||||
options[:instance_variable_name]
|
||||
elsif name
|
||||
:"@#{name}"
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# The raw default value for this resource.
|
||||
#
|
||||
# Does not coerce or validate the default. Does not evaluate lazy values.
|
||||
#
|
||||
# Defaults to `lazy { name }` if name_property is true; otherwise defaults to
|
||||
# `nil`
|
||||
#
|
||||
def default
|
||||
return options[:default] if options.has_key?(:default)
|
||||
return Chef::DelayedEvaluator.new { name } if name_property?
|
||||
nil
|
||||
end
|
||||
|
||||
#
|
||||
# Whether this is part of the resource's natural identity or not.
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
def identity?
|
||||
options[:identity]
|
||||
end
|
||||
|
||||
#
|
||||
# Whether this is part of desired state or not.
|
||||
#
|
||||
# Defaults to true.
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
def desired_state?
|
||||
return true if !options.has_key?(:desired_state)
|
||||
options[:desired_state]
|
||||
end
|
||||
|
||||
#
|
||||
# Whether this is name_property or not.
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
def name_property?
|
||||
options[:name_property]
|
||||
end
|
||||
|
||||
#
|
||||
# Whether this property has a default value.
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
def has_default?
|
||||
options.has_key?(:default) || name_property?
|
||||
end
|
||||
|
||||
#
|
||||
# Whether this property is required or not.
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
def required?
|
||||
options[:required]
|
||||
end
|
||||
|
||||
#
|
||||
# Whether this property is sensitive or not.
|
||||
#
|
||||
# Defaults to false.
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
def sensitive?
|
||||
options.fetch(:sensitive, false)
|
||||
end
|
||||
|
||||
#
|
||||
# Validation options. (See Chef::Mixin::ParamsValidate#validate.)
|
||||
#
|
||||
# @return [Hash<Symbol,Object>]
|
||||
#
|
||||
def validation_options
|
||||
@validation_options ||= options.reject do |k, v|
|
||||
[:declared_in, :name, :instance_variable_name, :desired_state, :identity, :default, :name_property, :coerce, :required, :nillable, :sensitive].include?(k)
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Handle the property being called.
|
||||
#
|
||||
# The base implementation does the property get-or-set:
|
||||
#
|
||||
# ```ruby
|
||||
# resource.myprop # get
|
||||
# resource.myprop value # set
|
||||
# ```
|
||||
#
|
||||
# Subclasses may implement this with any arguments they want, as long as
|
||||
# the corresponding DSL calls it correctly.
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource to get the property from.
|
||||
# @param value The value to set (or NOT_PASSED if it is a get).
|
||||
#
|
||||
# @return The current value of the property. If it is a `set`, lazy values
|
||||
# will be returned without running, validating or coercing. If it is a
|
||||
# `get`, the non-lazy, coerced, validated value will always be returned.
|
||||
#
|
||||
def call(resource, value = NOT_PASSED)
|
||||
if value == NOT_PASSED
|
||||
return get(resource)
|
||||
end
|
||||
|
||||
if value.nil? && !nillable?
|
||||
# In Chef 12, value(nil) does a *get* instead of a set, so we
|
||||
# warn if the value would have been changed. In Chef 13, it will be
|
||||
# equivalent to value = nil.
|
||||
result = get(resource, nil_set: true)
|
||||
|
||||
# Warn about this becoming a set in Chef 13.
|
||||
begin
|
||||
input_to_stored_value(resource, value)
|
||||
# If nil is valid, and it would change the value, warn that this will change to a set.
|
||||
if !result.nil?
|
||||
Chef.log_deprecation("An attempt was made to change #{name} from #{result.inspect} to nil by calling #{name}(nil). In Chef 12, this does a get rather than a set. In Chef 13, this will change to set the value to nil.")
|
||||
end
|
||||
rescue Chef::Exceptions::DeprecatedFeatureError
|
||||
raise
|
||||
rescue
|
||||
# If nil is invalid, warn that this will become an error.
|
||||
Chef.log_deprecation("nil is an invalid value for #{self}. In Chef 13, this warning will change to an error. Error: #{$!}")
|
||||
end
|
||||
|
||||
result
|
||||
else
|
||||
# Anything else, such as myprop(value) is a set
|
||||
set(resource, value)
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Get the property value from the resource, handling lazy values,
|
||||
# defaults, and validation.
|
||||
#
|
||||
# - If the property's value is lazy, it is evaluated, coerced and validated.
|
||||
# - If the property has no value, and is required, raises ValidationFailed.
|
||||
# - If the property has no value, but has a lazy default, it is evaluated,
|
||||
# coerced and validated. If the evaluated value is frozen, the resulting
|
||||
# - If the property has no value, but has a default, the default value
|
||||
# will be returned and frozen. If the default value is lazy, it will be
|
||||
# evaluated, coerced and validated, and the result stored in the property.
|
||||
# - If the property has no value, but is name_property, `resource.name`
|
||||
# is retrieved, coerced, validated and stored in the property.
|
||||
# - Otherwise, `nil` is returned.
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource to get the property from.
|
||||
#
|
||||
# @return The value of the property.
|
||||
#
|
||||
# @raise Chef::Exceptions::ValidationFailed If the value is invalid for
|
||||
# this property, or if the value is required and not set.
|
||||
#
|
||||
def get(resource, nil_set: false)
|
||||
# If it's set, return it (and evaluate any lazy values)
|
||||
if is_set?(resource)
|
||||
value = get_value(resource)
|
||||
value = stored_value_to_output(resource, value)
|
||||
|
||||
else
|
||||
# We are getting the default value.
|
||||
|
||||
# If the user does something like this:
|
||||
#
|
||||
# ```
|
||||
# class MyResource < Chef::Resource
|
||||
# property :content
|
||||
# action :create do
|
||||
# file '/x.txt' do
|
||||
# content content
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# ```
|
||||
#
|
||||
# It won't do what they expect. This checks whether you try to *read*
|
||||
# `content` while we are compiling the resource.
|
||||
if !nil_set &&
|
||||
resource.respond_to?(:resource_initializing) &&
|
||||
resource.resource_initializing &&
|
||||
resource.respond_to?(:enclosing_provider) &&
|
||||
resource.enclosing_provider &&
|
||||
resource.enclosing_provider.new_resource &&
|
||||
resource.enclosing_provider.new_resource.respond_to?(name)
|
||||
Chef::Log.warn("#{Chef::Log.caller_location}: property #{name} is declared in both #{resource} and #{resource.enclosing_provider}. Use new_resource.#{name} instead. At #{Chef::Log.caller_location}")
|
||||
end
|
||||
|
||||
if has_default?
|
||||
# If we were able to cache the stored_default, grab it.
|
||||
if defined?(@stored_default)
|
||||
value = @stored_default
|
||||
else
|
||||
# Otherwise, we have to validate it now.
|
||||
value = input_to_stored_value(resource, default, is_default: true)
|
||||
end
|
||||
value = stored_value_to_output(resource, value, is_default: true)
|
||||
|
||||
# If the value is mutable (non-frozen), we set it on the instance
|
||||
# so that people can mutate it. (All constant default values are
|
||||
# frozen.)
|
||||
if !value.frozen? && !value.nil?
|
||||
set_value(resource, value)
|
||||
end
|
||||
|
||||
value
|
||||
|
||||
elsif required?
|
||||
raise Chef::Exceptions::ValidationFailed, "#{name} is required"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Set the value of this property in the given resource.
|
||||
#
|
||||
# Non-lazy values are coerced and validated before being set. Coercion
|
||||
# and validation of lazy values is delayed until they are first retrieved.
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource to set this property in.
|
||||
# @param value The value to set.
|
||||
#
|
||||
# @return The value that was set, after coercion (if lazy, still returns
|
||||
# the lazy value)
|
||||
#
|
||||
# @raise Chef::Exceptions::ValidationFailed If the value is invalid for
|
||||
# this property.
|
||||
#
|
||||
def set(resource, value)
|
||||
set_value(resource, input_to_stored_value(resource, value))
|
||||
end
|
||||
|
||||
#
|
||||
# Find out whether this property has been set.
|
||||
#
|
||||
# This will be true if:
|
||||
# - The user explicitly set the value
|
||||
# - The property has a default, and the value was retrieved.
|
||||
#
|
||||
# From this point of view, it is worth looking at this as "what does the
|
||||
# user think this value should be." In order words, if the user grabbed
|
||||
# the value, even if it was a default, they probably based calculations on
|
||||
# it. If they based calculations on it and the value changes, the rest of
|
||||
# the world gets inconsistent.
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource to get the property from.
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
def is_set?(resource)
|
||||
value_is_set?(resource)
|
||||
end
|
||||
|
||||
#
|
||||
# Reset the value of this property so that is_set? will return false and the
|
||||
# default will be returned in the future.
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource to get the property from.
|
||||
#
|
||||
def reset(resource)
|
||||
reset_value(resource)
|
||||
end
|
||||
|
||||
#
|
||||
# Coerce an input value into canonical form for the property.
|
||||
#
|
||||
# After coercion, the value is suitable for storage in the resource.
|
||||
# You must validate values after coercion, however.
|
||||
#
|
||||
# Does no special handling for lazy values.
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource we're coercing against
|
||||
# (to provide context for the coerce).
|
||||
# @param value The value to coerce.
|
||||
#
|
||||
# @return The coerced value.
|
||||
#
|
||||
# @raise Chef::Exceptions::ValidationFailed If the value is invalid for
|
||||
# this property.
|
||||
#
|
||||
def coerce(resource, value)
|
||||
if options.has_key?(:coerce)
|
||||
# If we have no default value, `nil` is never coerced or validated
|
||||
unless !has_default? && value.nil?
|
||||
value = exec_in_resource(resource, options[:coerce], value)
|
||||
end
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
#
|
||||
# Validate a value.
|
||||
#
|
||||
# Calls Chef::Mixin::ParamsValidate#validate with #validation_options as
|
||||
# options.
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource we're validating against
|
||||
# (to provide context for the validate).
|
||||
# @param value The value to validate.
|
||||
#
|
||||
# @raise Chef::Exceptions::ValidationFailed If the value is invalid for
|
||||
# this property.
|
||||
#
|
||||
def validate(resource, value)
|
||||
# If we have no default value, `nil` is never coerced or validated
|
||||
unless value.nil? && !has_default?
|
||||
if resource
|
||||
resource.validate({ name => value }, { name => validation_options })
|
||||
else
|
||||
name = self.name || :property_type
|
||||
Chef::Mixin::ParamsValidate.validate({ name => value }, { name => validation_options })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Derive a new Property that is just like this one, except with some added or
|
||||
# changed options.
|
||||
#
|
||||
# @param options [Hash<Symbol,Object>] List of options that would be passed
|
||||
# to #initialize.
|
||||
#
|
||||
# @return [Property] The new property type.
|
||||
#
|
||||
def derive(**modified_options)
|
||||
# Since name_property, name_attribute and default override each other,
|
||||
# if you specify one of them in modified_options it overrides anything in
|
||||
# the original options.
|
||||
options = self.options
|
||||
if modified_options.has_key?(:name_property) ||
|
||||
modified_options.has_key?(:name_attribute) ||
|
||||
modified_options.has_key?(:default)
|
||||
options = options.reject { |k, v| k == :name_attribute || k == :name_property || k == :default }
|
||||
end
|
||||
self.class.new(options.merge(modified_options))
|
||||
end
|
||||
|
||||
#
|
||||
# Emit the DSL for this property into the resource class (`declared_in`).
|
||||
#
|
||||
# Creates a getter and setter for the property.
|
||||
#
|
||||
def emit_dsl
|
||||
# We don't create the getter/setter if it's a custom property; we will
|
||||
# be using the existing getter/setter to manipulate it instead.
|
||||
return if !instance_variable_name
|
||||
|
||||
# We prefer this form because the property name won't show up in the
|
||||
# stack trace if you use `define_method`.
|
||||
declared_in.class_eval <<-EOM, __FILE__, __LINE__ + 1
|
||||
def #{name}(value=NOT_PASSED)
|
||||
raise "Property `#{name}` of `\#{self}` was incorrectly passed a block. Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block_given?
|
||||
self.class.properties[#{name.inspect}].call(self, value)
|
||||
end
|
||||
def #{name}=(value)
|
||||
raise "Property `#{name}` of `\#{self}` was incorrectly passed a block. Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block_given?
|
||||
self.class.properties[#{name.inspect}].set(self, value)
|
||||
end
|
||||
EOM
|
||||
rescue SyntaxError
|
||||
# If the name is not a valid ruby name, we use define_method.
|
||||
declared_in.define_method(name) do |value = NOT_PASSED, &block|
|
||||
raise "Property `#{name}` of `#{self}` was incorrectly passed a block! Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block
|
||||
self.class.properties[name].call(self, value)
|
||||
end
|
||||
declared_in.define_method("#{name}=") do |value, &block|
|
||||
raise "Property `#{name}` of `#{self}` was incorrectly passed a block! Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block
|
||||
self.class.properties[name].set(self, value)
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# The options this Property will use for get/set behavior and validation.
|
||||
#
|
||||
# @see #initialize for a list of valid options.
|
||||
#
|
||||
attr_reader :options
|
||||
|
||||
#
|
||||
# Find out whether this type accepts nil explicitly.
|
||||
#
|
||||
# A type accepts nil explicitly if "is" allows nil, it validates as nil, *and* is not simply
|
||||
# an empty type.
|
||||
#
|
||||
# A type is presumed to accept nil if it does coercion (which must handle nil).
|
||||
#
|
||||
# These examples accept nil explicitly:
|
||||
# ```ruby
|
||||
# property :a, [ String, nil ]
|
||||
# property :a, [ String, NilClass ]
|
||||
# property :a, [ String, proc { |v| v.nil? } ]
|
||||
# ```
|
||||
#
|
||||
# This does not (because the "is" doesn't exist or doesn't have nil):
|
||||
#
|
||||
# ```ruby
|
||||
# property :x, String
|
||||
# ```
|
||||
#
|
||||
# These do not, even though nil would validate fine (because they do not
|
||||
# have "is"):
|
||||
#
|
||||
# ```ruby
|
||||
# property :a
|
||||
# property :a, equal_to: [ 1, 2, 3, nil ]
|
||||
# property :a, kind_of: [ String, NilClass ]
|
||||
# property :a, respond_to: [ ]
|
||||
# property :a, callbacks: { "a" => proc { |v| v.nil? } }
|
||||
# ```
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource we're coercing against
|
||||
# (to provide context for the coerce).
|
||||
#
|
||||
# @return [Boolean] Whether this value explicitly accepts nil.
|
||||
#
|
||||
# @api private
|
||||
def explicitly_accepts_nil?(resource)
|
||||
options.has_key?(:coerce) ||
|
||||
(options.has_key?(:is) && resource.send(:_pv_is, { name => nil }, name, options[:is], raise_error: false))
|
||||
end
|
||||
|
||||
# @api private
|
||||
def get_value(resource)
|
||||
if instance_variable_name
|
||||
resource.instance_variable_get(instance_variable_name)
|
||||
else
|
||||
resource.send(name)
|
||||
end
|
||||
end
|
||||
|
||||
# @api private
|
||||
def set_value(resource, value)
|
||||
if instance_variable_name
|
||||
resource.instance_variable_set(instance_variable_name, value)
|
||||
else
|
||||
resource.send(name, value)
|
||||
end
|
||||
end
|
||||
|
||||
# @api private
|
||||
def value_is_set?(resource)
|
||||
if instance_variable_name
|
||||
resource.instance_variable_defined?(instance_variable_name)
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
# @api private
|
||||
def reset_value(resource)
|
||||
if instance_variable_name
|
||||
if value_is_set?(resource)
|
||||
resource.remove_instance_variable(instance_variable_name)
|
||||
end
|
||||
else
|
||||
raise ArgumentError, "Property #{name} has no instance variable defined and cannot be reset"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def exec_in_resource(resource, proc, *args)
|
||||
if resource
|
||||
if proc.arity > args.size
|
||||
value = proc.call(resource, *args)
|
||||
else
|
||||
value = resource.instance_exec(*args, &proc)
|
||||
end
|
||||
else
|
||||
# If we don't have a resource yet, we can't exec in resource!
|
||||
raise Chef::Exceptions::CannotValidateStaticallyError, "Cannot validate or coerce without a resource"
|
||||
end
|
||||
end
|
||||
|
||||
def input_to_stored_value(resource, value, is_default: false)
|
||||
unless value.is_a?(DelayedEvaluator)
|
||||
value = coerce_and_validate(resource, value, is_default: is_default)
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
def stored_value_to_output(resource, value, is_default: false)
|
||||
# Crack open lazy values before giving the result to the user
|
||||
if value.is_a?(DelayedEvaluator)
|
||||
value = exec_in_resource(resource, value)
|
||||
value = coerce_and_validate(resource, value, is_default: is_default)
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
# Coerces and validates the value. If the value is a default, it will warn
|
||||
# the user that invalid defaults are bad mmkay, and return it as if it were
|
||||
# valid.
|
||||
def coerce_and_validate(resource, value, is_default: false)
|
||||
result = coerce(resource, value)
|
||||
begin
|
||||
# If the input is from a default, we need to emit an invalid default warning on validate.
|
||||
validate(resource, result)
|
||||
rescue Chef::Exceptions::CannotValidateStaticallyError
|
||||
# This one gets re-raised
|
||||
raise
|
||||
rescue
|
||||
# Anything else is just an invalid default: in those cases, we just
|
||||
# warn and return the (possibly coerced) value to the user.
|
||||
if is_default
|
||||
if value.nil?
|
||||
Chef.log_deprecation("Default value nil is invalid for property #{self}. Possible fixes: 1. Remove 'default: nil' if nil means 'undefined'. 2. Set a valid default value if there is a reasonable one. 3. Allow nil as a valid value of your property (for example, 'property #{name.inspect}, [ String, nil ], default: nil'). Error: #{$!}")
|
||||
else
|
||||
Chef.log_deprecation("Default value #{value.inspect} is invalid for property #{self}. In Chef 13 this will become an error: #{$!}.")
|
||||
end
|
||||
else
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
def nillable?
|
||||
!!options[:nillable]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,164 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/provider'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
require "chef_compat/copied_from_chef/chef/dsl/core"
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object)
|
||||
include Chef::DSL::Core
|
||||
attr_accessor :action
|
||||
def initialize(new_resource, run_context)
|
||||
super if defined?(::Chef::Provider)
|
||||
@new_resource = new_resource
|
||||
@action = action
|
||||
@current_resource = nil
|
||||
@run_context = run_context
|
||||
@converge_actions = nil
|
||||
|
||||
@recipe_name = nil
|
||||
@cookbook_name = nil
|
||||
self.class.include_resource_dsl_module(new_resource)
|
||||
end
|
||||
def converge_if_changed(*properties, &converge_block)
|
||||
if !converge_block
|
||||
raise ArgumentError, "converge_if_changed must be passed a block!"
|
||||
end
|
||||
|
||||
properties = new_resource.class.state_properties.map { |p| p.name } if properties.empty?
|
||||
properties = properties.map { |p| p.to_sym }
|
||||
if current_resource
|
||||
# Collect the list of modified properties
|
||||
specified_properties = properties.select { |property| new_resource.property_is_set?(property) }
|
||||
modified = specified_properties.select { |p| new_resource.send(p) != current_resource.send(p) }
|
||||
if modified.empty?
|
||||
properties_str = if sensitive
|
||||
specified_properties.join(", ")
|
||||
else
|
||||
specified_properties.map { |p| "#{p}=#{new_resource.send(p).inspect}" }.join(", ")
|
||||
end
|
||||
Chef::Log.debug("Skipping update of #{new_resource}: has not changed any of the specified properties #{properties_str}.")
|
||||
return false
|
||||
end
|
||||
|
||||
# Print the pretty green text and run the block
|
||||
property_size = modified.map { |p| p.size }.max
|
||||
modified.map! do |p|
|
||||
properties_str = if sensitive
|
||||
"(suppressed sensitive property)"
|
||||
else
|
||||
"#{new_resource.send(p).inspect} (was #{current_resource.send(p).inspect})"
|
||||
end
|
||||
" set #{p.to_s.ljust(property_size)} to #{properties_str}"
|
||||
end
|
||||
converge_by([ "update #{current_resource.identity}" ] + modified, &converge_block)
|
||||
|
||||
else
|
||||
# The resource doesn't exist. Mark that we are *creating* this, and
|
||||
# write down any properties we are setting.
|
||||
property_size = properties.map { |p| p.size }.max
|
||||
created = properties.map do |property|
|
||||
default = " (default value)" unless new_resource.property_is_set?(property)
|
||||
properties_str = if sensitive
|
||||
"(suppressed sensitive property)"
|
||||
else
|
||||
new_resource.send(property).inspect
|
||||
end
|
||||
" set #{property.to_s.ljust(property_size)} to #{properties_str}#{default}"
|
||||
end
|
||||
|
||||
converge_by([ "create #{new_resource.identity}" ] + created, &converge_block)
|
||||
end
|
||||
true
|
||||
end
|
||||
def self.include_resource_dsl(include_resource_dsl)
|
||||
@include_resource_dsl = include_resource_dsl
|
||||
end
|
||||
def self.include_resource_dsl_module(resource)
|
||||
if @include_resource_dsl && !defined?(@included_resource_dsl_module)
|
||||
provider_class = self
|
||||
@included_resource_dsl_module = Module.new do
|
||||
extend Forwardable
|
||||
define_singleton_method(:to_s) { "forwarder module for #{provider_class}" }
|
||||
define_singleton_method(:inspect) { to_s }
|
||||
# Add a delegator for each explicit property that will get the *current* value
|
||||
# of the property by default instead of the *actual* value.
|
||||
resource.class.properties.each do |name, property|
|
||||
class_eval(<<-EOM, __FILE__, __LINE__)
|
||||
def #{name}(*args, &block)
|
||||
# If no arguments were passed, we process "get" by defaulting
|
||||
# the value to current_resource, not new_resource. This helps
|
||||
# avoid issues where resources accidentally overwrite perfectly
|
||||
# valid stuff with default values.
|
||||
if args.empty? && !block
|
||||
if !new_resource.property_is_set?(__method__) && current_resource
|
||||
return current_resource.public_send(__method__)
|
||||
end
|
||||
end
|
||||
new_resource.public_send(__method__, *args, &block)
|
||||
end
|
||||
EOM
|
||||
end
|
||||
dsl_methods =
|
||||
resource.class.public_instance_methods +
|
||||
resource.class.protected_instance_methods -
|
||||
provider_class.instance_methods -
|
||||
resource.class.properties.keys
|
||||
def_delegators(:new_resource, *dsl_methods)
|
||||
end
|
||||
include @included_resource_dsl_module
|
||||
end
|
||||
end
|
||||
def self.use_inline_resources
|
||||
extend InlineResources::ClassMethods
|
||||
include InlineResources
|
||||
end
|
||||
module InlineResources
|
||||
CopiedFromChef.extend_chef_module(::Chef::Provider::InlineResources, self) if defined?(::Chef::Provider::InlineResources)
|
||||
def compile_and_converge_action(&block)
|
||||
old_run_context = run_context
|
||||
@run_context = run_context.create_child
|
||||
return_value = instance_eval(&block)
|
||||
Chef::Runner.new(run_context).converge
|
||||
return_value
|
||||
ensure
|
||||
if run_context.resource_collection.any? { |r| r.updated? }
|
||||
new_resource.updated_by_last_action(true)
|
||||
end
|
||||
@run_context = old_run_context
|
||||
end
|
||||
module ClassMethods
|
||||
CopiedFromChef.extend_chef_module(::Chef::Provider::InlineResources::ClassMethods, self) if defined?(::Chef::Provider::InlineResources::ClassMethods)
|
||||
def action(name, &block)
|
||||
# We need the block directly in a method so that `super` works
|
||||
define_method("compile_action_#{name}", &block)
|
||||
# We try hard to use `def` because define_method doesn't show the method name in the stack.
|
||||
begin
|
||||
class_eval <<-EOM
|
||||
def action_#{name}
|
||||
compile_and_converge_action { compile_action_#{name} }
|
||||
end
|
||||
EOM
|
||||
rescue SyntaxError
|
||||
define_method("action_#{name}") { send("compile_action_#{name}") }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
protected
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,269 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/provider/apt_repository'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Thom May (<thom@chef.io>)
|
||||
# Copyright:: Copyright (c) 2016 Chef Software, 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 "chef_compat/copied_from_chef/chef/resource"
|
||||
require "chef_compat/copied_from_chef/chef/dsl/declare_resource"
|
||||
require "chef_compat/copied_from_chef/chef/provider/noop"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object)
|
||||
class AptRepository < (defined?(::Chef::Provider::AptRepository) ? ::Chef::Provider::AptRepository : Chef::Provider)
|
||||
use_inline_resources
|
||||
|
||||
include Chef::Mixin::ShellOut
|
||||
extend Chef::Mixin::Which
|
||||
|
||||
provides :apt_repository do
|
||||
which("apt-get")
|
||||
end
|
||||
|
||||
def whyrun_supported?
|
||||
true
|
||||
end
|
||||
|
||||
def load_current_resource
|
||||
end
|
||||
|
||||
action :add do
|
||||
unless new_resource.key.nil?
|
||||
if is_key_id?(new_resource.key) && !has_cookbook_file?(new_resource.key)
|
||||
install_key_from_keyserver
|
||||
else
|
||||
install_key_from_uri
|
||||
end
|
||||
end
|
||||
|
||||
declare_resource(:execute, "apt-cache gencaches") do
|
||||
ignore_failure true
|
||||
action :nothing
|
||||
end
|
||||
|
||||
declare_resource(:apt_update, new_resource.name) do
|
||||
ignore_failure true
|
||||
action :nothing
|
||||
end
|
||||
|
||||
components = if is_ppa_url?(new_resource.uri) && new_resource.components.empty?
|
||||
"main"
|
||||
else
|
||||
new_resource.components
|
||||
end
|
||||
|
||||
repo = build_repo(
|
||||
new_resource.uri,
|
||||
new_resource.distribution,
|
||||
components,
|
||||
new_resource.trusted,
|
||||
new_resource.arch,
|
||||
new_resource.deb_src
|
||||
)
|
||||
|
||||
declare_resource(:file, "/etc/apt/sources.list.d/#{new_resource.name}.list") do
|
||||
owner "root"
|
||||
group "root"
|
||||
mode "0644"
|
||||
content repo
|
||||
sensitive new_resource.sensitive
|
||||
action :create
|
||||
notifies :run, "execute[apt-cache gencaches]", :immediately
|
||||
notifies :update, "apt_update[#{new_resource.name}]", :immediately if new_resource.cache_rebuild
|
||||
end
|
||||
end
|
||||
|
||||
action :remove do
|
||||
if ::File.exist?("/etc/apt/sources.list.d/#{new_resource.name}.list")
|
||||
converge_by "Removing #{new_resource.name} repository from /etc/apt/sources.list.d/" do
|
||||
declare_resource(:file, "/etc/apt/sources.list.d/#{new_resource.name}.list") do
|
||||
sensitive new_resource.sensitive
|
||||
action :delete
|
||||
notifies :update, "apt_update[#{new_resource.name}]", :immediately if new_resource.cache_rebuild
|
||||
end
|
||||
|
||||
declare_resource(:apt_update, new_resource.name) do
|
||||
ignore_failure true
|
||||
action :nothing
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def is_key_id?(id)
|
||||
id = id[2..-1] if id.start_with?("0x")
|
||||
id =~ /^\h+$/ && [8, 16, 40].include?(id.length)
|
||||
end
|
||||
|
||||
def extract_fingerprints_from_cmd(cmd)
|
||||
so = shell_out(cmd)
|
||||
so.run_command
|
||||
so.stdout.split(/\n/).map do |t|
|
||||
if z = t.match(/^ +Key fingerprint = ([0-9A-F ]+)/)
|
||||
z[1].split.join
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
|
||||
def key_is_valid?(cmd, key)
|
||||
valid = true
|
||||
|
||||
so = shell_out(cmd)
|
||||
so.run_command
|
||||
so.stdout.split(/\n/).map do |t|
|
||||
if t =~ %r{^\/#{key}.*\[expired: .*\]$}
|
||||
Chef::Log.debug "Found expired key: #{t}"
|
||||
valid = false
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
Chef::Log.debug "key #{key} #{valid ? "is valid" : "is not valid"}"
|
||||
valid
|
||||
end
|
||||
|
||||
def cookbook_name
|
||||
new_resource.cookbook || new_resource.cookbook_name
|
||||
end
|
||||
|
||||
def has_cookbook_file?(fn)
|
||||
run_context.has_cookbook_file_in_cookbook?(cookbook_name, fn)
|
||||
end
|
||||
|
||||
def no_new_keys?(file)
|
||||
installed_keys = extract_fingerprints_from_cmd("apt-key finger")
|
||||
proposed_keys = extract_fingerprints_from_cmd("gpg --with-fingerprint #{file}")
|
||||
(installed_keys & proposed_keys).sort == proposed_keys.sort
|
||||
end
|
||||
|
||||
def install_key_from_uri
|
||||
key_name = new_resource.key.gsub(/[^0-9A-Za-z\-]/, "_")
|
||||
cached_keyfile = ::File.join(Chef::Config[:file_cache_path], key_name)
|
||||
type = if new_resource.key.start_with?("http")
|
||||
:remote_file
|
||||
elsif has_cookbook_file?(new_resource.key)
|
||||
:cookbook_file
|
||||
else
|
||||
raise Chef::Exceptions::FileNotFound, "Cannot locate key file"
|
||||
end
|
||||
|
||||
declare_resource(type, cached_keyfile) do
|
||||
source new_resource.key
|
||||
mode "0644"
|
||||
sensitive new_resource.sensitive
|
||||
action :create
|
||||
end
|
||||
|
||||
raise "The key #{cached_keyfile} is invalid and cannot be used to verify an apt repository." unless key_is_valid?("gpg #{cached_keyfile}", "")
|
||||
|
||||
declare_resource(:execute, "apt-key add #{cached_keyfile}") do
|
||||
sensitive new_resource.sensitive
|
||||
action :run
|
||||
not_if do
|
||||
no_new_keys?(cached_keyfile)
|
||||
end
|
||||
notifies :run, "execute[apt-cache gencaches]", :immediately
|
||||
end
|
||||
end
|
||||
|
||||
def install_key_from_keyserver(key = new_resource.key, keyserver = new_resource.keyserver)
|
||||
cmd = "apt-key adv --recv"
|
||||
cmd << " --keyserver-options http-proxy=#{new_resource.key_proxy}" if new_resource.key_proxy
|
||||
cmd << " --keyserver "
|
||||
cmd << if keyserver.start_with?("hkp://")
|
||||
keyserver
|
||||
else
|
||||
"hkp://#{keyserver}:80"
|
||||
end
|
||||
|
||||
cmd << " #{key}"
|
||||
|
||||
declare_resource(:execute, "install-key #{key}") do
|
||||
command cmd
|
||||
sensitive new_resource.sensitive
|
||||
not_if do
|
||||
present = extract_fingerprints_from_cmd("apt-key finger").any? do |fp|
|
||||
fp.end_with? key.upcase
|
||||
end
|
||||
present && key_is_valid?("apt-key list", key.upcase)
|
||||
end
|
||||
notifies :run, "execute[apt-cache gencaches]", :immediately
|
||||
end
|
||||
|
||||
raise "The key #{key} is invalid and cannot be used to verify an apt repository." unless key_is_valid?("apt-key list", key.upcase)
|
||||
end
|
||||
|
||||
def install_ppa_key(owner, repo)
|
||||
url = "https://launchpad.net/api/1.0/~#{owner}/+archive/#{repo}"
|
||||
key_id = Chef::HTTP::Simple.new(url).get("signing_key_fingerprint").delete('"')
|
||||
install_key_from_keyserver(key_id, "keyserver.ubuntu.com")
|
||||
rescue Net::HTTPServerException => e
|
||||
raise "Could not access Launchpad ppa API: #{e.message}"
|
||||
end
|
||||
|
||||
def is_ppa_url?(url)
|
||||
url.start_with?("ppa:")
|
||||
end
|
||||
|
||||
def make_ppa_url(ppa)
|
||||
return unless is_ppa_url?(ppa)
|
||||
owner, repo = ppa[4..-1].split("/")
|
||||
repo ||= "ppa"
|
||||
|
||||
install_ppa_key(owner, repo)
|
||||
"http://ppa.launchpad.net/#{owner}/#{repo}/ubuntu"
|
||||
end
|
||||
|
||||
def build_repo(uri, distribution, components, trusted, arch, add_src = false)
|
||||
uri = make_ppa_url(uri) if is_ppa_url?(uri)
|
||||
|
||||
uri = '"' + uri + '"' unless uri.start_with?("'", '"')
|
||||
components = Array(components).join(" ")
|
||||
options = []
|
||||
options << "arch=#{arch}" if arch
|
||||
options << "trusted=yes" if trusted
|
||||
optstr = unless options.empty?
|
||||
"[" + options.join(" ") + "]"
|
||||
end
|
||||
info = [ optstr, uri, distribution, components ].compact.join(" ")
|
||||
repo = "deb #{info}\n"
|
||||
repo << "deb-src #{info}\n" if add_src
|
||||
repo
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Chef::Provider::Noop.provides :apt_repository
|
||||
end
|
||||
end
|
||||
end
|
@ -1,105 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/provider/apt_update'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Thom May (<thom@chef.io>)
|
||||
# Copyright:: Copyright (c) 2016 Chef Software, 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 "chef_compat/copied_from_chef/chef/provider"
|
||||
require "chef_compat/copied_from_chef/chef/provider/noop"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object)
|
||||
class AptUpdate < (defined?(::Chef::Provider::AptUpdate) ? ::Chef::Provider::AptUpdate : Chef::Provider)
|
||||
use_inline_resources
|
||||
|
||||
extend Chef::Mixin::Which
|
||||
|
||||
provides :apt_update do
|
||||
which("apt-get")
|
||||
end
|
||||
|
||||
APT_CONF_DIR = "/etc/apt/apt.conf.d"
|
||||
STAMP_DIR = "/var/lib/apt/periodic"
|
||||
|
||||
def whyrun_supported?
|
||||
true
|
||||
end
|
||||
|
||||
def load_current_resource
|
||||
end
|
||||
|
||||
action :periodic do
|
||||
if !apt_up_to_date?
|
||||
converge_by "update new lists of packages" do
|
||||
do_update
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :update do
|
||||
converge_by "force update new lists of packages" do
|
||||
do_update
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Determines whether we need to run `apt-get update`
|
||||
#
|
||||
# @return [Boolean]
|
||||
def apt_up_to_date?
|
||||
::File.exist?("#{STAMP_DIR}/update-success-stamp") &&
|
||||
::File.mtime("#{STAMP_DIR}/update-success-stamp") > Time.now - new_resource.frequency
|
||||
end
|
||||
|
||||
def do_update
|
||||
[STAMP_DIR, APT_CONF_DIR].each do |d|
|
||||
declare_resource(:directory, d) do
|
||||
recursive true
|
||||
end
|
||||
end
|
||||
|
||||
declare_resource(:file, "#{APT_CONF_DIR}/15update-stamp") do
|
||||
content "APT::Update::Post-Invoke-Success {\"touch #{STAMP_DIR}/update-success-stamp 2>/dev/null || true\";};\n"
|
||||
action :create_if_missing
|
||||
end
|
||||
|
||||
declare_resource(:execute, "apt-get -q update")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Chef::Provider::Noop.provides :apt_update
|
||||
end
|
||||
end
|
||||
end
|
@ -1,56 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/provider/noop'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Thom May (<thom@chef.io>)
|
||||
# Copyright:: Copyright (c) 2016 Chef Software, 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.
|
||||
#
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object)
|
||||
class Noop < (defined?(::Chef::Provider::Noop) ? ::Chef::Provider::Noop : Chef::Provider)
|
||||
def load_current_resource; end
|
||||
|
||||
def respond_to_missing?(method_sym, include_private = false)
|
||||
method_sym.to_s.start_with?("action_") || super
|
||||
end
|
||||
|
||||
def method_missing(method_sym, *arguments, &block)
|
||||
if method_sym.to_s =~ /^action_/
|
||||
Chef::Log.debug("NoOp-ing for #{method_sym}")
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,253 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/provider/systemd_unit'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Nathan Williams (<nath.e.will@gmail.com>)
|
||||
# Copyright:: Copyright 2016, Nathan Williams
|
||||
# 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 "chef_compat/copied_from_chef/chef/provider"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object)
|
||||
class SystemdUnit < (defined?(::Chef::Provider::SystemdUnit) ? ::Chef::Provider::SystemdUnit : Chef::Provider)
|
||||
include Chef::Mixin::Which
|
||||
include Chef::Mixin::ShellOut
|
||||
|
||||
provides :systemd_unit, os: "linux"
|
||||
|
||||
def load_current_resource
|
||||
@current_resource = Chef::Resource::SystemdUnit.new(new_resource.name)
|
||||
|
||||
current_resource.content(::File.read(unit_path)) if ::File.exist?(unit_path)
|
||||
current_resource.user(new_resource.user)
|
||||
current_resource.enabled(enabled?)
|
||||
current_resource.active(active?)
|
||||
current_resource.masked(masked?)
|
||||
current_resource.static(static?)
|
||||
current_resource.triggers_reload(new_resource.triggers_reload)
|
||||
|
||||
current_resource
|
||||
end
|
||||
|
||||
def define_resource_requirements
|
||||
super
|
||||
|
||||
requirements.assert(:create) do |a|
|
||||
a.assertion { IniParse.parse(new_resource.to_ini) }
|
||||
a.failure_message "Unit content is not valid INI text"
|
||||
end
|
||||
end
|
||||
|
||||
def action_create
|
||||
if current_resource.content != new_resource.to_ini
|
||||
converge_by("creating unit: #{new_resource.name}") do
|
||||
manage_unit_file(:create)
|
||||
daemon_reload if new_resource.triggers_reload
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_delete
|
||||
if ::File.exist?(unit_path)
|
||||
converge_by("deleting unit: #{new_resource.name}") do
|
||||
manage_unit_file(:delete)
|
||||
daemon_reload if new_resource.triggers_reload
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_enable
|
||||
if current_resource.static
|
||||
Chef::Log.debug("#{new_resource.name} is a static unit, enabling is a NOP.")
|
||||
end
|
||||
|
||||
unless current_resource.enabled || current_resource.static
|
||||
converge_by("enabling unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:enable, new_resource.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_disable
|
||||
if current_resource.static
|
||||
Chef::Log.debug("#{new_resource.name} is a static unit, disabling is a NOP.")
|
||||
end
|
||||
|
||||
if current_resource.enabled && !current_resource.static
|
||||
converge_by("disabling unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:disable, new_resource.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_mask
|
||||
unless current_resource.masked
|
||||
converge_by("masking unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:mask, new_resource.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_unmask
|
||||
if current_resource.masked
|
||||
converge_by("unmasking unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:unmask, new_resource.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_start
|
||||
unless current_resource.active
|
||||
converge_by("starting unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:start, new_resource.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_stop
|
||||
if current_resource.active
|
||||
converge_by("stopping unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:stop, new_resource.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_restart
|
||||
converge_by("restarting unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:restart, new_resource.name)
|
||||
end
|
||||
end
|
||||
|
||||
def action_reload
|
||||
if current_resource.active
|
||||
converge_by("reloading unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:reload, new_resource.name)
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource.name} is not active, skipping reload.")
|
||||
end
|
||||
end
|
||||
|
||||
def action_try_restart
|
||||
converge_by("try-restarting unit: #{new_resource.name}") do
|
||||
systemctl_execute!("try-restart", new_resource.name)
|
||||
end
|
||||
end
|
||||
|
||||
def action_reload_or_restart
|
||||
converge_by("reload-or-restarting unit: #{new_resource.name}") do
|
||||
systemctl_execute!("reload-or-restart", new_resource.name)
|
||||
end
|
||||
end
|
||||
|
||||
def action_reload_or_try_restart
|
||||
converge_by("reload-or-try-restarting unit: #{new_resource.name}") do
|
||||
systemctl_execute!("reload-or-try-restart", new_resource.name)
|
||||
end
|
||||
end
|
||||
|
||||
def active?
|
||||
systemctl_execute("is-active", new_resource.name).exitstatus == 0
|
||||
end
|
||||
|
||||
def enabled?
|
||||
systemctl_execute("is-enabled", new_resource.name).exitstatus == 0
|
||||
end
|
||||
|
||||
def masked?
|
||||
systemctl_execute(:status, new_resource.name).stdout.include?("masked")
|
||||
end
|
||||
|
||||
def static?
|
||||
systemctl_execute("is-enabled", new_resource.name).stdout.include?("static")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def unit_path
|
||||
if new_resource.user
|
||||
"/etc/systemd/user/#{new_resource.name}"
|
||||
else
|
||||
"/etc/systemd/system/#{new_resource.name}"
|
||||
end
|
||||
end
|
||||
|
||||
def manage_unit_file(action = :nothing)
|
||||
Chef::Resource::File.new(unit_path, run_context).tap do |f|
|
||||
f.owner "root"
|
||||
f.group "root"
|
||||
f.mode "0644"
|
||||
f.content new_resource.to_ini
|
||||
end.run_action(action)
|
||||
end
|
||||
|
||||
def daemon_reload
|
||||
shell_out_with_systems_locale!("#{systemctl_path} daemon-reload")
|
||||
end
|
||||
|
||||
def systemctl_execute!(action, unit)
|
||||
shell_out_with_systems_locale!("#{systemctl_cmd} #{action} #{unit}", systemctl_opts)
|
||||
end
|
||||
|
||||
def systemctl_execute(action, unit)
|
||||
shell_out("#{systemctl_cmd} #{action} #{unit}", systemctl_opts)
|
||||
end
|
||||
|
||||
def systemctl_cmd
|
||||
@systemctl_cmd ||= "#{systemctl_path} #{systemctl_args}"
|
||||
end
|
||||
|
||||
def systemctl_path
|
||||
@systemctl_path ||= which("systemctl")
|
||||
end
|
||||
|
||||
def systemctl_args
|
||||
@systemctl_args ||= new_resource.user ? "--user" : "--system"
|
||||
end
|
||||
|
||||
def systemctl_opts
|
||||
@systemctl_opts ||=
|
||||
if new_resource.user
|
||||
{
|
||||
:user => new_resource.user,
|
||||
:environment => {
|
||||
"DBUS_SESSION_BUS_ADDRESS" => "unix:path=/run/user/#{node['etc']['passwd'][new_resource.user]['uid']}/bus",
|
||||
},
|
||||
}
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,137 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/provider/yum_repository'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Thom May (<thom@chef.io>)
|
||||
# Copyright:: Copyright (c) 2016 Chef Software, 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 "chef_compat/copied_from_chef/chef/resource"
|
||||
require "chef_compat/copied_from_chef/chef/dsl/declare_resource"
|
||||
require "chef_compat/copied_from_chef/chef/provider/noop"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object)
|
||||
class YumRepository < (defined?(::Chef::Provider::YumRepository) ? ::Chef::Provider::YumRepository : Chef::Provider)
|
||||
use_inline_resources
|
||||
|
||||
extend Chef::Mixin::Which
|
||||
|
||||
provides :yum_repository do
|
||||
which "yum"
|
||||
end
|
||||
|
||||
def whyrun_supported?; true; end
|
||||
|
||||
def load_current_resource; end
|
||||
|
||||
action :create do
|
||||
declare_resource(:template, "/etc/yum.repos.d/#{new_resource.repositoryid}.repo") do
|
||||
if template_available?(new_resource.source)
|
||||
source new_resource.source
|
||||
else
|
||||
source ::File.expand_path("../support/yum_repo.erb", __FILE__)
|
||||
local true
|
||||
end
|
||||
sensitive new_resource.sensitive
|
||||
variables(config: new_resource)
|
||||
mode new_resource.mode
|
||||
if new_resource.make_cache
|
||||
notifies :run, "execute[yum clean metadata #{new_resource.repositoryid}]", :immediately if new_resource.clean_metadata || new_resource.clean_headers
|
||||
notifies :run, "execute[yum-makecache-#{new_resource.repositoryid}]", :immediately
|
||||
notifies :create, "ruby_block[yum-cache-reload-#{new_resource.repositoryid}]", :immediately
|
||||
end
|
||||
end
|
||||
|
||||
declare_resource(:execute, "yum clean metadata #{new_resource.repositoryid}") do
|
||||
command "yum clean metadata --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
|
||||
action :nothing
|
||||
end
|
||||
|
||||
# get the metadata for this repo only
|
||||
declare_resource(:execute, "yum-makecache-#{new_resource.repositoryid}") do
|
||||
command "yum -q -y makecache --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
|
||||
action :nothing
|
||||
only_if { new_resource.enabled }
|
||||
end
|
||||
|
||||
# reload internal Chef yum cache
|
||||
declare_resource(:ruby_block, "yum-cache-reload-#{new_resource.repositoryid}") do
|
||||
block { Chef::Provider::Package::Yum::YumCache.instance.reload }
|
||||
action :nothing
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
declare_resource(:file, "/etc/yum.repos.d/#{new_resource.repositoryid}.repo") do
|
||||
action :delete
|
||||
notifies :run, "execute[yum clean all #{new_resource.repositoryid}]", :immediately
|
||||
notifies :create, "ruby_block[yum-cache-reload-#{new_resource.repositoryid}]", :immediately
|
||||
end
|
||||
|
||||
declare_resource(:execute, "yum clean all #{new_resource.repositoryid}") do
|
||||
command "yum clean all --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
|
||||
only_if "yum repolist | grep -P '^#{new_resource.repositoryid}([ \t]|$)'"
|
||||
action :nothing
|
||||
end
|
||||
|
||||
declare_resource(:ruby_block, "yum-cache-reload-#{new_resource.repositoryid}") do
|
||||
block { Chef::Provider::Package::Yum::YumCache.instance.reload }
|
||||
action :nothing
|
||||
end
|
||||
end
|
||||
|
||||
action :makecache do
|
||||
declare_resource(:execute, "yum-makecache-#{new_resource.repositoryid}") do
|
||||
command "yum -q -y makecache --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
|
||||
action :run
|
||||
only_if { new_resource.enabled }
|
||||
end
|
||||
|
||||
declare_resource(:ruby_block, "yum-cache-reload-#{new_resource.repositoryid}") do
|
||||
block { Chef::Provider::Package::Yum::YumCache.instance.reload }
|
||||
action :run
|
||||
end
|
||||
end
|
||||
|
||||
alias_method :action_add, :action_create
|
||||
alias_method :action_remove, :action_delete
|
||||
|
||||
def template_available?(path)
|
||||
!path.nil? && run_context.has_template_in_cookbook?(new_resource.cookbook_name, path)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Chef::Provider::Noop.provides :yum_repository
|
||||
end
|
||||
end
|
||||
end
|
@ -1,214 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/resource'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
require "chef_compat/copied_from_chef/chef/resource/action_class"
|
||||
require "chef_compat/copied_from_chef/chef/provider"
|
||||
require "chef_compat/copied_from_chef/chef/mixin/properties"
|
||||
require "chef_compat/copied_from_chef/chef/dsl/universal"
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object)
|
||||
include Chef::Mixin::Properties
|
||||
property :name, String, coerce: proc { |v| v.is_a?(Array) ? v.join(", ") : v.to_s }, desired_state: false
|
||||
def initialize(name, run_context = nil)
|
||||
super if defined?(::Chef::Resource)
|
||||
name(name) unless name.nil?
|
||||
@run_context = run_context
|
||||
@noop = nil
|
||||
@before = nil
|
||||
@params = Hash.new
|
||||
@provider = nil
|
||||
@allowed_actions = self.class.allowed_actions.to_a
|
||||
@action = self.class.default_action
|
||||
@updated = false
|
||||
@updated_by_last_action = false
|
||||
@supports = {}
|
||||
@ignore_failure = false
|
||||
@retries = 0
|
||||
@retry_delay = 2
|
||||
@not_if = []
|
||||
@only_if = []
|
||||
@source_line = nil
|
||||
# We would like to raise an error when the user gives us a guard
|
||||
# interpreter and a ruby_block to the guard. In order to achieve this
|
||||
# we need to understand when the user overrides the default guard
|
||||
# interpreter. Therefore we store the default separately in a different
|
||||
# attribute.
|
||||
@guard_interpreter = nil
|
||||
@default_guard_interpreter = :default
|
||||
@elapsed_time = 0
|
||||
@sensitive = false
|
||||
end
|
||||
def action(arg = nil)
|
||||
if arg
|
||||
arg = Array(arg).map(&:to_sym)
|
||||
arg.each do |action|
|
||||
validate(
|
||||
{ action: action },
|
||||
{ action: { kind_of: Symbol, equal_to: allowed_actions } }
|
||||
)
|
||||
end
|
||||
@action = arg
|
||||
else
|
||||
@action
|
||||
end
|
||||
end
|
||||
alias_method :action=, :action
|
||||
class UnresolvedSubscribes < (defined?(::Chef::Resource::UnresolvedSubscribes) ? ::Chef::Resource::UnresolvedSubscribes : self)
|
||||
alias_method :to_s, :name
|
||||
alias_method :declared_key, :name
|
||||
end
|
||||
def state_for_resource_reporter
|
||||
state = {}
|
||||
state_properties = self.class.state_properties
|
||||
state_properties.each do |property|
|
||||
if property.identity? || property.is_set?(self)
|
||||
state[property.name] = property.sensitive? ? "*sensitive value suppressed*" : send(property.name)
|
||||
end
|
||||
end
|
||||
state
|
||||
end
|
||||
alias_method :state, :state_for_resource_reporter
|
||||
def identity
|
||||
result = {}
|
||||
identity_properties = self.class.identity_properties
|
||||
identity_properties.each do |property|
|
||||
result[property.name] = send(property.name)
|
||||
end
|
||||
return result.values.first if identity_properties.size == 1
|
||||
result
|
||||
end
|
||||
attr_reader :resource_initializing
|
||||
def resource_initializing=(value)
|
||||
if value
|
||||
@resource_initializing = true
|
||||
else
|
||||
remove_instance_variable(:@resource_initializing)
|
||||
end
|
||||
end
|
||||
def to_hash
|
||||
# Grab all current state, then any other ivars (backcompat)
|
||||
result = {}
|
||||
self.class.state_properties.each do |p|
|
||||
result[p.name] = p.get(self)
|
||||
end
|
||||
safe_ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS
|
||||
safe_ivars.each do |iv|
|
||||
key = iv.to_s.sub(/^@/, "").to_sym
|
||||
next if result.has_key?(key)
|
||||
result[key] = instance_variable_get(iv)
|
||||
end
|
||||
result
|
||||
end
|
||||
def self.identity_property(name = nil)
|
||||
result = identity_properties(*Array(name))
|
||||
if result.size > 1
|
||||
raise Chef::Exceptions::MultipleIdentityError, "identity_property cannot be called on an object with more than one identity property (#{result.map { |r| r.name }.join(", ")})."
|
||||
end
|
||||
result.first
|
||||
end
|
||||
attr_accessor :allowed_actions
|
||||
def allowed_actions(value = NOT_PASSED)
|
||||
if value != NOT_PASSED
|
||||
self.allowed_actions = value
|
||||
end
|
||||
@allowed_actions
|
||||
end
|
||||
def resource_name
|
||||
@resource_name || self.class.resource_name
|
||||
end
|
||||
def self.use_automatic_resource_name
|
||||
automatic_name = convert_to_snake_case(self.name.split("::")[-1])
|
||||
resource_name automatic_name
|
||||
end
|
||||
def self.allowed_actions(*actions)
|
||||
@allowed_actions ||=
|
||||
if superclass.respond_to?(:allowed_actions)
|
||||
superclass.allowed_actions.dup
|
||||
else
|
||||
[ :nothing ]
|
||||
end
|
||||
@allowed_actions |= actions.flatten
|
||||
end
|
||||
def self.allowed_actions=(value)
|
||||
@allowed_actions = value.uniq
|
||||
end
|
||||
def self.default_action(action_name = NOT_PASSED)
|
||||
unless action_name.equal?(NOT_PASSED)
|
||||
@default_action = Array(action_name).map(&:to_sym)
|
||||
self.allowed_actions |= @default_action
|
||||
end
|
||||
|
||||
if @default_action
|
||||
@default_action
|
||||
elsif superclass.respond_to?(:default_action)
|
||||
superclass.default_action
|
||||
else
|
||||
[:nothing]
|
||||
end
|
||||
end
|
||||
def self.default_action=(action_name)
|
||||
default_action action_name
|
||||
end
|
||||
def self.action(action, &recipe_block)
|
||||
action = action.to_sym
|
||||
declare_action_class
|
||||
action_class.action(action, &recipe_block)
|
||||
self.allowed_actions += [ action ]
|
||||
default_action action if Array(default_action) == [:nothing]
|
||||
end
|
||||
def self.load_current_value(&load_block)
|
||||
define_method(:load_current_value!, &load_block)
|
||||
end
|
||||
def current_value_does_not_exist!
|
||||
raise Chef::Exceptions::CurrentValueDoesNotExist
|
||||
end
|
||||
def self.action_class(&block)
|
||||
return @action_class if @action_class && !block
|
||||
# If the superclass needed one, then we need one as well.
|
||||
if block || (superclass.respond_to?(:action_class) && superclass.action_class)
|
||||
@action_class = declare_action_class(&block)
|
||||
end
|
||||
@action_class
|
||||
end
|
||||
def self.declare_action_class(&block)
|
||||
@action_class ||= begin
|
||||
if superclass.respond_to?(:action_class)
|
||||
base_provider = superclass.action_class
|
||||
end
|
||||
base_provider ||= Chef::Provider
|
||||
|
||||
resource_class = self
|
||||
Class.new(base_provider) do
|
||||
include ActionClass
|
||||
self.resource_class = resource_class
|
||||
end
|
||||
end
|
||||
@action_class.class_eval(&block) if block
|
||||
@action_class
|
||||
end
|
||||
FORBIDDEN_IVARS = [:@run_context, :@not_if, :@only_if, :@enclosing_provider]
|
||||
HIDDEN_IVARS = [:@allowed_actions, :@resource_name, :@source_line, :@run_context, :@name, :@not_if, :@only_if, :@elapsed_time, :@enclosing_provider]
|
||||
class << self
|
||||
end
|
||||
@@sorted_descendants = nil
|
||||
module DeprecatedLWRPClass
|
||||
CopiedFromChef.extend_chef_module(::Chef::Resource::DeprecatedLWRPClass, self) if defined?(::Chef::Resource::DeprecatedLWRPClass)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,114 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/resource/action_class'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: John Keiser (<jkeiser@chef.io)
|
||||
# Copyright:: Copyright 2015-2016, Chef Software 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 "chef_compat/copied_from_chef/chef/dsl/recipe"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object)
|
||||
module ActionClass
|
||||
CopiedFromChef.extend_chef_module(::Chef::Resource::ActionClass, self) if defined?(::Chef::Resource::ActionClass)
|
||||
include Chef::DSL::Recipe
|
||||
|
||||
def to_s
|
||||
"#{new_resource || "<no resource>"} action #{action ? action.inspect : "<no action>"}"
|
||||
end
|
||||
|
||||
def whyrun_supported?
|
||||
true
|
||||
end
|
||||
|
||||
#
|
||||
# If load_current_value! is defined on the resource, use that.
|
||||
#
|
||||
def load_current_resource
|
||||
if new_resource.respond_to?(:load_current_value!)
|
||||
# dup the resource and then reset desired-state properties.
|
||||
current_resource = new_resource.dup
|
||||
|
||||
# We clear desired state in the copy, because it is supposed to be actual state.
|
||||
# We keep identity properties and non-desired-state, which are assumed to be
|
||||
# "control" values like `recurse: true`
|
||||
current_resource.class.properties.each do |name, property|
|
||||
if property.desired_state? && !property.identity? && !property.name_property?
|
||||
property.reset(current_resource)
|
||||
end
|
||||
end
|
||||
|
||||
# Call the actual load_current_value! method. If it raises
|
||||
# CurrentValueDoesNotExist, set current_resource to `nil`.
|
||||
begin
|
||||
# If the user specifies load_current_value do |desired_resource|, we
|
||||
# pass in the desired resource as well as the current one.
|
||||
if current_resource.method(:load_current_value!).arity > 0
|
||||
current_resource.load_current_value!(new_resource)
|
||||
else
|
||||
current_resource.load_current_value!
|
||||
end
|
||||
rescue Chef::Exceptions::CurrentValueDoesNotExist
|
||||
current_resource = nil
|
||||
end
|
||||
end
|
||||
|
||||
@current_resource = current_resource
|
||||
end
|
||||
|
||||
def self.included(other)
|
||||
other.extend(ClassMethods)
|
||||
other.use_inline_resources
|
||||
other.include_resource_dsl true
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
CopiedFromChef.extend_chef_module(::Chef::Resource::ActionClass::ClassMethods, self) if defined?(::Chef::Resource::ActionClass::ClassMethods)
|
||||
#
|
||||
# The Chef::Resource class this ActionClass was declared against.
|
||||
#
|
||||
# @return [Class] The Chef::Resource class this ActionClass was declared against.
|
||||
#
|
||||
attr_accessor :resource_class
|
||||
|
||||
def to_s
|
||||
"#{resource_class} action provider"
|
||||
end
|
||||
|
||||
def inspect
|
||||
to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,66 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/resource/apt_repository'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Thom May (<thom@chef.io>)
|
||||
# Copyright:: Copyright (c) 2016 Chef Software, 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 "chef_compat/copied_from_chef/chef/resource"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object)
|
||||
class AptRepository < (defined?(::Chef::Resource::AptRepository) ? ::Chef::Resource::AptRepository : Chef::Resource)
|
||||
resource_name :apt_repository
|
||||
provides :apt_repository
|
||||
|
||||
property :repo_name, String, name_property: true
|
||||
property :uri, String
|
||||
property :distribution, [ String, nil, false ], default: lazy { node["lsb"]["codename"] }, nillable: true, coerce: proc { |x| x ? x : nil }
|
||||
property :components, Array, default: []
|
||||
property :arch, [String, nil, false], default: nil, nillable: true, coerce: proc { |x| x ? x : nil }
|
||||
property :trusted, [TrueClass, FalseClass], default: false
|
||||
# whether or not to add the repository as a source repo, too
|
||||
property :deb_src, [TrueClass, FalseClass], default: false
|
||||
property :keyserver, [String, nil, false], default: "keyserver.ubuntu.com", nillable: true, coerce: proc { |x| x ? x : nil }
|
||||
property :key, [String, nil, false], default: nil, nillable: true, coerce: proc { |x| x ? x : nil }
|
||||
property :key_proxy, [String, nil, false], default: nil, nillable: true, coerce: proc { |x| x ? x : nil }
|
||||
|
||||
property :cookbook, [String, nil, false], default: nil, desired_state: false, nillable: true, coerce: proc { |x| x ? x : nil }
|
||||
property :cache_rebuild, [TrueClass, FalseClass], default: true, desired_state: false
|
||||
property :sensitive, [TrueClass, FalseClass], default: false, desired_state: false
|
||||
|
||||
default_action :add
|
||||
allowed_actions :add, :remove
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,52 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/resource/apt_update'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Thom May (<thom@chef.io>)
|
||||
# Copyright:: Copyright (c) 2016 Chef Software, 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 "chef_compat/copied_from_chef/chef/resource"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object)
|
||||
class AptUpdate < (defined?(::Chef::Resource::AptUpdate) ? ::Chef::Resource::AptUpdate : Chef::Resource)
|
||||
resource_name :apt_update
|
||||
provides :apt_update, os: "linux"
|
||||
|
||||
property :frequency, Integer, default: 86_400
|
||||
|
||||
default_action :periodic
|
||||
allowed_actions :update, :periodic
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,81 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/resource/systemd_unit'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Nathan Williams (<nath.e.will@gmail.com>)
|
||||
# Copyright:: Copyright 2016, Nathan Williams
|
||||
# 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 "chef_compat/copied_from_chef/chef/resource"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object)
|
||||
class SystemdUnit < (defined?(::Chef::Resource::SystemdUnit) ? ::Chef::Resource::SystemdUnit : Chef::Resource)
|
||||
resource_name :systemd_unit
|
||||
|
||||
default_action :nothing
|
||||
allowed_actions :create, :delete,
|
||||
:enable, :disable,
|
||||
:mask, :unmask,
|
||||
:start, :stop,
|
||||
:restart, :reload,
|
||||
:try_restart, :reload_or_restart,
|
||||
:reload_or_try_restart
|
||||
|
||||
property :enabled, [TrueClass, FalseClass]
|
||||
property :active, [TrueClass, FalseClass]
|
||||
property :masked, [TrueClass, FalseClass]
|
||||
property :static, [TrueClass, FalseClass]
|
||||
property :user, String, desired_state: false
|
||||
property :content, [String, Hash]
|
||||
property :triggers_reload, [TrueClass, FalseClass],
|
||||
default: true, desired_state: false
|
||||
|
||||
def to_ini
|
||||
case content
|
||||
when Hash
|
||||
IniParse.gen do |doc|
|
||||
content.each_pair do |sect, opts|
|
||||
doc.section(sect) do |section|
|
||||
opts.each_pair do |opt, val|
|
||||
section.option(opt, val)
|
||||
end
|
||||
end
|
||||
end
|
||||
end.to_s
|
||||
else
|
||||
content.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,98 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/resource/yum_repository'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Thom May (<thom@chef.io>)
|
||||
# Copyright:: Copyright (c) 2016 Chef Software, 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 "chef_compat/copied_from_chef/chef/resource"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object)
|
||||
class YumRepository < (defined?(::Chef::Resource::YumRepository) ? ::Chef::Resource::YumRepository : Chef::Resource)
|
||||
resource_name :yum_repository
|
||||
provides :yum_repository
|
||||
|
||||
# http://linux.die.net/man/5/yum.conf
|
||||
property :baseurl, String, regex: /.*/
|
||||
property :cost, String, regex: /^\d+$/
|
||||
property :clean_headers, [TrueClass, FalseClass], default: false # deprecated
|
||||
property :clean_metadata, [TrueClass, FalseClass], default: true
|
||||
property :description, String, regex: /.*/, default: "Yum Repository"
|
||||
property :enabled, [TrueClass, FalseClass], default: true
|
||||
property :enablegroups, [TrueClass, FalseClass]
|
||||
property :exclude, String, regex: /.*/
|
||||
property :failovermethod, String, equal_to: %w{priority roundrobin}
|
||||
property :fastestmirror_enabled, [TrueClass, FalseClass]
|
||||
property :gpgcheck, [TrueClass, FalseClass], default: true
|
||||
property :gpgkey, [String, Array], regex: /.*/
|
||||
property :http_caching, String, equal_to: %w{packages all none}
|
||||
property :include_config, String, regex: /.*/
|
||||
property :includepkgs, String, regex: /.*/
|
||||
property :keepalive, [TrueClass, FalseClass]
|
||||
property :make_cache, [TrueClass, FalseClass], default: true
|
||||
property :max_retries, [String, Integer]
|
||||
property :metadata_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/, /never/]
|
||||
property :mirrorexpire, String, regex: /.*/
|
||||
property :mirrorlist, String, regex: /.*/
|
||||
property :mirror_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/]
|
||||
property :mirrorlist_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/]
|
||||
property :mode, default: "0644"
|
||||
property :priority, String, regex: /^(\d?[0-9]|[0-9][0-9])$/
|
||||
property :proxy, String, regex: /.*/
|
||||
property :proxy_username, String, regex: /.*/
|
||||
property :proxy_password, String, regex: /.*/
|
||||
property :username, String, regex: /.*/
|
||||
property :password, String, regex: /.*/
|
||||
property :repo_gpgcheck, [TrueClass, FalseClass]
|
||||
property :report_instanceid, [TrueClass, FalseClass]
|
||||
property :repositoryid, String, regex: /.*/, name_property: true
|
||||
property :sensitive, [TrueClass, FalseClass], default: false
|
||||
property :skip_if_unavailable, [TrueClass, FalseClass]
|
||||
property :source, String, regex: /.*/
|
||||
property :sslcacert, String, regex: /.*/
|
||||
property :sslclientcert, String, regex: /.*/
|
||||
property :sslclientkey, String, regex: /.*/
|
||||
property :sslverify, [TrueClass, FalseClass]
|
||||
property :timeout, String, regex: /^\d+$/
|
||||
property :options, Hash
|
||||
|
||||
default_action :create
|
||||
allowed_actions :create, :remove, :makecache, :add, :delete
|
||||
|
||||
# provide compatibility with the yum cookbook < 3.0 properties
|
||||
alias_method :url, :baseurl
|
||||
alias_method :keyurl, :gpgkey
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,174 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/resource_builder'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Lamont Granquist (<lamont@chef.io>)
|
||||
# Copyright:: Copyright 2015-2016, Chef Software, 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.
|
||||
#
|
||||
|
||||
# NOTE: this was extracted from the Recipe DSL mixin, relevant specs are in spec/unit/recipe_spec.rb
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class ResourceBuilder < (defined?(::Chef::ResourceBuilder) ? ::Chef::ResourceBuilder : Object)
|
||||
attr_reader :type
|
||||
attr_reader :name
|
||||
attr_reader :created_at
|
||||
attr_reader :params
|
||||
attr_reader :run_context
|
||||
attr_reader :cookbook_name
|
||||
attr_reader :recipe_name
|
||||
attr_reader :enclosing_provider
|
||||
attr_reader :resource
|
||||
|
||||
# FIXME (ruby-2.1 syntax): most of these are mandatory
|
||||
def initialize(type: nil, name: nil, created_at: nil, params: nil, run_context: nil, cookbook_name: nil, recipe_name: nil, enclosing_provider: nil)
|
||||
super if defined?(::Chef::ResourceBuilder)
|
||||
@type = type
|
||||
@name = name
|
||||
@created_at = created_at
|
||||
@params = params
|
||||
@run_context = run_context
|
||||
@cookbook_name = cookbook_name
|
||||
@recipe_name = recipe_name
|
||||
@enclosing_provider = enclosing_provider
|
||||
end
|
||||
|
||||
def build(&block)
|
||||
raise ArgumentError, "You must supply a name when declaring a #{type} resource" if name.nil?
|
||||
|
||||
@resource = resource_class.new(name, run_context)
|
||||
if resource.resource_name.nil?
|
||||
raise Chef::Exceptions::InvalidResourceSpecification, "#{resource}.resource_name is `nil`! Did you forget to put `provides :blah` or `resource_name :blah` in your resource class?"
|
||||
end
|
||||
resource.source_line = created_at
|
||||
resource.declared_type = type
|
||||
|
||||
# If we have a resource like this one, we want to steal its state
|
||||
# This behavior is very counter-intuitive and should be removed.
|
||||
# See CHEF-3694, https://tickets.opscode.com/browse/CHEF-3694
|
||||
# Moved to this location to resolve CHEF-5052, https://tickets.opscode.com/browse/CHEF-5052
|
||||
if prior_resource
|
||||
resource.load_from(prior_resource)
|
||||
end
|
||||
|
||||
resource.cookbook_name = cookbook_name
|
||||
resource.recipe_name = recipe_name
|
||||
# Determine whether this resource is being created in the context of an enclosing Provider
|
||||
resource.enclosing_provider = enclosing_provider
|
||||
|
||||
# XXX: this is required for definition params inside of the scope of a
|
||||
# subresource to work correctly.
|
||||
resource.params = params
|
||||
|
||||
# Evaluate resource attribute DSL
|
||||
if block_given?
|
||||
resource.resource_initializing = true
|
||||
begin
|
||||
resource.instance_eval(&block)
|
||||
ensure
|
||||
resource.resource_initializing = false
|
||||
end
|
||||
end
|
||||
|
||||
# emit a cloned resource warning if it is warranted
|
||||
if prior_resource
|
||||
if is_trivial_resource?(prior_resource) && identicalish_resources?(prior_resource, resource)
|
||||
emit_harmless_cloning_debug
|
||||
else
|
||||
emit_cloned_resource_warning
|
||||
end
|
||||
end
|
||||
|
||||
# Run optional resource hook
|
||||
resource.after_created
|
||||
|
||||
resource
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def resource_class
|
||||
# Checks the new platform => short_name => resource mapping initially
|
||||
# then fall back to the older approach (Chef::Resource.const_get) for
|
||||
# backward compatibility
|
||||
@resource_class ||= Chef::Resource.resource_for_node(type, run_context.node)
|
||||
end
|
||||
|
||||
def is_trivial_resource?(resource)
|
||||
trivial_resource = resource_class.new(name, run_context)
|
||||
# force un-lazy the name property on the created trivial resource
|
||||
name_property = resource_class.properties.find { |sym, p| p.name_property? }
|
||||
trivial_resource.send(name_property[0]) unless name_property.nil?
|
||||
identicalish_resources?(trivial_resource, resource)
|
||||
end
|
||||
|
||||
# this is an equality test specific to checking for 3694 cloning warnings
|
||||
def identicalish_resources?(first, second)
|
||||
skipped_ivars = [ :@source_line, :@cookbook_name, :@recipe_name, :@params, :@elapsed_time, :@declared_type ]
|
||||
checked_ivars = ( first.instance_variables | second.instance_variables ) - skipped_ivars
|
||||
non_matching_ivars = checked_ivars.reject do |iv|
|
||||
if iv == :@action && ( [first.instance_variable_get(iv)].flatten == [:nothing] || [second.instance_variable_get(iv)].flatten == [:nothing] )
|
||||
# :nothing action on either side of the comparison always matches
|
||||
true
|
||||
else
|
||||
first.instance_variable_get(iv) == second.instance_variable_get(iv)
|
||||
end
|
||||
end
|
||||
Chef::Log.debug("ivars which did not match with the prior resource: #{non_matching_ivars}")
|
||||
non_matching_ivars.empty?
|
||||
end
|
||||
|
||||
def emit_cloned_resource_warning
|
||||
message = "Cloning resource attributes for #{resource} from prior resource (CHEF-3694)"
|
||||
message << "\nPrevious #{prior_resource}: #{prior_resource.source_line}" if prior_resource.source_line
|
||||
message << "\nCurrent #{resource}: #{resource.source_line}" if resource.source_line
|
||||
Chef.log_deprecation(message)
|
||||
end
|
||||
|
||||
def emit_harmless_cloning_debug
|
||||
Chef::Log.debug("Harmless resource cloning from #{prior_resource}:#{prior_resource.source_line} to #{resource}:#{resource.source_line}")
|
||||
end
|
||||
|
||||
def prior_resource
|
||||
@prior_resource ||=
|
||||
begin
|
||||
key = "#{type}[#{name}]"
|
||||
run_context.resource_collection.lookup_local(key)
|
||||
rescue Chef::Exceptions::ResourceNotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
require "chef_compat/copied_from_chef/chef/resource"
|
||||
end
|
||||
end
|
||||
end
|
@ -1,8 +0,0 @@
|
||||
require 'chef_compat/monkeypatches'
|
||||
require 'chef_compat/copied_from_chef/chef/mixin/properties'
|
||||
|
||||
module ChefCompat
|
||||
module Mixin
|
||||
Properties = ChefCompat::CopiedFromChef::Chef::Mixin::Properties
|
||||
end
|
||||
end
|
@ -1,41 +0,0 @@
|
||||
class Chef
|
||||
class RunContext
|
||||
class ChildRunContext < RunContext
|
||||
# magic that lets us re-parse the ChildRunContext without erroring due to
|
||||
# cheffish and chef-provisioning hooks having been loaded (on old versions of
|
||||
# chef-client without the lazy hooks for those gems)
|
||||
@__skip_method_checking = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# fix to quiet constant redefined warnings
|
||||
if defined?(Chef::RunContext::ChildRunContext::CHILD_STATE)
|
||||
Chef::RunContext::ChildRunContext.send(:remove_const, :CHILD_STATE)
|
||||
end
|
||||
|
||||
require 'chef_compat/monkeypatches/chef'
|
||||
require 'chef_compat/monkeypatches/chef/exceptions'
|
||||
require 'chef_compat/monkeypatches/chef/log'
|
||||
require 'chef_compat/monkeypatches/chef/node'
|
||||
require 'chef_compat/monkeypatches/chef/mixin/params_validate'
|
||||
require 'chef_compat/monkeypatches/chef/property'
|
||||
require 'chef_compat/monkeypatches/chef/provider'
|
||||
require 'chef_compat/monkeypatches/chef/recipe' # copied from chef
|
||||
require 'chef_compat/monkeypatches/chef/recipe_hook'
|
||||
require 'chef_compat/monkeypatches/chef/resource'
|
||||
require 'chef_compat/monkeypatches/chef/resource_builder'
|
||||
require 'chef_compat/monkeypatches/chef/resource/lwrp_base'
|
||||
require 'chef_compat/monkeypatches/chef/resource_collection'
|
||||
require 'chef_compat/monkeypatches/chef/resource_collection/resource_list'
|
||||
require 'chef_compat/monkeypatches/chef/resource_collection/resource_set'
|
||||
require 'chef_compat/monkeypatches/chef/run_context' # copied from chef
|
||||
require 'chef_compat/monkeypatches/chef/runner' # copied from chef
|
||||
|
||||
# fix for Chef::RunContext instance that has already been created
|
||||
ObjectSpace.each_object(Chef::RunContext) do |run_context|
|
||||
run_context.node.run_context = run_context
|
||||
run_context.instance_variable_set(:@loaded_recipes_hash, {})
|
||||
run_context.instance_variable_set(:@loaded_attributes_hash, {})
|
||||
run_context.initialize_child_state
|
||||
end
|
@ -1,33 +0,0 @@
|
||||
class Chef
|
||||
NOT_PASSED = Object.new if !defined?(NOT_PASSED)
|
||||
# Earlier versions of Chef didn't have this message
|
||||
module ChefCompatDeprecation
|
||||
def log_deprecation(message, location=nil)
|
||||
if !location
|
||||
# Pick the first caller that is *not* part of the Chef or ChefCompat gem,
|
||||
# that's the thing the user wrote.
|
||||
chef_compat_gem_path = File.expand_path("../../..", __FILE__)
|
||||
chef_gem_path = File.expand_path("../..",::Chef::Resource.instance_method(:initialize).source_location[0])
|
||||
caller(0..10).each do |c|
|
||||
if !c.start_with?(chef_gem_path) && !c.start_with?(chef_compat_gem_path)
|
||||
location = c
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
super
|
||||
# Bleagh. `super_method` doesn't exist on older rubies and I haven't
|
||||
# figured out a way to check for its existence otherwise.
|
||||
rescue NoMethodError
|
||||
Chef::Log.warn(message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class<<self
|
||||
prepend ChefCompatDeprecation
|
||||
end
|
||||
|
||||
end
|
@ -1,10 +0,0 @@
|
||||
require 'chef/exceptions'
|
||||
|
||||
class Chef
|
||||
class Exceptions
|
||||
# Used in Resource::ActionClass#load_current_resource to denote that
|
||||
# the resource doesn't actually exist (for example, the file does not exist)
|
||||
class CurrentValueDoesNotExist < RuntimeError; end unless defined?(CurrentValueDoesNotExist)
|
||||
class CannotValidateStaticallyError < RuntimeError; end unless defined?(CannotValidateStaticallyError)
|
||||
end
|
||||
end
|
@ -1,30 +0,0 @@
|
||||
require 'chef/log'
|
||||
|
||||
# for now we have to patch this in everything
|
||||
class Chef
|
||||
class Log
|
||||
def self.caller_location
|
||||
# Pick the first caller that is *not* part of the Chef gem, that's the
|
||||
# thing the user wrote.
|
||||
compat_resource_path = File.expand_path("../../../../..", __FILE__)
|
||||
chef_gem_path = Gem.loaded_specs['chef'].full_gem_path
|
||||
caller(0..20).find { |c| !c.start_with?(compat_resource_path) && !c.start_with?(chef_gem_path) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if Gem::Requirement.new('< 12.13.37').satisfied_by?(Gem::Version.new(Chef::VERSION))
|
||||
|
||||
# FIXME: why does this not match the implementation in Chef itself?
|
||||
class Chef
|
||||
class Log
|
||||
module ChefCompatDeprecation
|
||||
def deprecation(message, location=nil)
|
||||
Chef.log_deprecation(message, location)
|
||||
end
|
||||
end
|
||||
extend ChefCompatDeprecation
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -1,17 +0,0 @@
|
||||
if Chef::VERSION.to_f >= 12.5 && Chef::VERSION.to_f <= 12.8
|
||||
require 'chef/mixin/params_validate'
|
||||
class Chef
|
||||
module Mixin
|
||||
module ParamsValidate
|
||||
class SetOrReturnProperty < Chef::Property
|
||||
# 12.9 introduced a new optional parameter to `get()` to avoid a nil-set warning.
|
||||
# When their method gets called with 2 args, we need to ignore and call with 1.
|
||||
alias_method :_original_get2, :get
|
||||
def get(resource, *args)
|
||||
_original_get2(resource)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,9 +0,0 @@
|
||||
class Chef
|
||||
class Node
|
||||
unless method_defined?(:set_cookbook_attribute)
|
||||
def set_cookbook_attribute
|
||||
# this implementation deliberately left blank - we don't need to do anything we just need to not fail
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,15 +0,0 @@
|
||||
# 12.9 introduced a new optional parameter to `get()` to avoid a nil-set warning.
|
||||
# We need to mimick it here.
|
||||
if Chef::VERSION.to_f >= 12.5 && Chef::VERSION.to_f <= 12.8
|
||||
require 'chef/property'
|
||||
class Chef
|
||||
class Property
|
||||
# 12.9 introduced a new optional parameter to `get()` to avoid a nil-set warning.
|
||||
# When their method gets called with 2 args, we need to ignore and call with 1.
|
||||
alias_method :_original_get, :get
|
||||
def get(resource, *args)
|
||||
_original_get(resource)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,65 +0,0 @@
|
||||
require 'chef/provider'
|
||||
require 'chef/provider/lwrp_base'
|
||||
|
||||
class Chef::Provider
|
||||
if !defined?(InlineResources)
|
||||
InlineResources = Chef::Provider::LWRPBase::InlineResources
|
||||
end
|
||||
module InlineResources
|
||||
require 'chef/dsl/recipe'
|
||||
require 'chef/dsl/platform_introspection'
|
||||
require 'chef/dsl/data_query'
|
||||
require 'chef/dsl/include_recipe'
|
||||
include Chef::DSL::Recipe
|
||||
include Chef::DSL::PlatformIntrospection
|
||||
include Chef::DSL::DataQuery
|
||||
include Chef::DSL::IncludeRecipe
|
||||
|
||||
unless Chef::Provider::InlineResources::ClassMethods.instance_method(:action).source_location[0] =~ /chefspec/
|
||||
# Don't override action if chefspec is doing its thing
|
||||
module ::ChefCompat
|
||||
module Monkeypatches
|
||||
module InlineResources
|
||||
module ClassMethods
|
||||
def action(name, &block)
|
||||
super(name) { send("compile_action_#{name}") }
|
||||
# We put the action in its own method so that super() works.
|
||||
define_method("compile_action_#{name}", &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
module ClassMethods
|
||||
prepend ChefCompat::Monkeypatches::InlineResources::ClassMethods
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class Chef
|
||||
class Provider
|
||||
class LWRPBase < Provider
|
||||
if defined?(InlineResources)
|
||||
module InlineResources
|
||||
# since we upgrade the Chef::Runner and Chef::RunContext globally to >= 12.14 style classes, we need to also
|
||||
# fix the use_inline_resources LWRPBase wrapper that creates a sub-resource collection with the ugpraded code
|
||||
# from the Chef::Provider subclasses that do similar things in post-12.5 chef.
|
||||
def recipe_eval_with_update_check(&block)
|
||||
old_run_context = run_context
|
||||
@run_context = run_context.create_child
|
||||
return_value = instance_eval(&block)
|
||||
Chef::Runner.new(run_context).converge
|
||||
return_value
|
||||
ensure
|
||||
if run_context.resource_collection.any? { |r| r.updated? }
|
||||
new_resource.updated_by_last_action(true)
|
||||
end
|
||||
@run_context = old_run_context
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,118 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
if Gem::Requirement.new('< 12.16.42').satisfied_by?(Gem::Version.new(Chef::VERSION))
|
||||
#--
|
||||
# Author:: Adam Jacob (<adam@chef.io>)
|
||||
# Author:: Christopher Walters (<cw@chef.io>)
|
||||
# Copyright:: Copyright 2008-2016, Chef Software 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 "chef/dsl/recipe"
|
||||
require "chef/mixin/from_file"
|
||||
require "chef/mixin/deprecation"
|
||||
|
||||
class Chef
|
||||
# == Chef::Recipe
|
||||
# A Recipe object is the context in which Chef recipes are evaluated.
|
||||
class Recipe
|
||||
attr_accessor :cookbook_name, :recipe_name, :recipe, :params, :run_context
|
||||
|
||||
include Chef::DSL::Recipe
|
||||
|
||||
include Chef::Mixin::FromFile
|
||||
include Chef::Mixin::Deprecation
|
||||
|
||||
# Parses a potentially fully-qualified recipe name into its
|
||||
# cookbook name and recipe short name.
|
||||
#
|
||||
# For example:
|
||||
# "aws::elastic_ip" returns [:aws, "elastic_ip"]
|
||||
# "aws" returns [:aws, "default"]
|
||||
# "::elastic_ip" returns [ current_cookbook, "elastic_ip" ]
|
||||
#--
|
||||
# TODO: Duplicates functionality of RunListItem
|
||||
def self.parse_recipe_name(recipe_name, current_cookbook: nil)
|
||||
case recipe_name
|
||||
when /(.+?)::(.+)/
|
||||
[ $1.to_sym, $2 ]
|
||||
when /^::(.+)/
|
||||
raise "current_cookbook is nil, cannot resolve #{recipe_name}" if current_cookbook.nil?
|
||||
[ current_cookbook.to_sym, $1 ]
|
||||
else
|
||||
[ recipe_name.to_sym, "default" ]
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(cookbook_name, recipe_name, run_context)
|
||||
@cookbook_name = cookbook_name
|
||||
@recipe_name = recipe_name
|
||||
@run_context = run_context
|
||||
# TODO: 5/19/2010 cw/tim: determine whether this can be removed
|
||||
@params = Hash.new
|
||||
end
|
||||
|
||||
# Used in DSL mixins
|
||||
def node
|
||||
run_context.node
|
||||
end
|
||||
|
||||
# Used by the DSL to look up resources when executing in the context of a
|
||||
# recipe.
|
||||
def resources(*args)
|
||||
run_context.resource_collection.find(*args)
|
||||
end
|
||||
|
||||
# This was moved to Chef::Node#tag, redirecting here for compatibility
|
||||
def tag(*tags)
|
||||
run_context.node.tag(*tags)
|
||||
end
|
||||
|
||||
# Returns true if the node is tagged with *all* of the supplied +tags+.
|
||||
#
|
||||
# === Parameters
|
||||
# tags<Array>:: A list of tags
|
||||
#
|
||||
# === Returns
|
||||
# true<TrueClass>:: If all the parameters are present
|
||||
# false<FalseClass>:: If any of the parameters are missing
|
||||
def tagged?(*tags)
|
||||
tags.each do |tag|
|
||||
return false unless run_context.node.tags.include?(tag)
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
# Removes the list of tags from the node.
|
||||
#
|
||||
# === Parameters
|
||||
# tags<Array>:: A list of tags
|
||||
#
|
||||
# === Returns
|
||||
# tags<Array>:: The current list of run_context.node.tags
|
||||
def untag(*tags)
|
||||
tags.each do |tag|
|
||||
run_context.node.tags.delete(tag)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,20 +0,0 @@
|
||||
require 'chef/recipe'
|
||||
require 'chef_compat/recipe'
|
||||
|
||||
class Chef::Recipe
|
||||
# If the cookbook depends on compat_resource, create a ChefCompat::Recipe object
|
||||
# instead of Chef::Recipe, for the extra goodies.
|
||||
def self.new(cookbook_name, recipe_name, run_context)
|
||||
if run_context &&
|
||||
cookbook_name &&
|
||||
recipe_name &&
|
||||
run_context.cookbook_collection &&
|
||||
run_context.cookbook_collection[cookbook_name] &&
|
||||
run_context.cookbook_collection[cookbook_name].metadata.dependencies.has_key?('compat_resource') &&
|
||||
self != ::ChefCompat::Recipe
|
||||
::ChefCompat::Recipe.new(cookbook_name, recipe_name, run_context)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
@ -1,156 +0,0 @@
|
||||
# this is NOT an AUTOGENERATED file
|
||||
|
||||
require 'chef/resource'
|
||||
|
||||
class Chef
|
||||
class Resource
|
||||
|
||||
class UnresolvedSubscribes < self
|
||||
# The full key ise given as the name in {Resource#subscribes}
|
||||
alias_method :to_s, :name
|
||||
alias_method :declared_key, :name
|
||||
end
|
||||
|
||||
#
|
||||
# Force a delayed notification into this resource's run_context.
|
||||
#
|
||||
# This should most likely be paired with action :nothing
|
||||
#
|
||||
# @param arg [Array[Symbol], Symbol] A list of actions (e.g. `:create`)
|
||||
#
|
||||
def delayed_action(arg)
|
||||
arg = Array(arg).map(&:to_sym)
|
||||
arg.map do |action|
|
||||
validate(
|
||||
{ action: action },
|
||||
{ action: { kind_of: Symbol, equal_to: allowed_actions } }
|
||||
)
|
||||
# the resource effectively sends a delayed notification to itself
|
||||
run_context.add_delayed_action(Notification.new(self, action, self))
|
||||
end
|
||||
end
|
||||
|
||||
def subscribes(action, resources, timing = :delayed)
|
||||
resources = [resources].flatten
|
||||
resources.each do |resource|
|
||||
if resource.is_a?(String)
|
||||
resource = UnresolvedSubscribes.new(resource, run_context)
|
||||
end
|
||||
if resource.run_context.nil?
|
||||
resource.run_context = run_context
|
||||
end
|
||||
resource.notifies(action, self, timing)
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def notifies(action, resource_spec, timing = :delayed)
|
||||
# when using old-style resources(:template => "/foo.txt") style, you
|
||||
# could end up with multiple resources.
|
||||
validate_resource_spec!(resource_spec)
|
||||
|
||||
resources = [ resource_spec ].flatten
|
||||
resources.each do |resource|
|
||||
|
||||
case timing.to_s
|
||||
when "delayed"
|
||||
notifies_delayed(action, resource)
|
||||
when "immediate", "immediately"
|
||||
notifies_immediately(action, resource)
|
||||
when "before"
|
||||
notifies_before(action, resource)
|
||||
else
|
||||
raise ArgumentError, "invalid timing: #{timing} for notifies(#{action}, #{resources.inspect}, #{timing}) resource #{self} "\
|
||||
"Valid timings are: :delayed, :immediate, :immediately, :before"
|
||||
end
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
#
|
||||
# Iterates over all immediate and delayed notifications, calling
|
||||
# resolve_resource_reference on each in turn, causing them to
|
||||
# resolve lazy/forward references.
|
||||
def resolve_notification_references
|
||||
run_context.before_notifications(self).each { |n|
|
||||
n.resolve_resource_reference(run_context.resource_collection)
|
||||
}
|
||||
run_context.immediate_notifications(self).each { |n|
|
||||
n.resolve_resource_reference(run_context.resource_collection)
|
||||
}
|
||||
run_context.delayed_notifications(self).each {|n|
|
||||
n.resolve_resource_reference(run_context.resource_collection)
|
||||
}
|
||||
end
|
||||
|
||||
# Helper for #notifies
|
||||
def notifies_before(action, resource_spec)
|
||||
run_context.notifies_before(Notification.new(resource_spec, action, self))
|
||||
end
|
||||
|
||||
# Helper for #notifies
|
||||
def notifies_immediately(action, resource_spec)
|
||||
run_context.notifies_immediately(Notification.new(resource_spec, action, self))
|
||||
end
|
||||
|
||||
# Helper for #notifies
|
||||
def notifies_delayed(action, resource_spec)
|
||||
run_context.notifies_delayed(Notification.new(resource_spec, action, self))
|
||||
end
|
||||
|
||||
#
|
||||
# Get the current actual value of this resource.
|
||||
#
|
||||
# This does not cache--a new value will be returned each time.
|
||||
#
|
||||
# @return A new copy of the resource, with values filled in from the actual
|
||||
# current value.
|
||||
#
|
||||
def current_value
|
||||
provider = provider_for_action(Array(action).first)
|
||||
if provider.whyrun_mode? && !provider.whyrun_supported?
|
||||
raise "Cannot retrieve #{self.class.current_resource} in why-run mode: #{provider} does not support why-run"
|
||||
end
|
||||
provider.load_current_resource
|
||||
provider.current_resource
|
||||
end
|
||||
|
||||
# These methods are necessary for new resources to initialize old ones properly
|
||||
attr_reader :resource_initializing
|
||||
def resource_initializing=(value)
|
||||
if value
|
||||
@resource_initializing = value
|
||||
else
|
||||
remove_instance_variable(:@resource_initializing)
|
||||
end
|
||||
end
|
||||
|
||||
if !respond_to?(:resource_name)
|
||||
def self.resource_name(name=Chef::NOT_PASSED)
|
||||
# Setter
|
||||
if name != Chef::NOT_PASSED
|
||||
# remove_canonical_dsl
|
||||
|
||||
# Set the resource_name and call provides
|
||||
if name
|
||||
name = name.to_sym
|
||||
# If our class is not already providing this name, provide it.
|
||||
# Commented out: use of resource_name and provides will need to be
|
||||
# mutually exclusive in this world, generally.
|
||||
# if !Chef::ResourceResolver.includes_handler?(name, self)
|
||||
provides name#, canonical: true
|
||||
# end
|
||||
@resource_name = name
|
||||
else
|
||||
@resource_name = nil
|
||||
end
|
||||
end
|
||||
@resource_name
|
||||
end
|
||||
def self.resource_name=(name)
|
||||
resource_name(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,60 +0,0 @@
|
||||
require 'chef_compat/resource/lwrp_base'
|
||||
require 'chef/resource/lwrp_base'
|
||||
|
||||
module ChefCompat
|
||||
module Monkeypatches
|
||||
#
|
||||
# NOTE: LOTS OF METAPROGRAMMING HERE. NOT FOR FAINT OF HEART.
|
||||
#
|
||||
|
||||
# Add an empty module to Class so we can temporarily override it in build_from_file
|
||||
module Class
|
||||
end
|
||||
class<<::Class
|
||||
prepend(ChefCompat::Monkeypatches::Class)
|
||||
end
|
||||
|
||||
module Chef
|
||||
module Resource
|
||||
module LWRPBase
|
||||
def build_from_file(cookbook_name, filename, run_context)
|
||||
# If the cookbook this LWRP is from depends on compat_resource, fix its LWRPs up real good
|
||||
if run_context.cookbook_collection[cookbook_name].metadata.dependencies.has_key?('compat_resource')
|
||||
# All cookbooks do Class.new(Chef::Resource::LWRPBase). Change Class.new
|
||||
# temporarily to translate Chef::Resource::LWRPBase to ChefCompat::Resource
|
||||
ChefCompat::Monkeypatches::Class.module_eval do
|
||||
def new(*args, &block)
|
||||
# Trick it! Use ChefCompat::Resource instead of Chef::Resource::LWRPBase
|
||||
if args == [ ::Chef::Resource::LWRPBase ]
|
||||
ChefCompat::Monkeypatches::Class.module_eval do
|
||||
remove_method(:new) if method_defined?(:new)
|
||||
end
|
||||
args = [ ChefCompat::Resource::LWRPBase ]
|
||||
end
|
||||
super(*args, &block)
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
|
||||
# Call the actual build_from_file
|
||||
super
|
||||
|
||||
ensure
|
||||
class<<ChefCompat::Monkeypatches::Class
|
||||
remove_method(:new) if method_defined?(:new)
|
||||
end
|
||||
end
|
||||
else
|
||||
# Call the actual build_from_file
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
class <<::Chef::Resource::LWRPBase
|
||||
prepend(LWRPBase)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,167 +0,0 @@
|
||||
#
|
||||
# Author:: Lamont Granquist (<lamont@chef.io>)
|
||||
# Copyright:: Copyright 2015-2016, Chef Software, 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.
|
||||
#
|
||||
|
||||
# XXX: we now have two copies of this file in the compat_resource cookbook. I'm uncertain if this is a
|
||||
# bug or a feature, and I suspect it is actually a feature. The point of this file is that for all
|
||||
# resources and cookbooks the global Chef::ResourceBuilder class must be upgraded to at least the
|
||||
# 12.10.24 version. The point of the other copy is that for compat_resource cookbooks all their
|
||||
# resources should be using the lastest version that has been sync'd. So these two files should
|
||||
# diverge as times goes on. I believe that is the correct behavior and that we want to have both
|
||||
# files in this cookbook.
|
||||
|
||||
# NOTE: this was extracted from the Recipe DSL mixin, relevant specs are in spec/unit/recipe_spec.rb
|
||||
|
||||
if Gem::Requirement.new("< 12.10.24").satisfied_by?(Gem::Version.new(Chef::VERSION))
|
||||
begin
|
||||
require 'chef/resource_builder'
|
||||
# we use the LoadError this creates on early 12.x to not monkeypatch chef client versions that don't have Chef::ResourceBuilder
|
||||
# (it is lazily included and doesn't appear until compile time so we can't resolve the symbol during library loading)
|
||||
|
||||
class Chef
|
||||
class ResourceBuilder
|
||||
attr_reader :type
|
||||
attr_reader :name
|
||||
attr_reader :created_at
|
||||
attr_reader :params
|
||||
attr_reader :run_context
|
||||
attr_reader :cookbook_name
|
||||
attr_reader :recipe_name
|
||||
attr_reader :enclosing_provider
|
||||
attr_reader :resource
|
||||
|
||||
# FIXME (ruby-2.1 syntax): most of these are mandatory
|
||||
def initialize(type:nil, name:nil, created_at: nil, params: nil, run_context: nil, cookbook_name: nil, recipe_name: nil, enclosing_provider: nil)
|
||||
@type = type
|
||||
@name = name
|
||||
@created_at = created_at
|
||||
@params = params
|
||||
@run_context = run_context
|
||||
@cookbook_name = cookbook_name
|
||||
@recipe_name = recipe_name
|
||||
@enclosing_provider = enclosing_provider
|
||||
end
|
||||
|
||||
def build(&block)
|
||||
raise ArgumentError, "You must supply a name when declaring a #{type} resource" if name.nil?
|
||||
|
||||
@resource = resource_class.new(name, run_context)
|
||||
if resource.resource_name.nil?
|
||||
raise Chef::Exceptions::InvalidResourceSpecification, "#{resource}.resource_name is `nil`! Did you forget to put `provides :blah` or `resource_name :blah` in your resource class?"
|
||||
end
|
||||
resource.source_line = created_at
|
||||
resource.declared_type = type
|
||||
|
||||
# If we have a resource like this one, we want to steal its state
|
||||
# This behavior is very counter-intuitive and should be removed.
|
||||
# See CHEF-3694, https://tickets.opscode.com/browse/CHEF-3694
|
||||
# Moved to this location to resolve CHEF-5052, https://tickets.opscode.com/browse/CHEF-5052
|
||||
if prior_resource
|
||||
resource.load_from(prior_resource)
|
||||
end
|
||||
|
||||
resource.cookbook_name = cookbook_name
|
||||
resource.recipe_name = recipe_name
|
||||
# Determine whether this resource is being created in the context of an enclosing Provider
|
||||
resource.enclosing_provider = enclosing_provider
|
||||
|
||||
# XXX: this is required for definition params inside of the scope of a
|
||||
# subresource to work correctly.
|
||||
resource.params = params
|
||||
|
||||
# Evaluate resource attribute DSL
|
||||
if block_given?
|
||||
resource.resource_initializing = true
|
||||
begin
|
||||
resource.instance_eval(&block)
|
||||
ensure
|
||||
resource.resource_initializing = false
|
||||
end
|
||||
end
|
||||
|
||||
# emit a cloned resource warning if it is warranted
|
||||
if prior_resource
|
||||
if is_trivial_resource?(prior_resource) && identicalish_resources?(prior_resource, resource)
|
||||
emit_harmless_cloning_debug
|
||||
else
|
||||
emit_cloned_resource_warning
|
||||
end
|
||||
end
|
||||
|
||||
# Run optional resource hook
|
||||
resource.after_created
|
||||
|
||||
resource
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def resource_class
|
||||
# Checks the new platform => short_name => resource mapping initially
|
||||
# then fall back to the older approach (Chef::Resource.const_get) for
|
||||
# backward compatibility
|
||||
@resource_class ||= Chef::Resource.resource_for_node(type, run_context.node)
|
||||
end
|
||||
|
||||
def is_trivial_resource?(resource)
|
||||
identicalish_resources?(resource_class.new(name, run_context), resource)
|
||||
end
|
||||
|
||||
# this is an equality test specific to checking for 3694 cloning warnings
|
||||
def identicalish_resources?(first, second)
|
||||
skipped_ivars = [ :@source_line, :@cookbook_name, :@recipe_name, :@params, :@elapsed_time, :@declared_type ]
|
||||
checked_ivars = ( first.instance_variables | second.instance_variables ) - skipped_ivars
|
||||
non_matching_ivars = checked_ivars.reject do |iv|
|
||||
if iv == :@action && ( [first.instance_variable_get(iv)].flatten == [:nothing] || [second.instance_variable_get(iv)].flatten == [:nothing] )
|
||||
# :nothing action on either side of the comparison always matches
|
||||
true
|
||||
else
|
||||
first.instance_variable_get(iv) == second.instance_variable_get(iv)
|
||||
end
|
||||
end
|
||||
Chef::Log.debug("ivars which did not match with the prior resource: #{non_matching_ivars}")
|
||||
non_matching_ivars.empty?
|
||||
end
|
||||
|
||||
def emit_cloned_resource_warning
|
||||
Chef::Log.warn("Cloning resource attributes for #{resource} from prior resource (CHEF-3694)")
|
||||
Chef::Log.warn("Previous #{prior_resource}: #{prior_resource.source_line}") if prior_resource.source_line
|
||||
Chef::Log.warn("Current #{resource}: #{resource.source_line}") if resource.source_line
|
||||
end
|
||||
|
||||
def emit_harmless_cloning_debug
|
||||
Chef::Log.debug("Harmless resource cloning from #{prior_resource}:#{prior_resource.source_line} to #{resource}:#{resource.source_line}")
|
||||
end
|
||||
|
||||
def prior_resource
|
||||
@prior_resource ||=
|
||||
begin
|
||||
key = "#{type}[#{name}]"
|
||||
run_context.resource_collection.lookup_local(key)
|
||||
rescue Chef::Exceptions::ResourceNotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
rescue LoadError
|
||||
# cool we're just on early chef 12.x, nothing to do -- we don't have to worry because there's also not parent_run_context pointer, so we don't have to
|
||||
# use lookup_local to avoid resource cloning shit out of the parent run_context. the resource collection's lookup() method will always use lookup_local
|
||||
# over lookup_recursive.
|
||||
end
|
||||
end
|
@ -1,103 +0,0 @@
|
||||
#
|
||||
# Author:: Adam Jacob (<adam@chef.io>)
|
||||
# Author:: Christopher Walters (<cw@chef.io>)
|
||||
# Copyright:: Copyright 2008-2016, Chef Software 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 "chef/resource_collection/resource_set"
|
||||
require "chef/resource_collection/resource_list"
|
||||
require "chef/resource_collection"
|
||||
require "chef/exceptions"
|
||||
|
||||
module ChefCompat
|
||||
module Monkeypatches
|
||||
module Chef
|
||||
module ResourceCollection
|
||||
module RecursiveNotificationLookup
|
||||
#
|
||||
# Copied verbatim from Chef 12.10.24
|
||||
#
|
||||
attr_accessor :run_context
|
||||
|
||||
def initialize(run_context = nil)
|
||||
super()
|
||||
@run_context = run_context
|
||||
end
|
||||
|
||||
def lookup_local(key)
|
||||
resource_set.lookup(key)
|
||||
end
|
||||
|
||||
def find_local(*args)
|
||||
resource_set.find(*args)
|
||||
end
|
||||
|
||||
def lookup(key)
|
||||
if run_context.nil?
|
||||
lookup_local(key)
|
||||
else
|
||||
lookup_recursive(run_context, key)
|
||||
end
|
||||
end
|
||||
|
||||
def find(*args)
|
||||
if run_context.nil?
|
||||
find_local(*args)
|
||||
else
|
||||
find_recursive(run_context, *args)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def lookup_recursive(rc, key)
|
||||
rc.resource_collection.send(:resource_set).lookup(key)
|
||||
rescue ::Chef::Exceptions::ResourceNotFound
|
||||
raise if !rc.respond_to?(:parent_run_context) || rc.parent_run_context.nil?
|
||||
lookup_recursive(rc.parent_run_context, key)
|
||||
end
|
||||
|
||||
def find_recursive(rc, *args)
|
||||
rc.resource_collection.send(:resource_set).find(*args)
|
||||
rescue ::Chef::Exceptions::ResourceNotFound
|
||||
raise if !rc.respond_to?(:parent_run_context) || rc.parent_run_context.nil?
|
||||
find_recursive(rc.parent_run_context, *args)
|
||||
end
|
||||
end
|
||||
|
||||
module DeleteResources
|
||||
#
|
||||
# Copied verbatim from Chef 12.10.24
|
||||
#
|
||||
def delete(key)
|
||||
resource_list.delete(key)
|
||||
resource_set.delete(key)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class Chef::ResourceCollection
|
||||
unless method_defined?(:lookup_local)
|
||||
prepend ChefCompat::Monkeypatches::Chef::ResourceCollection::RecursiveNotificationLookup
|
||||
end
|
||||
unless method_defined?(:delete)
|
||||
prepend ChefCompat::Monkeypatches::Chef::ResourceCollection::DeleteResources
|
||||
end
|
||||
end
|
@ -1,49 +0,0 @@
|
||||
#
|
||||
# Author:: Tyler Ball (<tball@chef.io>)
|
||||
# Copyright:: Copyright 2014-2016, Chef Software, 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 "chef/resource_collection/resource_list"
|
||||
require "chef/exceptions"
|
||||
|
||||
module ChefCompat
|
||||
module Monkeypatches
|
||||
module Chef
|
||||
module ResourceCollection
|
||||
module ResourceList
|
||||
module DeleteResource
|
||||
# Copied verbatim from Chef 12.10.4
|
||||
def delete(key)
|
||||
raise ArgumentError, "Must pass a Chef::Resource or String to delete" unless key.is_a?(String) || key.is_a?(Chef::Resource)
|
||||
key = key.to_s
|
||||
ret = @resources.reject! { |r| r.to_s == key }
|
||||
if ret.nil?
|
||||
raise ::Chef::Exceptions::ResourceNotFound, "Cannot find a resource matching #{key} (did you define it first?)"
|
||||
end
|
||||
ret
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Chef::ResourceCollection::ResourceList
|
||||
unless method_defined?(:delete)
|
||||
prepend ChefCompat::Monkeypatches::Chef::ResourceCollection::ResourceList::DeleteResource
|
||||
end
|
||||
end
|
@ -1,49 +0,0 @@
|
||||
#
|
||||
# Author:: Tyler Ball (<tball@chef.io>)
|
||||
# Copyright:: Copyright 2014-2016, Chef Software, 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 "chef/resource_collection/resource_list"
|
||||
require "chef/exceptions"
|
||||
|
||||
module ChefCompat
|
||||
module Monkeypatches
|
||||
module Chef
|
||||
module ResourceCollection
|
||||
module ResourceSet
|
||||
module DeleteResource
|
||||
def delete(key)
|
||||
raise ArgumentError, "Must pass a Chef::Resource or String to delete" unless key.is_a?(String) || key.is_a?(Chef::Resource)
|
||||
key = key.to_s
|
||||
res = @resources_by_key.delete(key)
|
||||
|
||||
if res == @resources_by_key.default
|
||||
raise Chef::Exceptions::ResourceNotFound, "Cannot find a resource matching #{key} (did you define it first?)"
|
||||
end
|
||||
res
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Chef::ResourceCollection::ResourceSet
|
||||
unless method_defined?(:delete)
|
||||
prepend ChefCompat::Monkeypatches::Chef::ResourceCollection::ResourceSet::DeleteResource
|
||||
end
|
||||
end
|
@ -1,691 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
if Gem::Requirement.new('< 12.16.42').satisfied_by?(Gem::Version.new(Chef::VERSION))
|
||||
#
|
||||
# Author:: Adam Jacob (<adam@chef.io>)
|
||||
# Author:: Christopher Walters (<cw@chef.io>)
|
||||
# Author:: Tim Hinderliter (<tim@chef.io>)
|
||||
# Copyright:: Copyright 2008-2016, Chef Software 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 "chef/resource_collection"
|
||||
require "chef/cookbook_version"
|
||||
require "chef/node"
|
||||
require "chef/role"
|
||||
require "chef/log"
|
||||
require "chef/recipe"
|
||||
require "chef/run_context/cookbook_compiler"
|
||||
require "chef/event_dispatch/events_output_stream"
|
||||
require "forwardable"
|
||||
|
||||
class Chef
|
||||
|
||||
# == Chef::RunContext
|
||||
# Value object that loads and tracks the context of a Chef run
|
||||
class RunContext
|
||||
#
|
||||
# Global state
|
||||
#
|
||||
|
||||
#
|
||||
# The node for this run
|
||||
#
|
||||
# @return [Chef::Node]
|
||||
#
|
||||
attr_reader :node
|
||||
|
||||
#
|
||||
# The set of cookbooks involved in this run
|
||||
#
|
||||
# @return [Chef::CookbookCollection]
|
||||
#
|
||||
attr_reader :cookbook_collection
|
||||
|
||||
#
|
||||
# Resource Definitions for this run. Populated when the files in
|
||||
# +definitions/+ are evaluated (this is triggered by #load).
|
||||
#
|
||||
# @return [Array[Chef::ResourceDefinition]]
|
||||
#
|
||||
attr_reader :definitions
|
||||
|
||||
#
|
||||
# Event dispatcher for this run.
|
||||
#
|
||||
# @return [Chef::EventDispatch::Dispatcher]
|
||||
#
|
||||
attr_reader :events
|
||||
|
||||
#
|
||||
# Hash of factoids for a reboot request.
|
||||
#
|
||||
# @return [Hash]
|
||||
#
|
||||
attr_accessor :reboot_info
|
||||
|
||||
#
|
||||
# Scoped state
|
||||
#
|
||||
|
||||
#
|
||||
# The parent run context.
|
||||
#
|
||||
# @return [Chef::RunContext] The parent run context, or `nil` if this is the
|
||||
# root context.
|
||||
#
|
||||
attr_reader :parent_run_context
|
||||
|
||||
#
|
||||
# The root run context.
|
||||
#
|
||||
# @return [Chef::RunContext] The root run context.
|
||||
#
|
||||
def root_run_context
|
||||
rc = self
|
||||
rc = rc.parent_run_context until rc.parent_run_context.nil?
|
||||
rc
|
||||
end
|
||||
|
||||
#
|
||||
# The collection of resources intended to be converged (and able to be
|
||||
# notified).
|
||||
#
|
||||
# @return [Chef::ResourceCollection]
|
||||
#
|
||||
# @see CookbookCompiler
|
||||
#
|
||||
attr_reader :resource_collection
|
||||
|
||||
#
|
||||
# The list of control groups to execute during the audit phase
|
||||
#
|
||||
attr_reader :audits
|
||||
|
||||
#
|
||||
# Notification handling
|
||||
#
|
||||
|
||||
#
|
||||
# A Hash containing the before notifications triggered by resources
|
||||
# during the converge phase of the chef run.
|
||||
#
|
||||
# @return [Hash[String, Array[Chef::Resource::Notification]]] A hash from
|
||||
# <notifying resource name> => <list of notifications it sent>
|
||||
#
|
||||
attr_reader :before_notification_collection
|
||||
|
||||
#
|
||||
# A Hash containing the immediate notifications triggered by resources
|
||||
# during the converge phase of the chef run.
|
||||
#
|
||||
# @return [Hash[String, Array[Chef::Resource::Notification]]] A hash from
|
||||
# <notifying resource name> => <list of notifications it sent>
|
||||
#
|
||||
attr_reader :immediate_notification_collection
|
||||
|
||||
#
|
||||
# A Hash containing the delayed (end of run) notifications triggered by
|
||||
# resources during the converge phase of the chef run.
|
||||
#
|
||||
# @return [Hash[String, Array[Chef::Resource::Notification]]] A hash from
|
||||
# <notifying resource name> => <list of notifications it sent>
|
||||
#
|
||||
attr_reader :delayed_notification_collection
|
||||
|
||||
#
|
||||
# An Array containing the delayed (end of run) notifications triggered by
|
||||
# resources during the converge phase of the chef run.
|
||||
#
|
||||
# @return [Array[Chef::Resource::Notification]] An array of notification objects
|
||||
#
|
||||
attr_reader :delayed_actions
|
||||
|
||||
# Creates a new Chef::RunContext object and populates its fields. This object gets
|
||||
# used by the Chef Server to generate a fully compiled recipe list for a node.
|
||||
#
|
||||
# @param node [Chef::Node] The node to run against.
|
||||
# @param cookbook_collection [Chef::CookbookCollection] The cookbooks
|
||||
# involved in this run.
|
||||
# @param events [EventDispatch::Dispatcher] The event dispatcher for this
|
||||
# run.
|
||||
#
|
||||
def initialize(node, cookbook_collection, events)
|
||||
@node = node
|
||||
@cookbook_collection = cookbook_collection
|
||||
@events = events
|
||||
|
||||
node.run_context = self
|
||||
node.set_cookbook_attribute
|
||||
|
||||
@definitions = Hash.new
|
||||
@loaded_recipes_hash = {}
|
||||
@loaded_attributes_hash = {}
|
||||
@reboot_info = {}
|
||||
@cookbook_compiler = nil
|
||||
@delayed_actions = []
|
||||
|
||||
initialize_child_state
|
||||
end
|
||||
|
||||
#
|
||||
# Triggers the compile phase of the chef run.
|
||||
#
|
||||
# @param run_list_expansion [Chef::RunList::RunListExpansion] The run list.
|
||||
# @see Chef::RunContext::CookbookCompiler
|
||||
#
|
||||
def load(run_list_expansion)
|
||||
@cookbook_compiler = CookbookCompiler.new(self, run_list_expansion, events)
|
||||
cookbook_compiler.compile
|
||||
end
|
||||
|
||||
#
|
||||
# Initialize state that applies to both Chef::RunContext and Chef::ChildRunContext
|
||||
#
|
||||
def initialize_child_state
|
||||
@audits = {}
|
||||
@resource_collection = Chef::ResourceCollection.new(self)
|
||||
@before_notification_collection = Hash.new { |h, k| h[k] = [] }
|
||||
@immediate_notification_collection = Hash.new { |h, k| h[k] = [] }
|
||||
@delayed_notification_collection = Hash.new { |h, k| h[k] = [] }
|
||||
@delayed_actions = []
|
||||
end
|
||||
|
||||
#
|
||||
# Adds an before notification to the +before_notification_collection+.
|
||||
#
|
||||
# @param [Chef::Resource::Notification] The notification to add.
|
||||
#
|
||||
def notifies_before(notification)
|
||||
# Note for the future, notification.notifying_resource may be an instance
|
||||
# of Chef::Resource::UnresolvedSubscribes when calling {Resource#subscribes}
|
||||
# with a string value.
|
||||
before_notification_collection[notification.notifying_resource.declared_key] << notification
|
||||
end
|
||||
|
||||
#
|
||||
# Adds an immediate notification to the +immediate_notification_collection+.
|
||||
#
|
||||
# @param [Chef::Resource::Notification] The notification to add.
|
||||
#
|
||||
def notifies_immediately(notification)
|
||||
# Note for the future, notification.notifying_resource may be an instance
|
||||
# of Chef::Resource::UnresolvedSubscribes when calling {Resource#subscribes}
|
||||
# with a string value.
|
||||
immediate_notification_collection[notification.notifying_resource.declared_key] << notification
|
||||
end
|
||||
|
||||
#
|
||||
# Adds a delayed notification to the +delayed_notification_collection+.
|
||||
#
|
||||
# @param [Chef::Resource::Notification] The notification to add.
|
||||
#
|
||||
def notifies_delayed(notification)
|
||||
# Note for the future, notification.notifying_resource may be an instance
|
||||
# of Chef::Resource::UnresolvedSubscribes when calling {Resource#subscribes}
|
||||
# with a string value.
|
||||
delayed_notification_collection[notification.notifying_resource.declared_key] << notification
|
||||
end
|
||||
|
||||
#
|
||||
# Adds a delayed action to the +delayed_actions+.
|
||||
#
|
||||
def add_delayed_action(notification)
|
||||
if delayed_actions.any? { |existing_notification| existing_notification.duplicates?(notification) }
|
||||
Chef::Log.info( "#{notification.notifying_resource} not queuing delayed action #{notification.action} on #{notification.resource}"\
|
||||
" (delayed), as it's already been queued")
|
||||
else
|
||||
delayed_actions << notification
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Get the list of before notifications sent by the given resource.
|
||||
#
|
||||
# @return [Array[Notification]]
|
||||
#
|
||||
def before_notifications(resource)
|
||||
return before_notification_collection[resource.declared_key]
|
||||
end
|
||||
|
||||
#
|
||||
# Get the list of immediate notifications sent by the given resource.
|
||||
#
|
||||
# @return [Array[Notification]]
|
||||
#
|
||||
def immediate_notifications(resource)
|
||||
return immediate_notification_collection[resource.declared_key]
|
||||
end
|
||||
|
||||
#
|
||||
# Get the list of delayed (end of run) notifications sent by the given
|
||||
# resource.
|
||||
#
|
||||
# @return [Array[Notification]]
|
||||
#
|
||||
def delayed_notifications(resource)
|
||||
return delayed_notification_collection[resource.declared_key]
|
||||
end
|
||||
|
||||
#
|
||||
# Cookbook and recipe loading
|
||||
#
|
||||
|
||||
#
|
||||
# Evaluates the recipes +recipe_names+. Used by DSL::IncludeRecipe
|
||||
#
|
||||
# @param recipe_names [Array[String]] The list of recipe names (e.g.
|
||||
# 'my_cookbook' or 'my_cookbook::my_resource').
|
||||
# @param current_cookbook The cookbook we are currently running in.
|
||||
#
|
||||
# @see DSL::IncludeRecipe#include_recipe
|
||||
#
|
||||
def include_recipe(*recipe_names, current_cookbook: nil)
|
||||
result_recipes = Array.new
|
||||
recipe_names.flatten.each do |recipe_name|
|
||||
if result = load_recipe(recipe_name, current_cookbook: current_cookbook)
|
||||
result_recipes << result
|
||||
end
|
||||
end
|
||||
result_recipes
|
||||
end
|
||||
|
||||
#
|
||||
# Evaluates the recipe +recipe_name+. Used by DSL::IncludeRecipe
|
||||
#
|
||||
# TODO I am sort of confused why we have both this and include_recipe ...
|
||||
# I don't see anything different beyond accepting and returning an
|
||||
# array of recipes.
|
||||
#
|
||||
# @param recipe_names [Array[String]] The recipe name (e.g 'my_cookbook' or
|
||||
# 'my_cookbook::my_resource').
|
||||
# @param current_cookbook The cookbook we are currently running in.
|
||||
#
|
||||
# @return A truthy value if the load occurred; `false` if already loaded.
|
||||
#
|
||||
# @see DSL::IncludeRecipe#load_recipe
|
||||
#
|
||||
def load_recipe(recipe_name, current_cookbook: nil)
|
||||
Chef::Log.debug("Loading recipe #{recipe_name} via include_recipe")
|
||||
|
||||
cookbook_name, recipe_short_name = Chef::Recipe.parse_recipe_name(recipe_name, current_cookbook: current_cookbook)
|
||||
|
||||
if unreachable_cookbook?(cookbook_name) # CHEF-4367
|
||||
Chef::Log.warn(<<-ERROR_MESSAGE)
|
||||
MissingCookbookDependency:
|
||||
Recipe `#{recipe_name}` is not in the run_list, and cookbook '#{cookbook_name}'
|
||||
is not a dependency of any cookbook in the run_list. To load this recipe,
|
||||
first add a dependency on cookbook '#{cookbook_name}' in the cookbook you're
|
||||
including it from in that cookbook's metadata.
|
||||
ERROR_MESSAGE
|
||||
end
|
||||
|
||||
if loaded_fully_qualified_recipe?(cookbook_name, recipe_short_name)
|
||||
Chef::Log.debug("I am not loading #{recipe_name}, because I have already seen it.")
|
||||
false
|
||||
else
|
||||
loaded_recipe(cookbook_name, recipe_short_name)
|
||||
node.loaded_recipe(cookbook_name, recipe_short_name)
|
||||
cookbook = cookbook_collection[cookbook_name]
|
||||
cookbook.load_recipe(recipe_short_name, self)
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Load the given recipe from a filename.
|
||||
#
|
||||
# @param recipe_file [String] The recipe filename.
|
||||
#
|
||||
# @return [Chef::Recipe] The loaded recipe.
|
||||
#
|
||||
# @raise [Chef::Exceptions::RecipeNotFound] If the file does not exist.
|
||||
#
|
||||
def load_recipe_file(recipe_file)
|
||||
if !File.exist?(recipe_file)
|
||||
raise Chef::Exceptions::RecipeNotFound, "could not find recipe file #{recipe_file}"
|
||||
end
|
||||
|
||||
Chef::Log.debug("Loading recipe file #{recipe_file}")
|
||||
recipe = Chef::Recipe.new("@recipe_files", recipe_file, self)
|
||||
recipe.from_file(recipe_file)
|
||||
recipe
|
||||
end
|
||||
|
||||
#
|
||||
# Look up an attribute filename.
|
||||
#
|
||||
# @param cookbook_name [String] The cookbook name of the attribute file.
|
||||
# @param attr_file_name [String] The attribute file's name (not path).
|
||||
#
|
||||
# @return [String] The filename.
|
||||
#
|
||||
# @see DSL::IncludeAttribute#include_attribute
|
||||
#
|
||||
# @raise [Chef::Exceptions::CookbookNotFound] If the cookbook could not be found.
|
||||
# @raise [Chef::Exceptions::AttributeNotFound] If the attribute file could not be found.
|
||||
#
|
||||
def resolve_attribute(cookbook_name, attr_file_name)
|
||||
cookbook = cookbook_collection[cookbook_name]
|
||||
raise Chef::Exceptions::CookbookNotFound, "could not find cookbook #{cookbook_name} while loading attribute #{name}" unless cookbook
|
||||
|
||||
attribute_filename = cookbook.attribute_filenames_by_short_filename[attr_file_name]
|
||||
raise Chef::Exceptions::AttributeNotFound, "could not find filename for attribute #{attr_file_name} in cookbook #{cookbook_name}" unless attribute_filename
|
||||
|
||||
attribute_filename
|
||||
end
|
||||
|
||||
#
|
||||
# A list of all recipes that have been loaded.
|
||||
#
|
||||
# This is stored internally as a Hash, so ordering is predictable.
|
||||
#
|
||||
# TODO is the above statement true in a 1.9+ ruby world? Is it relevant?
|
||||
#
|
||||
# @return [Array[String]] A list of recipes in fully qualified form, e.g.
|
||||
# the recipe "nginx" will be given as "nginx::default".
|
||||
#
|
||||
# @see #loaded_recipe? To determine if a particular recipe has been loaded.
|
||||
#
|
||||
def loaded_recipes
|
||||
loaded_recipes_hash.keys
|
||||
end
|
||||
|
||||
#
|
||||
# A list of all attributes files that have been loaded.
|
||||
#
|
||||
# Stored internally using a Hash, so order is predictable.
|
||||
#
|
||||
# TODO is the above statement true in a 1.9+ ruby world? Is it relevant?
|
||||
#
|
||||
# @return [Array[String]] A list of attribute file names in fully qualified
|
||||
# form, e.g. the "nginx" will be given as "nginx::default".
|
||||
#
|
||||
def loaded_attributes
|
||||
loaded_attributes_hash.keys
|
||||
end
|
||||
|
||||
#
|
||||
# Find out if a given recipe has been loaded.
|
||||
#
|
||||
# @param cookbook [String] Cookbook name.
|
||||
# @param recipe [String] Recipe name.
|
||||
#
|
||||
# @return [Boolean] `true` if the recipe has been loaded, `false` otherwise.
|
||||
#
|
||||
def loaded_fully_qualified_recipe?(cookbook, recipe)
|
||||
loaded_recipes_hash.has_key?("#{cookbook}::#{recipe}")
|
||||
end
|
||||
|
||||
#
|
||||
# Find out if a given recipe has been loaded.
|
||||
#
|
||||
# @param recipe [String] Recipe name. "nginx" and "nginx::default" yield
|
||||
# the same results.
|
||||
#
|
||||
# @return [Boolean] `true` if the recipe has been loaded, `false` otherwise.
|
||||
#
|
||||
def loaded_recipe?(recipe)
|
||||
cookbook, recipe_name = Chef::Recipe.parse_recipe_name(recipe)
|
||||
loaded_fully_qualified_recipe?(cookbook, recipe_name)
|
||||
end
|
||||
|
||||
#
|
||||
# Mark a given recipe as having been loaded.
|
||||
#
|
||||
# @param cookbook [String] Cookbook name.
|
||||
# @param recipe [String] Recipe name.
|
||||
#
|
||||
def loaded_recipe(cookbook, recipe)
|
||||
loaded_recipes_hash["#{cookbook}::#{recipe}"] = true
|
||||
end
|
||||
|
||||
#
|
||||
# Find out if a given attribute file has been loaded.
|
||||
#
|
||||
# @param cookbook [String] Cookbook name.
|
||||
# @param attribute_file [String] Attribute file name.
|
||||
#
|
||||
# @return [Boolean] `true` if the recipe has been loaded, `false` otherwise.
|
||||
#
|
||||
def loaded_fully_qualified_attribute?(cookbook, attribute_file)
|
||||
loaded_attributes_hash.has_key?("#{cookbook}::#{attribute_file}")
|
||||
end
|
||||
|
||||
#
|
||||
# Mark a given attribute file as having been loaded.
|
||||
#
|
||||
# @param cookbook [String] Cookbook name.
|
||||
# @param attribute_file [String] Attribute file name.
|
||||
#
|
||||
def loaded_attribute(cookbook, attribute_file)
|
||||
loaded_attributes_hash["#{cookbook}::#{attribute_file}"] = true
|
||||
end
|
||||
|
||||
##
|
||||
# Cookbook File Introspection
|
||||
|
||||
#
|
||||
# Find out if the cookbook has the given template.
|
||||
#
|
||||
# @param cookbook [String] Cookbook name.
|
||||
# @param template_name [String] Template name.
|
||||
#
|
||||
# @return [Boolean] `true` if the template is in the cookbook, `false`
|
||||
# otherwise.
|
||||
# @see Chef::CookbookVersion#has_template_for_node?
|
||||
#
|
||||
def has_template_in_cookbook?(cookbook, template_name)
|
||||
cookbook = cookbook_collection[cookbook]
|
||||
cookbook.has_template_for_node?(node, template_name)
|
||||
end
|
||||
|
||||
#
|
||||
# Find out if the cookbook has the given file.
|
||||
#
|
||||
# @param cookbook [String] Cookbook name.
|
||||
# @param cb_file_name [String] File name.
|
||||
#
|
||||
# @return [Boolean] `true` if the file is in the cookbook, `false`
|
||||
# otherwise.
|
||||
# @see Chef::CookbookVersion#has_cookbook_file_for_node?
|
||||
#
|
||||
def has_cookbook_file_in_cookbook?(cookbook, cb_file_name)
|
||||
cookbook = cookbook_collection[cookbook]
|
||||
cookbook.has_cookbook_file_for_node?(node, cb_file_name)
|
||||
end
|
||||
|
||||
#
|
||||
# Find out whether the given cookbook is in the cookbook dependency graph.
|
||||
#
|
||||
# @param cookbook_name [String] Cookbook name.
|
||||
#
|
||||
# @return [Boolean] `true` if the cookbook is reachable, `false` otherwise.
|
||||
#
|
||||
# @see Chef::CookbookCompiler#unreachable_cookbook?
|
||||
def unreachable_cookbook?(cookbook_name)
|
||||
cookbook_compiler.unreachable_cookbook?(cookbook_name)
|
||||
end
|
||||
|
||||
#
|
||||
# Open a stream object that can be printed into and will dispatch to events
|
||||
#
|
||||
# @param name [String] The name of the stream.
|
||||
# @param options [Hash] Other options for the stream.
|
||||
#
|
||||
# @return [EventDispatch::EventsOutputStream] The created stream.
|
||||
#
|
||||
# @yield If a block is passed, it will be run and the stream will be closed
|
||||
# afterwards.
|
||||
# @yieldparam stream [EventDispatch::EventsOutputStream] The created stream.
|
||||
#
|
||||
def open_stream(name: nil, **options)
|
||||
stream = EventDispatch::EventsOutputStream.new(events, name: name, **options)
|
||||
if block_given?
|
||||
begin
|
||||
yield stream
|
||||
ensure
|
||||
stream.close
|
||||
end
|
||||
else
|
||||
stream
|
||||
end
|
||||
end
|
||||
|
||||
# there are options for how to handle multiple calls to these functions:
|
||||
# 1. first call always wins (never change reboot_info once set).
|
||||
# 2. last call always wins (happily change reboot_info whenever).
|
||||
# 3. raise an exception on the first conflict.
|
||||
# 4. disable reboot after this run if anyone ever calls :cancel.
|
||||
# 5. raise an exception on any second call.
|
||||
# 6. ?
|
||||
def request_reboot(reboot_info)
|
||||
Chef::Log.info "Changing reboot status from #{self.reboot_info.inspect} to #{reboot_info.inspect}"
|
||||
@reboot_info = reboot_info
|
||||
end
|
||||
|
||||
def cancel_reboot
|
||||
Chef::Log.info "Changing reboot status from #{reboot_info.inspect} to {}"
|
||||
@reboot_info = {}
|
||||
end
|
||||
|
||||
def reboot_requested?
|
||||
reboot_info.size > 0
|
||||
end
|
||||
|
||||
#
|
||||
# Create a child RunContext.
|
||||
#
|
||||
def create_child
|
||||
ChildRunContext.new(self)
|
||||
end
|
||||
|
||||
# @api private
|
||||
attr_writer :resource_collection
|
||||
|
||||
protected
|
||||
|
||||
attr_reader :cookbook_compiler
|
||||
attr_reader :loaded_attributes_hash
|
||||
attr_reader :loaded_recipes_hash
|
||||
|
||||
module Deprecated
|
||||
###
|
||||
# These need to be settable so deploy can run a resource_collection
|
||||
# independent of any cookbooks via +recipe_eval+
|
||||
def audits=(value)
|
||||
Chef.log_deprecation("Setting run_context.audits will be removed in a future Chef. Use run_context.create_child to create a new RunContext instead.")
|
||||
@audits = value
|
||||
end
|
||||
|
||||
def immediate_notification_collection=(value)
|
||||
Chef.log_deprecation("Setting run_context.immediate_notification_collection will be removed in a future Chef. Use run_context.create_child to create a new RunContext instead.")
|
||||
@immediate_notification_collection = value
|
||||
end
|
||||
|
||||
def delayed_notification_collection=(value)
|
||||
Chef.log_deprecation("Setting run_context.delayed_notification_collection will be removed in a future Chef. Use run_context.create_child to create a new RunContext instead.")
|
||||
@delayed_notification_collection = value
|
||||
end
|
||||
end
|
||||
prepend Deprecated
|
||||
|
||||
#
|
||||
# A child run context. Delegates all root context calls to its parent.
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
class ChildRunContext < RunContext
|
||||
extend Forwardable
|
||||
def_delegators :parent_run_context, *%w{
|
||||
cancel_reboot
|
||||
config
|
||||
cookbook_collection
|
||||
cookbook_compiler
|
||||
definitions
|
||||
events
|
||||
has_cookbook_file_in_cookbook?
|
||||
has_template_in_cookbook?
|
||||
load
|
||||
loaded_attribute
|
||||
loaded_attributes
|
||||
loaded_attributes_hash
|
||||
loaded_fully_qualified_attribute?
|
||||
loaded_fully_qualified_recipe?
|
||||
loaded_recipe
|
||||
loaded_recipe?
|
||||
loaded_recipes
|
||||
loaded_recipes_hash
|
||||
node
|
||||
open_stream
|
||||
reboot_info
|
||||
reboot_info=
|
||||
reboot_requested?
|
||||
request_reboot
|
||||
resolve_attribute
|
||||
unreachable_cookbook?
|
||||
}
|
||||
|
||||
def initialize(parent_run_context)
|
||||
@parent_run_context = parent_run_context
|
||||
|
||||
# We don't call super, because we don't bother initializing stuff we're
|
||||
# going to delegate to the parent anyway. Just initialize things that
|
||||
# every instance needs.
|
||||
initialize_child_state
|
||||
end
|
||||
|
||||
CHILD_STATE = %w{
|
||||
audits
|
||||
audits=
|
||||
create_child
|
||||
add_delayed_action
|
||||
delayed_actions
|
||||
delayed_notification_collection
|
||||
delayed_notification_collection=
|
||||
delayed_notifications
|
||||
immediate_notification_collection
|
||||
immediate_notification_collection=
|
||||
immediate_notifications
|
||||
before_notification_collection
|
||||
before_notifications
|
||||
include_recipe
|
||||
initialize_child_state
|
||||
load_recipe
|
||||
load_recipe_file
|
||||
notifies_before
|
||||
notifies_immediately
|
||||
notifies_delayed
|
||||
parent_run_context
|
||||
root_run_context
|
||||
resource_collection
|
||||
resource_collection=
|
||||
}.map { |x| x.to_sym }
|
||||
|
||||
# Verify that we didn't miss any methods
|
||||
unless @__skip_method_checking # hook specifically for compat_resource
|
||||
missing_methods = superclass.instance_methods(false) - instance_methods(false) - CHILD_STATE
|
||||
if !missing_methods.empty?
|
||||
raise "ERROR: not all methods of RunContext accounted for in ChildRunContext! All methods must be marked as child methods with CHILD_STATE or delegated to the parent_run_context. Missing #{missing_methods.join(", ")}."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,153 +0,0 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
if Gem::Requirement.new('< 12.16.42').satisfied_by?(Gem::Version.new(Chef::VERSION))
|
||||
#--
|
||||
# Author:: Adam Jacob (<adam@chef.io>)
|
||||
# Author:: Christopher Walters (<cw@chef.io>)
|
||||
# Author:: Tim Hinderliter (<tim@chef.io>)
|
||||
# Copyright:: Copyright 2008-2016, Chef Software 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 "chef/exceptions"
|
||||
require "chef/mixin/params_validate"
|
||||
require "chef/node"
|
||||
require "chef/resource_collection"
|
||||
|
||||
class Chef
|
||||
# == Chef::Runner
|
||||
# This class is responsible for executing the steps in a Chef run.
|
||||
class Runner
|
||||
|
||||
attr_reader :run_context
|
||||
|
||||
include Chef::Mixin::ParamsValidate
|
||||
|
||||
def initialize(run_context)
|
||||
@run_context = run_context
|
||||
end
|
||||
|
||||
def delayed_actions
|
||||
@run_context.delayed_actions
|
||||
end
|
||||
|
||||
def events
|
||||
@run_context.events
|
||||
end
|
||||
|
||||
# Determine the appropriate provider for the given resource, then
|
||||
# execute it.
|
||||
def run_action(resource, action, notification_type = nil, notifying_resource = nil)
|
||||
# If there are any before notifications, why-run the resource
|
||||
# and notify anyone who needs notifying
|
||||
before_notifications = run_context.before_notifications(resource) || []
|
||||
unless before_notifications.empty?
|
||||
forced_why_run do
|
||||
Chef::Log.info("#{resource} running why-run #{action} action to support before action")
|
||||
resource.run_action(action, notification_type, notifying_resource)
|
||||
end
|
||||
|
||||
if resource.updated_by_last_action?
|
||||
before_notifications.each do |notification|
|
||||
Chef::Log.info("#{resource} sending #{notification.action} action to #{notification.resource} (before)")
|
||||
run_action(notification.resource, notification.action, :before, resource)
|
||||
end
|
||||
resource.updated_by_last_action(false)
|
||||
end
|
||||
end
|
||||
|
||||
# Actually run the action for realsies
|
||||
resource.run_action(action, notification_type, notifying_resource)
|
||||
|
||||
# Execute any immediate and queue up any delayed notifications
|
||||
# associated with the resource, but only if it was updated *this time*
|
||||
# we ran an action on it.
|
||||
if resource.updated_by_last_action?
|
||||
run_context.immediate_notifications(resource).each do |notification|
|
||||
Chef::Log.info("#{resource} sending #{notification.action} action to #{notification.resource} (immediate)")
|
||||
run_action(notification.resource, notification.action, :immediate, resource)
|
||||
end
|
||||
|
||||
run_context.delayed_notifications(resource).each do |notification|
|
||||
# send the notification to the run_context of the receiving resource
|
||||
notification.resource.run_context.add_delayed_action(notification)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Iterates over the +resource_collection+ in the +run_context+ calling
|
||||
# +run_action+ for each resource in turn.
|
||||
def converge
|
||||
# Resolve all lazy/forward references in notifications
|
||||
run_context.resource_collection.each do |resource|
|
||||
resource.resolve_notification_references
|
||||
end
|
||||
|
||||
# Execute each resource.
|
||||
run_context.resource_collection.execute_each_resource do |resource|
|
||||
Array(resource.action).each { |action| run_action(resource, action) }
|
||||
end
|
||||
|
||||
rescue Exception => e
|
||||
Chef::Log.info "Running queued delayed notifications before re-raising exception"
|
||||
run_delayed_notifications(e)
|
||||
else
|
||||
run_delayed_notifications(nil)
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Run all our :delayed actions
|
||||
def run_delayed_notifications(error = nil)
|
||||
collected_failures = Exceptions::MultipleFailures.new
|
||||
collected_failures.client_run_failure(error) unless error.nil?
|
||||
delayed_actions.each do |notification|
|
||||
result = run_delayed_notification(notification)
|
||||
if result.kind_of?(Exception)
|
||||
collected_failures.notification_failure(result)
|
||||
end
|
||||
end
|
||||
collected_failures.raise!
|
||||
end
|
||||
|
||||
def run_delayed_notification(notification)
|
||||
Chef::Log.info( "#{notification.notifying_resource} sending #{notification.action}"\
|
||||
" action to #{notification.resource} (delayed)")
|
||||
# Struct of resource/action to call
|
||||
run_action(notification.resource, notification.action, :delayed)
|
||||
true
|
||||
rescue Exception => e
|
||||
e
|
||||
end
|
||||
|
||||
# helper to run a block of code with why_run forced to true and then restore it correctly
|
||||
def forced_why_run
|
||||
saved = Chef::Config[:why_run]
|
||||
Chef::Config[:why_run] = true
|
||||
yield
|
||||
ensure
|
||||
Chef::Config[:why_run] = saved
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
@ -1,6 +0,0 @@
|
||||
require 'chef_compat/copied_from_chef/chef/property'
|
||||
|
||||
module ChefCompat
|
||||
class Property < ChefCompat::CopiedFromChef::Chef::Property
|
||||
end
|
||||
end
|
@ -1,8 +0,0 @@
|
||||
require 'chef/recipe'
|
||||
require 'chef_compat/copied_from_chef/chef/dsl/recipe'
|
||||
|
||||
module ChefCompat
|
||||
class Recipe < Chef::Recipe
|
||||
include ChefCompat::CopiedFromChef::Chef::DSL::Recipe::FullDSL
|
||||
end
|
||||
end
|
@ -1,56 +0,0 @@
|
||||
require 'chef_compat/monkeypatches'
|
||||
require 'chef_compat/copied_from_chef/chef/resource'
|
||||
|
||||
# We do NOT want action defined if chefspec is engaged
|
||||
if Chef::Provider::InlineResources::ClassMethods.instance_method(:action).source_location[0] =~ /chefspec/
|
||||
ChefCompat::CopiedFromChef::Chef::Provider::InlineResources::ClassMethods.instance_eval do
|
||||
remove_method(:action)
|
||||
end
|
||||
end
|
||||
|
||||
module ChefCompat
|
||||
class Resource < ChefCompat::CopiedFromChef::Chef::Resource
|
||||
def initialize(*args, &block)
|
||||
super
|
||||
# @resource_name is used in earlier Chef versions
|
||||
@resource_name = self.class.resource_name
|
||||
end
|
||||
# Things we'll need to define ourselves:
|
||||
# 1. provider
|
||||
# 2. resource_name
|
||||
|
||||
def provider(*args, &block)
|
||||
super || self.class.action_class
|
||||
end
|
||||
def provider=(arg)
|
||||
provider(arg)
|
||||
end
|
||||
|
||||
if !respond_to?(:resource_name)
|
||||
def self.resource_name(name=Chef::NOT_PASSED)
|
||||
# Setter
|
||||
if name != Chef::NOT_PASSED
|
||||
# remove_canonical_dsl
|
||||
|
||||
# Set the resource_name and call provides
|
||||
if name
|
||||
name = name.to_sym
|
||||
# If our class is not already providing this name, provide it.
|
||||
# Commented out: use of resource_name and provides will need to be
|
||||
# mutually exclusive in this world, generally.
|
||||
# if !Chef::ResourceResolver.includes_handler?(name, self)
|
||||
provides name#, canonical: true
|
||||
# end
|
||||
@resource_name = name
|
||||
else
|
||||
@resource_name = nil
|
||||
end
|
||||
end
|
||||
@resource_name
|
||||
end
|
||||
def self.resource_name=(name)
|
||||
resource_name(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,44 +0,0 @@
|
||||
require 'chef_compat/resource'
|
||||
require 'chef_compat/copied_from_chef/chef/resource'
|
||||
require 'chef/mixin/convert_to_class_name'
|
||||
require 'chef/mixin/from_file'
|
||||
|
||||
module ChefCompat
|
||||
class Resource < ChefCompat::CopiedFromChef::Chef::Resource
|
||||
class LWRPBase < ChefCompat::Resource
|
||||
class<<self
|
||||
|
||||
include Chef::Mixin::ConvertToClassName
|
||||
include Chef::Mixin::FromFile
|
||||
|
||||
alias :attribute :property
|
||||
|
||||
# Adds +action_names+ to the list of valid actions for this resource.
|
||||
# Does not include superclass's action list when appending.
|
||||
def actions(*action_names)
|
||||
action_names = action_names.flatten
|
||||
if !action_names.empty? && !@allowed_actions
|
||||
self.allowed_actions = ([ :nothing ] + action_names).uniq
|
||||
else
|
||||
allowed_actions(*action_names)
|
||||
end
|
||||
end
|
||||
alias :actions= :allowed_actions=
|
||||
|
||||
# @deprecated
|
||||
def valid_actions(*args)
|
||||
Chef::Log.warn("`valid_actions' is deprecated, please use allowed_actions `instead'!")
|
||||
allowed_actions(*args)
|
||||
end
|
||||
|
||||
# Set the run context on the class. Used to provide access to the node
|
||||
# during class definition.
|
||||
attr_accessor :run_context
|
||||
|
||||
def node
|
||||
run_context ? run_context.node : nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,3 +0,0 @@
|
||||
module ChefCompat
|
||||
CHEF_UPSTREAM_VERSION="12.16.42"
|
||||
end
|
@ -1,35 +0,0 @@
|
||||
require "chef/version"
|
||||
|
||||
if Gem::Requirement.new(">= 12.0").satisfied_by?(Gem::Version.new(Chef::VERSION))
|
||||
|
||||
require 'chef_compat/resource'
|
||||
require 'chef_compat/property'
|
||||
require 'chef_compat/mixin/properties'
|
||||
|
||||
resources_dir = File.expand_path("chef_compat/copied_from_chef/chef/resource", File.dirname(__FILE__))
|
||||
providers_dir = File.expand_path("chef_compat/copied_from_chef/chef/provider", File.dirname(__FILE__))
|
||||
Dir["#{resources_dir}/*.rb"].each {|file| require file }
|
||||
Dir["#{providers_dir}/*.rb"].each {|file| require file }
|
||||
else
|
||||
|
||||
class Chef
|
||||
class Resource
|
||||
def self.property(args, &block)
|
||||
raise_chef_11_error
|
||||
end
|
||||
|
||||
def self.resource_name(args, &block)
|
||||
raise_chef_11_error
|
||||
end
|
||||
|
||||
def self.action(args, &block)
|
||||
raise_chef_11_error
|
||||
end
|
||||
|
||||
def self.raise_chef_11_error
|
||||
raise "This resource is written with Chef 12.5 custom resources, and requires at least Chef 12.0 used with the compat_resource cookbook, it will not work with Chef 11.x clients, and those users must pin their cookbooks to older versions or upgrade."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -1,31 +0,0 @@
|
||||
unless Gem::Requirement.new(">= 12.0").satisfied_by?(Gem::Version.new(Chef::VERSION))
|
||||
raise "This resource is written with Chef 12.5 custom resources, and requires at least Chef 12.0 used with the compat_resource cookbook, it will not work with Chef 11.x clients, and those users must pin their cookbooks to older versions or upgrade."
|
||||
end
|
||||
|
||||
# If users are on old verisons of ChefDK which activates an (old) gem via cheffish before this cookbook loads, then
|
||||
# we just try to monkeypatch over the top of a monkeypatch. Its possible that we have checks in this cookbook which
|
||||
# will defeat that purpose and fail to monkeypatch on top of monkeypatches -- in which case those checks should be
|
||||
# removed -- this cookbook needs to win when it gets into a fight with the old gem versions.
|
||||
if Gem.loaded_specs["compat_resource"]
|
||||
Chef.log_deprecation "using compat_resource as a gem is deprecated; please update cheffish and chef-provisioning gems (or use the latest Chef/ChefDK packages) or else manually pin your compat_resource cookbook version to the same version as the gem you are using to remove this warning"
|
||||
end
|
||||
|
||||
# we want to not pollute the libpath with our files until after we've done the version check
|
||||
require_relative '../files/lib/chef_upstream_version'
|
||||
|
||||
# on any chef client later than the one we were based off of we just turn into a no-op
|
||||
if Gem::Requirement.new("< #{ChefCompat::CHEF_UPSTREAM_VERSION}").satisfied_by?(Gem::Version.new(Chef::VERSION))
|
||||
Chef::Log.debug "loading compat_resource based on chef-version #{ChefCompat::CHEF_UPSTREAM_VERSION} over chef version #{Gem::Version.new(Chef::VERSION)}"
|
||||
$LOAD_PATH.unshift(File.expand_path("../files/lib", File.dirname(__FILE__)))
|
||||
require 'compat_resource'
|
||||
else
|
||||
Chef::Log.debug "NOT LOADING compat_resource based on chef-version #{ChefCompat::CHEF_UPSTREAM_VERSION} over chef version #{Gem::Version.new(Chef::VERSION)}"
|
||||
unless defined?(ChefCompat::Resource) && defined?(ChefCompat::Mixin::Properties)
|
||||
module ChefCompat
|
||||
Resource = Chef::Resource
|
||||
module Mixin
|
||||
Properties = Chef::Mixin::Properties
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1 +0,0 @@
|
||||
{"name":"compat_resource","version":"12.16.3","description":"Backports functionality introduced in the latest chef-client releases to any chef-client from 12.1 onwards","long_description":"# compat_resource cookbook\n\n[](https://travis-ci.org/chef-cookbooks/compat_resource) [](https://supermarket.chef.io/cookbooks/compat_resource)\n\nThis cookbook backports functionality introduced in the latest chef-client releases to any chef-client from 12.1 onwards. This includes [Custom Resource](https://docs.chef.io/custom_resources.html) functionality, notification improvements, as well as new resources added to core chef. It allows for the usage of these new resources in cookbooks without requiring the very latest Chef client release.\n\n## Backported functionality\n\n- [Custom Resources](https://docs.chef.io/custom_resources.html)\n- [apt_repository](https://docs.chef.io/resource_apt_repository.html)\n- [apt_update](https://docs.chef.io/resource_apt_update.html)\n- [systemd_unit](https://docs.chef.io/resource_systemd_unit.html)\n- [yum_repository](https://docs.chef.io/resource_yum_repository.html)\n- [:before notifications](https://docs.chef.io/resources.html#timers)\n\n## Requirements\n\n### Platforms\n\n- All platforms supported by Chef\n\n### Chef\n\n- Chef 12.1+\n\n### Cookbooks\n\n- none\n\n## Usage\n\nTo use this cookbook, put `depends 'compat_resource'` in the metadata.rb of your cookbook. Once this is done, you can use all the new custom resource features to define resources. It Just Works.\n\n## Custom Resources?\n\nCurious about how to use custom resources?\n\n- Docs: <https://docs.chef.io/custom_resources.html>\n- Slides: <https://docs.chef.io/decks/custom_resources.html>\n\n## License & Authors\n\n- Author:: Lamont Granquist ([lamont@chef.io](mailto:lamont@chef.io))\n- Author:: John Keiser ([jkeiser@chef.io](mailto:jkeiser@chef.io))\n\n```text\nCopyright:: 2015-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":"Lamont Granquist","maintainer_email":"lamont@chef.io","license":"Apache 2.0","platforms":{},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/chef-cookbooks/compat_resource","issues_url":"https://github.com/chef-cookbooks/compat_resource/issues","chef_version":">= 12.1","ohai_version":{}}
|
@ -22,6 +22,11 @@ end
|
||||
socket = "/var/run/mysql-#{db['instance_name']}/mysqld.sock"
|
||||
|
||||
if node['platform_family'] == 'debian'
|
||||
directory "/var/run/mysqld" do
|
||||
action :create
|
||||
owner "mysql"
|
||||
group "mysql"
|
||||
end
|
||||
link '/var/run/mysqld/mysqld.sock' do
|
||||
to socket
|
||||
not_if 'test -f /var/run/mysqld/mysqld.sock'
|
||||
|
@ -10,7 +10,15 @@
|
||||
include_recipe "apt"
|
||||
|
||||
include_recipe "php::default"
|
||||
include_recipe "php::module_apc"
|
||||
|
||||
if node['platform'] == 'ubuntu' and node['platform_version'] >= '16.04'
|
||||
# APC is now apcu in PHP 7
|
||||
include_recipe "php::module_apcu"
|
||||
# Dependency
|
||||
package "php7.0-mbstring"
|
||||
else
|
||||
include_recipe "php::module_apc"
|
||||
end
|
||||
include_recipe "php::module_mysql"
|
||||
|
||||
include_recipe "mediawiki::database"
|
||||
@ -38,8 +46,11 @@ when "debian"
|
||||
package "libicu-dev"
|
||||
end
|
||||
|
||||
php_pear "intl" do
|
||||
if platform?('ubuntu') && node[:platform_version].to_f < 16.04
|
||||
# bundled with PHP since version 5.3
|
||||
php_pear "intl" do
|
||||
action :install
|
||||
end
|
||||
end
|
||||
|
||||
# Configure mediawiki database
|
||||
|
@ -7,32 +7,7 @@ node.set_unless['php-fpm']['pools'] = []
|
||||
|
||||
include_recipe "php-fpm"
|
||||
include_recipe 'php-fpm::repository' unless node['php-fpm']['skip_repository_install']
|
||||
|
||||
if node['php-fpm']['package_name'].nil?
|
||||
if platform_family?("rhel")
|
||||
php_fpm_package_name = "php-fpm"
|
||||
else
|
||||
php_fpm_package_name = "php5-fpm"
|
||||
end
|
||||
else
|
||||
php_fpm_package_name = node['php-fpm']['package_name']
|
||||
end
|
||||
|
||||
package php_fpm_package_name do
|
||||
action :install
|
||||
end
|
||||
|
||||
if node['php-fpm']['service_name'].nil?
|
||||
php_fpm_service_name = php_fpm_package_name
|
||||
else
|
||||
php_fpm_service_name = node['php-fpm']['service_name']
|
||||
end
|
||||
|
||||
service "php-fpm" do
|
||||
service_name php_fpm_service_name
|
||||
supports :start => true, :stop => true, :restart => true, :reload => true
|
||||
action [ :enable, :start ]
|
||||
end
|
||||
include_recipe "php-fpm::install"
|
||||
|
||||
php_fpm_pool "www" do
|
||||
enable false
|
||||
|
@ -2,6 +2,80 @@
|
||||
|
||||
This file is used to list changes made in each version of the mysql cookbook.
|
||||
|
||||
## 8.3.0 (2017-03-20)
|
||||
- Refactor mysql_service_manager_upstart.rb to eliminate use of cloned resource
|
||||
|
||||
## 8.2.0 (2016-12-03)
|
||||
|
||||
- Include client development packages on RHEL/SUSE platforms
|
||||
|
||||
## 8.1.1 (2016-10-31)
|
||||
- Fixing CVE-2016-6662 - Reverting execure bit on mysql config
|
||||
|
||||
## 8.1.0 (2016-10-29)
|
||||
|
||||
- Drop hardcoded, specific package version logic that broke many users
|
||||
|
||||
## 8.0.4 (2016-09-26)
|
||||
- Bump debian version
|
||||
- Updated packages for 12.04 and 14.04 too
|
||||
- Add chef_version metadata
|
||||
- Update platforms in the kitchen file
|
||||
- Add selinux to the Berksfile for testing
|
||||
- Make sure yum repos are setup in local Test Kitchen
|
||||
|
||||
## 8.0.3 (2016-09-14)
|
||||
- [GH-390] Fix #390 incorrect escaping of initial_root_password
|
||||
- Updated package versions for Ubuntu 16.04
|
||||
- Testing updates
|
||||
|
||||
# v8.0.2 (2016-08-25)
|
||||
- Various bug fixed and updates to package version strings
|
||||
|
||||
# v8.0.1 (2016-07-20)
|
||||
- Fixed a regression in the mysql_client resource where the action was changed from create to install in the 8.0 release
|
||||
- Added oracle, opensuse, and opensuseleap as supported platforms in the metadata
|
||||
|
||||
# v8.0.0 (2016-07-11)
|
||||
|
||||
- Converting from LWRP to custom resources
|
||||
- Removing yum-mysql and other dependencies.
|
||||
- ^ BREAKING CHANGE: RHELish users are now responsible
|
||||
for including a recipe from the "yum-mysql" or equivalent
|
||||
cookbook before utilizing the mysql_* resources.
|
||||
- More thoughtful ChefSpec
|
||||
- Renaming "replication" test suite to "smoke"
|
||||
- Moving to Inspec
|
||||
|
||||
## v7.2.0 (2016-06-30)
|
||||
|
||||
- Support openeSUSE leap
|
||||
- Support Fedora 24
|
||||
|
||||
## v7.1.2 (2016-06-30)
|
||||
|
||||
- Avoid deprecation warnings on the upcoming Chef 12.12 release
|
||||
|
||||
## v7.1.1 (2016-06-03)
|
||||
|
||||
- Fix apparmor blocking writes to non-default tmp_dirs
|
||||
- Updated apparmor config to allow read & write to sock.lock file
|
||||
- Use cookstyle instead of Rubocop directly
|
||||
|
||||
## v7.1.0 (2016-05-11)
|
||||
|
||||
- Added support for Ubuntu 16.04
|
||||
|
||||
## v7.0.0 (2016-04-19)
|
||||
|
||||
- Removed support for legacy distros: Ubuntu 10.04/13.04/14.10/15.04, Fedora 20/21, OmniOS r151006, opensuse 11.3/12.0
|
||||
- Added support for Fedora 23, suse 13.X, and Ubuntu 16.04
|
||||
- Updated the systemd support to create unit files in /etc/systemd and not /usr/lib/systemd
|
||||
- Adding umask to bash resource that sets root password PR #386 @gziskind
|
||||
- Cleaned up the Test Kitchen config to test the right platform version + mysql pairings
|
||||
- Added Travis CI Test Kitchen testing on Fedora 22/23 and removed Fedora 21
|
||||
- Updated the platforms used in the specs
|
||||
|
||||
## v6.1.3 (2016-03-14)
|
||||
|
||||
- Added support for Ubuntu 15.10
|
||||
|
@ -1,13 +1,10 @@
|
||||
<!-- This is a generated file. Please do not edit directly -->
|
||||
|
||||
# Maintainers
|
||||
This file lists how this cookbook project is maintained. When making changes to the system, this
|
||||
file tells you who needs to review your patch - you need a simple majority of maintainers
|
||||
for the relevant subsystems to provide a :+1: on your pull request. Additionally, you need
|
||||
to not receive a veto from a Lieutenant or the Project Lead.
|
||||
|
||||
Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD)
|
||||
for details on the process and how to become a maintainer or the project lead.
|
||||
This file lists how this cookbook project is maintained. When making changes to the system, this file tells you who needs to review your patch - you need a review from an existing maintainer for the cookbook to provide a :+1: on your pull request. Additionally, you need to not receive a veto from a Lieutenant or the Project Lead.
|
||||
|
||||
Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) for details on the process and how to become a maintainer or the project lead.
|
||||
|
||||
# Project Maintainer
|
||||
* [Tim Smith](https://github.com/tas50)
|
||||
|
@ -2,16 +2,15 @@
|
||||
|
||||
[](https://travis-ci.org/chef-cookbooks/mysql) [](https://supermarket.chef.io/cookbooks/mysql)
|
||||
|
||||
The Mysql Cookbook is a library cookbook that provides resource primitives (LWRPs) for use in recipes. It is designed to be a reference example for creating highly reusable cross-platform cookbooks.
|
||||
The MySQL Cookbook is a library cookbook that provides resource primitives (LWRPs) for use in recipes. It is designed to be a reference example for creating highly reusable cross-platform cookbooks.
|
||||
|
||||
## Scope
|
||||
|
||||
This cookbook is concerned with the "MySQL Community Server", particularly those shipped with F/OSS Unix and Linux distributions. It does not address forks or value-added repackaged MySQL distributions like Drizzle, MariaDB, or Percona.
|
||||
This cookbook is concerned with the "MySQL Community Server", particularly those shipped with F/OSS Unix and Linux distributions. It does not address forks or value-added repackaged MySQL distributions like MariaDB or Percona.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Chef 11 or higher
|
||||
- Ruby 1.9 or higher (preferably from the Chef full-stack installer)
|
||||
- Chef 12.5 or higher
|
||||
- Network accessible package repositories
|
||||
- 'recipe[selinux::disabled]' on RHEL platforms
|
||||
|
||||
@ -20,42 +19,39 @@ This cookbook is concerned with the "MySQL Community Server", particularly those
|
||||
The following platforms have been tested with Test Kitchen:
|
||||
|
||||
```
|
||||
|----------------+-----+-----+-----+-----+-----|
|
||||
| | 5.0 | 5.1 | 5.5 | 5.6 | 5.7 |
|
||||
|----------------+-----+-----+-----+-----+-----|
|
||||
| debian-7 | | | X | | |
|
||||
|----------------+-----+-----+-----+-----+-----|
|
||||
| ubuntu-12.04 | | | X | | |
|
||||
|----------------+-----+-----+-----+-----+-----|
|
||||
| ubuntu-14.04 | | | X | X | |
|
||||
|----------------+-----+-----+-----+-----+-----|
|
||||
| ubuntu-15.04 | | | | X | |
|
||||
|----------------+-----+-----+-----+-----+-----|
|
||||
| centos-5 | X | X | X | X | X |
|
||||
|----------------+-----+-----+-----+-----+-----|
|
||||
| centos-6 | | X | X | X | X |
|
||||
|----------------+-----+-----+-----+-----+-----|
|
||||
| centos-7 | | | X | X | X |
|
||||
|----------------+-----+-----+-----+-----+-----|
|
||||
| amazon | | | X | X | X |
|
||||
|----------------+-----+-----+-----+-----+-----|
|
||||
| fedora-22 | | | X | X | X |
|
||||
|----------------+-----+-----+-----+-----+-----|
|
||||
| fedora-23 | | | X | X | X |
|
||||
|----------------+-----+-----+-----+-----+-----|
|
||||
|----------------+-----+-----+-----+-----|
|
||||
| | 5.1 | 5.5 | 5.6 | 5.7 |
|
||||
|----------------+-----+-----+-----+-----|
|
||||
| debian-7 | | X | | |
|
||||
|----------------+-----+-----+-----+-----|
|
||||
| debian-8 | | X | | |
|
||||
|----------------+-----+-----+-----+-----|
|
||||
| ubuntu-14.04 | | X | X | |
|
||||
|----------------+-----+-----+-----+-----|
|
||||
| ubuntu-16.04 | | | | X |
|
||||
|----------------+-----+-----+-----+-----|
|
||||
| centos-6 | X | X | X | X |
|
||||
|----------------+-----+-----+-----+-----|
|
||||
| centos-7 | | X | X | X |
|
||||
|----------------+-----+-----+-----+-----|
|
||||
| fedora | | | X | X |
|
||||
|----------------+-----+-----+-----+-----|
|
||||
| openSUSE 13.2 | | | X | |
|
||||
|----------------+-----+-----+-----+-----|
|
||||
| openSUSE Leap | | | X | |
|
||||
|----------------+-----+-----+-----+-----|
|
||||
```
|
||||
|
||||
## Cookbook Dependencies
|
||||
|
||||
- yum-mysql-community
|
||||
- smf
|
||||
There are no hard coupled dependencies. However, there is a loose dependency on `yum-mysql-community` for RHEL/CentOS platforms. As of the 8.0 version of this cookbook, configuration of the package repos is now the responsibility of the user.
|
||||
|
||||
## Usage
|
||||
|
||||
Place a dependency on the mysql cookbook in your cookbook's metadata.rb
|
||||
|
||||
```ruby
|
||||
depends 'mysql', '~> 6.0'
|
||||
depends 'mysql', '~> 8.0'
|
||||
```
|
||||
|
||||
Then, in a recipe:
|
||||
@ -274,7 +270,7 @@ mysql_client 'default' do
|
||||
end
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
#### Properties
|
||||
|
||||
- `package_name` - An array of packages to be installed. Defaults to a value looked up in an internal map.
|
||||
- `package_version` - Specific versions of the package to install, passed onto the underlying package manager. Defaults to `nil`.
|
||||
@ -401,31 +397,16 @@ Or to connect over the network, use something like this: connect over the networ
|
||||
|
||||
These network or socket ssettings can also be put in you $HOME/.my.cnf, if preferred.
|
||||
|
||||
### What about MariaDB, Percona, Drizzle, WebScaleSQL, etc.
|
||||
### What about MariaDB, Percona, etc.
|
||||
|
||||
MySQL forks are purposefully out of scope for this cookbook. This is mostly to reduce the testing matrix to a manageable size. Cookbooks for these technologies can easily be created by copying and adapting this cookbook. However, there will be differences.
|
||||
|
||||
Package repository locations, package version names, software major version numbers, supported platform matrices, and the availability of software such as XtraDB and Galera are the main reasons that creating multiple cookbooks to make sense.
|
||||
|
||||
## Warnings
|
||||
|
||||
## Hacking / Testing / TODO
|
||||
|
||||
Please refer to the HACKING.md
|
||||
|
||||
## License & Authors
|
||||
|
||||
- Author:: Joshua Timberman ([joshua@chef.io](mailto:joshua@chef.io))
|
||||
- Author:: AJ Christensen ([aj@chef.io](mailto:aj@chef.io))
|
||||
- Author:: Seth Chisamore ([schisamo@chef.io](mailto:schisamo@chef.io))
|
||||
- Author:: Brian Bianco ([brian.bianco@gmail.com](mailto:brian.bianco@gmail.com))
|
||||
- Author:: Jesse Howarth ([him@jessehowarth.com](mailto:him@jessehowarth.com))
|
||||
- Author:: Andrew Crump ([andrew@kotirisoftware.com](mailto:andrew@kotirisoftware.com))
|
||||
- Author:: Christoph Hartmann ([chris@lollyrock.com](mailto:chris@lollyrock.com))
|
||||
- Author:: Sean OMeara ([sean@chef.io](mailto:sean@chef.io))
|
||||
## License
|
||||
|
||||
```text
|
||||
Copyright:: 2009-2014 Chef Software, Inc
|
||||
Copyright:: 2009-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.
|
||||
|
@ -1,67 +1,120 @@
|
||||
require 'shellwords'
|
||||
|
||||
module MysqlCookbook
|
||||
module Helpers
|
||||
include Chef::DSL::IncludeRecipe
|
||||
module HelpersBase
|
||||
require 'shellwords'
|
||||
|
||||
def base_dir
|
||||
prefix_dir || '/usr'
|
||||
def el6?
|
||||
return true if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 6
|
||||
false
|
||||
end
|
||||
|
||||
def configure_package_repositories
|
||||
# we need to enable the yum-mysql-community repository to get packages
|
||||
return unless %w(rhel fedora).include? node['platform_family']
|
||||
case parsed_version
|
||||
when '5.5'
|
||||
# Prefer packages from native repos
|
||||
return if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 5
|
||||
return if node['platform_family'] == 'fedora'
|
||||
include_recipe('yum-mysql-community::mysql55')
|
||||
when '5.6'
|
||||
include_recipe('yum-mysql-community::mysql56')
|
||||
when '5.7'
|
||||
include_recipe('yum-mysql-community::mysql57')
|
||||
end
|
||||
def el7?
|
||||
return true if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 7
|
||||
false
|
||||
end
|
||||
|
||||
def client_package_name
|
||||
return new_resource.package_name if new_resource.package_name
|
||||
client_package
|
||||
def wheezy?
|
||||
return true if node['platform'] == 'debian' && node['platform_version'].to_i == 7
|
||||
false
|
||||
end
|
||||
|
||||
def jessie?
|
||||
return true if node['platform'] == 'debian' && node['platform_version'].to_i == 8
|
||||
false
|
||||
end
|
||||
|
||||
def precise?
|
||||
return true if node['platform'] == 'ubuntu' && node['platform_version'] == '12.04'
|
||||
false
|
||||
end
|
||||
|
||||
def trusty?
|
||||
return true if node['platform'] == 'ubuntu' && node['platform_version'] == '14.04'
|
||||
return true if node['platform'] == 'linuxmint' && node['platform_version'] =~ /^17\.[0-9]$/
|
||||
false
|
||||
end
|
||||
|
||||
def xenial?
|
||||
return true if node['platform'] == 'ubuntu' && node['platform_version'] == '16.04'
|
||||
false
|
||||
end
|
||||
|
||||
def defaults_file
|
||||
"#{etc_dir}/my.cnf"
|
||||
end
|
||||
|
||||
def error_log
|
||||
return new_resource.error_log if new_resource.error_log
|
||||
def default_data_dir
|
||||
return "/var/lib/#{mysql_name}" if node['os'] == 'linux'
|
||||
return "/opt/local/lib/#{mysql_name}" if node['os'] == 'solaris2'
|
||||
return "/var/db/#{mysql_name}" if node['os'] == 'freebsd'
|
||||
end
|
||||
|
||||
def default_error_log
|
||||
"#{log_dir}/error.log"
|
||||
end
|
||||
|
||||
def etc_dir
|
||||
return "/opt/mysql#{pkg_ver_string}/etc/#{mysql_name}" if node['platform_family'] == 'omnios'
|
||||
return "#{prefix_dir}/etc/#{mysql_name}" if node['platform_family'] == 'smartos'
|
||||
"#{prefix_dir}/etc/#{mysql_name}"
|
||||
def default_pid_file
|
||||
"#{run_dir}/mysqld.pid"
|
||||
end
|
||||
|
||||
def include_dir
|
||||
"#{etc_dir}/conf.d"
|
||||
def default_major_version
|
||||
# rhelish
|
||||
return '5.1' if el6?
|
||||
return '5.6' if el7?
|
||||
return '5.5' if node['platform'] == 'amazon'
|
||||
|
||||
# debian
|
||||
return '5.5' if wheezy?
|
||||
return '5.5' if jessie?
|
||||
|
||||
# ubuntu
|
||||
return '5.5' if precise?
|
||||
return '5.5' if trusty?
|
||||
return '5.7' if xenial?
|
||||
|
||||
# misc
|
||||
return '5.6' if node['platform'] == 'freebsd'
|
||||
return '5.6' if node['platform'] == 'fedora'
|
||||
return '5.6' if node['platform_family'] == 'suse'
|
||||
end
|
||||
|
||||
def lc_messages_dir
|
||||
end
|
||||
|
||||
def log_dir
|
||||
return "/var/adm/log/#{mysql_name}" if node['platform_family'] == 'omnios'
|
||||
"#{prefix_dir}/var/log/#{mysql_name}"
|
||||
def major_from_full(v)
|
||||
v.split('.').shift(2).join('.')
|
||||
end
|
||||
|
||||
def mysql_name
|
||||
"mysql-#{new_resource.instance}"
|
||||
"mysql-#{instance}"
|
||||
end
|
||||
|
||||
def pkg_ver_string
|
||||
parsed_version.delete('.') if node['platform_family'] == 'omnios'
|
||||
def default_socket_file
|
||||
"#{run_dir}/mysqld.sock"
|
||||
end
|
||||
|
||||
def default_client_package_name
|
||||
return ['mysql', 'mysql-devel'] if major_version == '5.1' && el6?
|
||||
return ['mysql-client-5.5', 'libmysqlclient-dev'] if major_version == '5.5' && node['platform_family'] == 'debian'
|
||||
return ['mysql-client-5.6', 'libmysqlclient-dev'] if major_version == '5.6' && node['platform_family'] == 'debian'
|
||||
return ['mysql-client-5.7', 'libmysqlclient-dev'] if major_version == '5.7' && node['platform_family'] == 'debian'
|
||||
return 'mysql-community-server-client' if major_version == '5.6' && node['platform_family'] == 'suse'
|
||||
['mysql-community-client', 'mysql-community-devel']
|
||||
end
|
||||
|
||||
def default_server_package_name
|
||||
return 'mysql-server' if major_version == '5.1' && el6?
|
||||
return 'mysql-server-5.5' if major_version == '5.5' && node['platform_family'] == 'debian'
|
||||
return 'mysql-server-5.6' if major_version == '5.6' && node['platform_family'] == 'debian'
|
||||
return 'mysql-server-5.7' if major_version == '5.7' && node['platform_family'] == 'debian'
|
||||
return 'mysql-community-server' if major_version == '5.6' && node['platform_family'] == 'suse'
|
||||
'mysql-community-server'
|
||||
end
|
||||
|
||||
def socket_dir
|
||||
File.dirname(socket)
|
||||
end
|
||||
|
||||
def run_dir
|
||||
return "#{prefix_dir}/var/run/#{mysql_name}" if node['platform_family'] == 'rhel'
|
||||
return "/run/#{mysql_name}" if node['platform_family'] == 'debian'
|
||||
"/var/run/#{mysql_name}"
|
||||
end
|
||||
|
||||
def prefix_dir
|
||||
@ -72,102 +125,70 @@ module MysqlCookbook
|
||||
|
||||
def scl_name
|
||||
return unless node['platform_family'] == 'rhel'
|
||||
return 'mysql51' if parsed_version == '5.1' && node['platform_version'].to_i == 5
|
||||
return 'mysql55' if parsed_version == '5.5' && node['platform_version'].to_i == 5
|
||||
return 'mysql51' if version == '5.1' && node['platform_version'].to_i == 5
|
||||
return 'mysql55' if version == '5.5' && node['platform_version'].to_i == 5
|
||||
end
|
||||
|
||||
def scl_package?
|
||||
return unless node['platform_family'] == 'rhel'
|
||||
return true if parsed_version == '5.1' && node['platform_version'].to_i == 5
|
||||
return true if parsed_version == '5.5' && node['platform_version'].to_i == 5
|
||||
return true if version == '5.1' && node['platform_version'].to_i == 5
|
||||
return true if version == '5.5' && node['platform_version'].to_i == 5
|
||||
false
|
||||
end
|
||||
|
||||
def etc_dir
|
||||
return "/opt/mysql#{pkg_ver_string}/etc/#{mysql_name}" if node['platform_family'] == 'omnios'
|
||||
return "#{prefix_dir}/etc/#{mysql_name}" if node['platform_family'] == 'smartos'
|
||||
"#{prefix_dir}/etc/#{mysql_name}"
|
||||
end
|
||||
|
||||
def base_dir
|
||||
prefix_dir || '/usr'
|
||||
end
|
||||
|
||||
def system_service_name
|
||||
return 'mysql51-mysqld' if node['platform_family'] == 'rhel' && scl_name == 'mysql51'
|
||||
return 'mysql55-mysqld' if node['platform_family'] == 'rhel' && scl_name == 'mysql55'
|
||||
return 'mysqld' if node['platform_family'] == 'rhel'
|
||||
return 'mysqld' if node['platform_family'] == 'fedora'
|
||||
return 'mysql' if node['platform_family'] == 'debian'
|
||||
return 'mysql' if node['platform_family'] == 'suse'
|
||||
return 'mysql' if node['platform_family'] == 'omnios'
|
||||
return 'mysql' if node['platform_family'] == 'smartos'
|
||||
'mysql' # not one of the above
|
||||
end
|
||||
|
||||
def v56plus
|
||||
return false if parsed_version.split('.')[0].to_i < 5
|
||||
return false if parsed_version.split('.')[1].to_i < 6
|
||||
return false if version.split('.')[0].to_i < 5
|
||||
return false if version.split('.')[1].to_i < 6
|
||||
true
|
||||
end
|
||||
|
||||
def v57plus
|
||||
return false if parsed_version.split('.')[0].to_i < 5
|
||||
return false if parsed_version.split('.')[1].to_i < 7
|
||||
return false if version.split('.')[0].to_i < 5
|
||||
return false if version.split('.')[1].to_i < 7
|
||||
true
|
||||
end
|
||||
|
||||
def password_column_name
|
||||
return 'authentication_string' if v57plus
|
||||
'password'
|
||||
def default_include_dir
|
||||
"#{etc_dir}/conf.d"
|
||||
end
|
||||
|
||||
def password_expired
|
||||
return ", password_expired='N'" if v57plus
|
||||
''
|
||||
def log_dir
|
||||
return "/var/adm/log/#{mysql_name}" if node['platform_family'] == 'omnios'
|
||||
"#{prefix_dir}/var/log/#{mysql_name}"
|
||||
end
|
||||
|
||||
def root_password
|
||||
if new_resource.initial_root_password == ''
|
||||
Chef::Log.info('Root password is empty')
|
||||
return ''
|
||||
end
|
||||
Shellwords.escape(new_resource.initial_root_password)
|
||||
end
|
||||
|
||||
# database and initial records
|
||||
# initialization commands
|
||||
|
||||
def mysqld_initialize_cmd
|
||||
cmd = mysqld_bin
|
||||
cmd << " --defaults-file=#{etc_dir}/my.cnf"
|
||||
cmd << ' --initialize'
|
||||
cmd << ' --explicit_defaults_for_timestamp' if v56plus
|
||||
return "scl enable #{scl_name} \"#{cmd}\"" if scl_package?
|
||||
cmd
|
||||
end
|
||||
|
||||
def mysql_install_db_cmd
|
||||
cmd = mysql_install_db_bin
|
||||
cmd << " --defaults-file=#{etc_dir}/my.cnf"
|
||||
cmd << " --datadir=#{parsed_data_dir}"
|
||||
cmd << ' --explicit_defaults_for_timestamp' if v56plus
|
||||
return "scl enable #{scl_name} \"#{cmd}\"" if scl_package?
|
||||
cmd
|
||||
end
|
||||
|
||||
def record_init
|
||||
cmd = v56plus ? mysqld_bin : mysqld_safe_bin
|
||||
cmd << " --defaults-file=#{etc_dir}/my.cnf"
|
||||
cmd << " --init-file=/tmp/#{mysql_name}/my.sql"
|
||||
cmd << ' --explicit_defaults_for_timestamp' if v56plus
|
||||
cmd << ' &'
|
||||
return "scl enable #{scl_name} \"#{cmd}\"" if scl_package?
|
||||
cmd
|
||||
end
|
||||
|
||||
def db_init
|
||||
return mysqld_initialize_cmd if v57plus
|
||||
mysql_install_db_cmd
|
||||
end
|
||||
def lc_messages_dir; end
|
||||
|
||||
def init_records_script
|
||||
# Note: shell-escaping passwords in a SQL file may cause corruption - eg
|
||||
# mysql will read \& as &, but \% as \%. Just escape bare-minimum \ and '
|
||||
sql_escaped_password = root_password.gsub('\\') { '\\\\' }.gsub("'") { '\\\'' }
|
||||
|
||||
<<-EOS
|
||||
set -e
|
||||
rm -rf /tmp/#{mysql_name}
|
||||
mkdir /tmp/#{mysql_name}
|
||||
|
||||
cat > /tmp/#{mysql_name}/my.sql <<-EOSQL
|
||||
UPDATE mysql.user SET #{password_column_name}=PASSWORD('#{root_password}')#{password_expired} WHERE user = 'root';
|
||||
cat > /tmp/#{mysql_name}/my.sql <<-'EOSQL'
|
||||
UPDATE mysql.user SET #{password_column_name}=PASSWORD('#{sql_escaped_password}')#{password_expired} WHERE user = 'root';
|
||||
DELETE FROM mysql.user WHERE USER LIKE '';
|
||||
DELETE FROM mysql.user WHERE user = 'root' and host NOT IN ('127.0.0.1', 'localhost');
|
||||
FLUSH PRIVILEGES;
|
||||
@ -185,10 +206,27 @@ EOSQL
|
||||
EOS
|
||||
end
|
||||
|
||||
def mysql_bin
|
||||
return "#{prefix_dir}/bin/mysql" if node['platform_family'] == 'smartos'
|
||||
return "#{base_dir}/bin/mysql" if node['platform_family'] == 'omnios'
|
||||
"#{prefix_dir}/usr/bin/mysql"
|
||||
def password_column_name
|
||||
return 'authentication_string' if v57plus
|
||||
'password'
|
||||
end
|
||||
|
||||
def root_password
|
||||
if initial_root_password == ''
|
||||
Chef::Log.info('Root password is empty')
|
||||
return ''
|
||||
end
|
||||
initial_root_password
|
||||
end
|
||||
|
||||
def password_expired
|
||||
return ", password_expired='N'" if v57plus
|
||||
''
|
||||
end
|
||||
|
||||
def db_init
|
||||
return mysqld_initialize_cmd if v57plus
|
||||
mysql_install_db_cmd
|
||||
end
|
||||
|
||||
def mysql_install_db_bin
|
||||
@ -197,8 +235,13 @@ EOSQL
|
||||
'mysql_install_db'
|
||||
end
|
||||
|
||||
def mysql_version
|
||||
new_resource.version
|
||||
def mysql_install_db_cmd
|
||||
cmd = mysql_install_db_bin
|
||||
cmd << " --defaults-file=#{etc_dir}/my.cnf"
|
||||
cmd << " --datadir=#{data_dir}"
|
||||
cmd << ' --explicit_defaults_for_timestamp' if v56plus && !v57plus
|
||||
return "scl enable #{scl_name} \"#{cmd}\"" if scl_package?
|
||||
cmd
|
||||
end
|
||||
|
||||
def mysqladmin_bin
|
||||
@ -216,6 +259,15 @@ EOSQL
|
||||
"#{prefix_dir}/usr/sbin/mysqld"
|
||||
end
|
||||
|
||||
def mysqld_initialize_cmd
|
||||
cmd = mysqld_bin
|
||||
cmd << " --defaults-file=#{etc_dir}/my.cnf"
|
||||
cmd << ' --initialize'
|
||||
cmd << ' --explicit_defaults_for_timestamp' if v56plus
|
||||
return "scl enable #{scl_name} \"#{cmd}\"" if scl_package?
|
||||
cmd
|
||||
end
|
||||
|
||||
def mysqld_safe_bin
|
||||
return "#{prefix_dir}/bin/mysqld_safe" if node['platform_family'] == 'smartos'
|
||||
return "#{base_dir}/bin/mysqld_safe" if node['platform_family'] == 'omnios'
|
||||
@ -223,248 +275,18 @@ EOSQL
|
||||
"#{prefix_dir}/usr/bin/mysqld_safe"
|
||||
end
|
||||
|
||||
def pid_file
|
||||
return new_resource.pid_file if new_resource.pid_file
|
||||
"#{run_dir}/mysqld.pid"
|
||||
end
|
||||
|
||||
def run_dir
|
||||
return "#{prefix_dir}/var/run/#{mysql_name}" if node['platform_family'] == 'rhel'
|
||||
return "/run/#{mysql_name}" if node['platform_family'] == 'debian'
|
||||
"/var/run/#{mysql_name}"
|
||||
def record_init
|
||||
cmd = v56plus ? mysqld_bin : mysqld_safe_bin
|
||||
cmd << " --defaults-file=#{etc_dir}/my.cnf"
|
||||
cmd << " --init-file=/tmp/#{mysql_name}/my.sql"
|
||||
cmd << ' --explicit_defaults_for_timestamp' if v56plus
|
||||
cmd << ' &'
|
||||
return "scl enable #{scl_name} \"#{cmd}\"" if scl_package?
|
||||
cmd
|
||||
end
|
||||
|
||||
def sensitive_supported?
|
||||
Gem::Version.new(Chef::VERSION) >= Gem::Version.new('11.14.0')
|
||||
end
|
||||
|
||||
def socket_file
|
||||
return new_resource.socket if new_resource.socket
|
||||
"#{run_dir}/mysqld.sock"
|
||||
end
|
||||
|
||||
def socket_dir
|
||||
return File.dirname(new_resource.socket) if new_resource.socket
|
||||
run_dir
|
||||
end
|
||||
|
||||
def tmp_dir
|
||||
return new_resource.tmp_dir if new_resource.tmp_dir
|
||||
'/tmp'
|
||||
end
|
||||
|
||||
#######
|
||||
# FIXME: There is a LOT of duplication here..
|
||||
# There has to be a less gnarly way to look up this information. Refactor for great good!
|
||||
#######
|
||||
class Pkginfo
|
||||
def self.pkginfo
|
||||
# Autovivification is Perl.
|
||||
@pkginfo = Chef::Node.new
|
||||
|
||||
@pkginfo.set['debian']['10.04']['5.1']['client_package'] = %w(mysql-client-5.1 libmysqlclient-dev)
|
||||
@pkginfo.set['debian']['10.04']['5.1']['server_package'] = 'mysql-server-5.1'
|
||||
@pkginfo.set['debian']['12.04']['5.5']['client_package'] = %w(mysql-client-5.5 libmysqlclient-dev)
|
||||
@pkginfo.set['debian']['12.04']['5.5']['server_package'] = 'mysql-server-5.5'
|
||||
@pkginfo.set['debian']['13.04']['5.5']['client_package'] = %w(mysql-client-5.5 libmysqlclient-dev)
|
||||
@pkginfo.set['debian']['13.04']['5.5']['server_package'] = 'mysql-server-5.5'
|
||||
@pkginfo.set['debian']['13.10']['5.5']['client_package'] = %w(mysql-client-5.5 libmysqlclient-dev)
|
||||
@pkginfo.set['debian']['13.10']['5.5']['server_package'] = 'mysql-server-5.5'
|
||||
@pkginfo.set['debian']['14.04']['5.5']['client_package'] = %w(mysql-client-5.5 libmysqlclient-dev)
|
||||
@pkginfo.set['debian']['14.04']['5.5']['server_package'] = 'mysql-server-5.5'
|
||||
@pkginfo.set['debian']['14.04']['5.6']['client_package'] = %w(mysql-client-5.6 libmysqlclient-dev)
|
||||
@pkginfo.set['debian']['14.04']['5.6']['server_package'] = 'mysql-server-5.6'
|
||||
@pkginfo.set['debian']['14.10']['5.5']['client_package'] = %w(mysql-client-5.5 libmysqlclient-dev)
|
||||
@pkginfo.set['debian']['14.10']['5.5']['server_package'] = 'mysql-server-5.5'
|
||||
@pkginfo.set['debian']['14.10']['5.6']['client_package'] = %w(mysql-client-5.6 libmysqlclient-dev)
|
||||
@pkginfo.set['debian']['14.10']['5.6']['server_package'] = 'mysql-server-5.6'
|
||||
@pkginfo.set['debian']['15.04']['5.6']['client_package'] = %w(mysql-client-5.6 libmysqlclient-dev)
|
||||
@pkginfo.set['debian']['15.04']['5.6']['server_package'] = 'mysql-server-5.6'
|
||||
@pkginfo.set['debian']['15.10']['5.6']['client_package'] = %w(mysql-client-5.6 libmysqlclient-dev)
|
||||
@pkginfo.set['debian']['15.10']['5.6']['server_package'] = 'mysql-server-5.6'
|
||||
@pkginfo.set['debian']['6']['5.1']['client_package'] = %w(mysql-client libmysqlclient-dev)
|
||||
@pkginfo.set['debian']['6']['5.1']['server_package'] = 'mysql-server-5.1'
|
||||
@pkginfo.set['debian']['7']['5.5']['client_package'] = %w(mysql-client libmysqlclient-dev)
|
||||
@pkginfo.set['debian']['7']['5.5']['server_package'] = 'mysql-server-5.5'
|
||||
@pkginfo.set['debian']['7']['5.6']['client_package'] = %w(mysql-client libmysqlclient-dev) # apt-repo from dotdeb
|
||||
@pkginfo.set['debian']['7']['5.6']['server_package'] = 'mysql-server-5.6'
|
||||
@pkginfo.set['debian']['7']['5.7']['client_package'] = %w(mysql-client libmysqlclient-dev) # apt-repo from dotdeb
|
||||
@pkginfo.set['debian']['7']['5.7']['server_package'] = 'mysql-server-5.7'
|
||||
@pkginfo.set['debian']['8']['5.5']['client_package'] = %w(mysql-client libmysqlclient-dev)
|
||||
@pkginfo.set['debian']['8']['5.5']['server_package'] = 'mysql-server-5.5'
|
||||
@pkginfo.set['fedora']['20']['5.5']['client_package'] = %w(community-mysql community-mysql-devel)
|
||||
@pkginfo.set['fedora']['20']['5.5']['server_package'] = 'community-mysql-server'
|
||||
@pkginfo.set['fedora']['20']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['fedora']['20']['5.6']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['fedora']['20']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['fedora']['20']['5.7']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['fedora']['21']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['fedora']['21']['5.6']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['fedora']['21']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['fedora']['21']['5.7']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['fedora']['22']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['fedora']['22']['5.6']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['fedora']['22']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['fedora']['22']['5.7']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['freebsd']['10']['5.5']['client_package'] = %w(mysql55-client)
|
||||
@pkginfo.set['freebsd']['10']['5.5']['server_package'] = 'mysql55-server'
|
||||
@pkginfo.set['freebsd']['9']['5.5']['client_package'] = %w(mysql55-client)
|
||||
@pkginfo.set['freebsd']['9']['5.5']['server_package'] = 'mysql55-server'
|
||||
@pkginfo.set['omnios']['151006']['5.5']['client_package'] = %w(database/mysql-55/library)
|
||||
@pkginfo.set['omnios']['151006']['5.5']['server_package'] = 'database/mysql-55'
|
||||
@pkginfo.set['omnios']['151006']['5.6']['client_package'] = %w(database/mysql-56)
|
||||
@pkginfo.set['omnios']['151006']['5.6']['server_package'] = 'database/mysql-56'
|
||||
@pkginfo.set['rhel']['2014.09']['5.1']['server_package'] = %w(mysql51 mysql51-devel)
|
||||
@pkginfo.set['rhel']['2014.09']['5.1']['server_package'] = 'mysql51-server'
|
||||
@pkginfo.set['rhel']['2014.09']['5.5']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['2014.09']['5.5']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['2014.09']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['2014.09']['5.6']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['2014.09']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['2014.09']['5.7']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['2015.03']['5.1']['server_package'] = %w(mysql51 mysql51-devel)
|
||||
@pkginfo.set['rhel']['2015.03']['5.1']['server_package'] = 'mysql51-server'
|
||||
@pkginfo.set['rhel']['2015.03']['5.5']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['2015.03']['5.5']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['2015.03']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['2015.03']['5.6']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['2015.03']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['2015.03']['5.7']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['2015.09']['5.1']['server_package'] = %w(mysql51 mysql51-devel)
|
||||
@pkginfo.set['rhel']['2015.09']['5.1']['server_package'] = 'mysql51-server'
|
||||
@pkginfo.set['rhel']['2015.09']['5.5']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['2015.09']['5.5']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['2015.09']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['2015.09']['5.6']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['2015.09']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['2015.09']['5.7']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['2016.03']['5.1']['server_package'] = %w(mysql51 mysql51-devel)
|
||||
@pkginfo.set['rhel']['2016.03']['5.1']['server_package'] = 'mysql51-server'
|
||||
@pkginfo.set['rhel']['2016.03']['5.5']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['2016.03']['5.5']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['2016.03']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['2016.03']['5.6']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['2016.03']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['2016.03']['5.7']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['5']['5.0']['client_package'] = %w(mysql mysql-devel)
|
||||
@pkginfo.set['rhel']['5']['5.0']['server_package'] = 'mysql-server'
|
||||
@pkginfo.set['rhel']['5']['5.1']['client_package'] = %w(mysql51-mysql)
|
||||
@pkginfo.set['rhel']['5']['5.1']['server_package'] = 'mysql51-mysql-server'
|
||||
@pkginfo.set['rhel']['5']['5.5']['client_package'] = %w(mysql55-mysql mysql55-mysql-devel)
|
||||
@pkginfo.set['rhel']['5']['5.5']['server_package'] = 'mysql55-mysql-server'
|
||||
@pkginfo.set['rhel']['5']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['5']['5.6']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['5']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['5']['5.7']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['6']['5.1']['client_package'] = %w(mysql mysql-devel)
|
||||
@pkginfo.set['rhel']['6']['5.1']['server_package'] = 'mysql-server'
|
||||
@pkginfo.set['rhel']['6']['5.5']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['6']['5.5']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['6']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['6']['5.6']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['6']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['6']['5.7']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['7']['5.5']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['7']['5.5']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['7']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['7']['5.6']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['rhel']['7']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel)
|
||||
@pkginfo.set['rhel']['7']['5.7']['server_package'] = 'mysql-community-server'
|
||||
@pkginfo.set['smartos']['5.11']['5.5']['client_package'] = %w(mysql-client)
|
||||
@pkginfo.set['smartos']['5.11']['5.5']['server_package'] = 'mysql-server'
|
||||
@pkginfo.set['smartos']['5.11']['5.6']['client_package'] = %w(mysql-client)
|
||||
@pkginfo.set['smartos']['5.11']['5.6']['server_package'] = 'mysql-server'
|
||||
@pkginfo.set['suse']['11.3']['5.5']['client_package'] = %w(mysql-client)
|
||||
@pkginfo.set['suse']['11.3']['5.5']['server_package'] = 'mysql'
|
||||
@pkginfo.set['suse']['12.0']['5.5']['client_package'] = %w(mysql-client)
|
||||
@pkginfo.set['suse']['12.0']['5.5']['server_package'] = 'mysql'
|
||||
|
||||
@pkginfo
|
||||
end
|
||||
end
|
||||
|
||||
def package_name_for(platform, platform_family, platform_version, version, type)
|
||||
keyname = keyname_for(platform, platform_family, platform_version)
|
||||
info = Pkginfo.pkginfo[platform_family.to_sym][keyname]
|
||||
type_label = type.to_s.gsub('_package', '').capitalize
|
||||
unless info[version]
|
||||
# Show availabe versions if the requested is not available on the current platform
|
||||
Chef::Log.error("Unsupported Version: You requested to install a Mysql #{type_label} version that is not supported by your platform")
|
||||
Chef::Log.error("Platform: #{platform_family} #{platform_version} - Request Mysql #{type_label} version: #{version}")
|
||||
Chef::Log.error("Availabe versions for your platform are: #{info.map { |k, _v| k }.join(' - ')}")
|
||||
raise "Unsupported Mysql #{type_label} Version"
|
||||
end
|
||||
info[version][type]
|
||||
end
|
||||
|
||||
def keyname_for(platform, platform_family, platform_version)
|
||||
return platform_version if platform_family == 'debian' && platform == 'ubuntu'
|
||||
return platform_version if platform_family == 'fedora'
|
||||
return platform_version if platform_family == 'omnios'
|
||||
return platform_version if platform_family == 'rhel' && platform == 'amazon'
|
||||
return platform_version if platform_family == 'smartos'
|
||||
return platform_version if platform_family == 'suse'
|
||||
return platform_version.to_i.to_s if platform_family == 'debian'
|
||||
return platform_version.to_i.to_s if platform_family == 'rhel'
|
||||
return platform_version.to_s if platform_family == 'debian' && platform_version =~ /sid$/
|
||||
return platform_version.to_s if platform_family == 'freebsd'
|
||||
end
|
||||
|
||||
def parsed_data_dir
|
||||
return new_resource.data_dir if new_resource.data_dir
|
||||
return "/opt/local/lib/#{mysql_name}" if node['os'] == 'solaris2'
|
||||
return "/var/lib/#{mysql_name}" if node['os'] == 'linux'
|
||||
return "/var/db/#{mysql_name}" if node['os'] == 'freebsd'
|
||||
end
|
||||
|
||||
def client_package
|
||||
package_name_for(
|
||||
node['platform'],
|
||||
node['platform_family'],
|
||||
node['platform_version'],
|
||||
parsed_version,
|
||||
:client_package
|
||||
)
|
||||
end
|
||||
|
||||
def server_package
|
||||
package_name_for(
|
||||
node['platform'],
|
||||
node['platform_family'],
|
||||
node['platform_version'],
|
||||
parsed_version,
|
||||
:server_package
|
||||
)
|
||||
end
|
||||
|
||||
def server_package_name
|
||||
return new_resource.package_name if new_resource.package_name
|
||||
server_package
|
||||
end
|
||||
|
||||
def parsed_version
|
||||
return new_resource.version if new_resource.version
|
||||
return '5.0' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 5
|
||||
return '5.1' if node['platform_family'] == 'debian' && node['platform_version'] == '10.04'
|
||||
return '5.1' if node['platform_family'] == 'debian' && node['platform_version'].to_i == 6
|
||||
return '5.1' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 6
|
||||
return '5.5' if node['platform_family'] == 'debian' && node['platform_version'] == '12.04'
|
||||
return '5.5' if node['platform_family'] == 'debian' && node['platform_version'] == '13.04'
|
||||
return '5.5' if node['platform_family'] == 'debian' && node['platform_version'] == '13.10'
|
||||
return '5.5' if node['platform_family'] == 'debian' && node['platform_version'] == '14.04'
|
||||
return '5.5' if node['platform_family'] == 'debian' && node['platform_version'] == '14.10'
|
||||
return '5.5' if node['platform_family'] == 'debian' && node['platform_version'].to_i == 7
|
||||
return '5.5' if node['platform_family'] == 'debian' && node['platform_version'].to_i == 8
|
||||
return '5.5' if node['platform_family'] == 'freebsd'
|
||||
return '5.5' if node['platform_family'] == 'omnios'
|
||||
return '5.5' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 2014
|
||||
return '5.5' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 2015
|
||||
return '5.5' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 7
|
||||
return '5.5' if node['platform_family'] == 'smartos'
|
||||
return '5.5' if node['platform_family'] == 'suse'
|
||||
return '5.6' if node['platform_family'] == 'fedora'
|
||||
return '5.6' if node['platform_family'] == 'debian' && node['platform_version'] == '15.04'
|
||||
return '5.6' if node['platform_family'] == 'debian' && node['platform_version'] == '15.10'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,18 +1,40 @@
|
||||
if defined?(ChefSpec)
|
||||
if ChefSpec.respond_to?(:define_matcher)
|
||||
# ChefSpec >= 4.1
|
||||
ChefSpec.define_matcher :mysql_config
|
||||
ChefSpec.define_matcher :mysql_service
|
||||
ChefSpec.define_matcher :mysql_client
|
||||
elsif defined?(ChefSpec::Runner) &&
|
||||
ChefSpec::Runner.respond_to?(:define_runner_method)
|
||||
# ChefSpec < 4.1
|
||||
ChefSpec::Runner.define_runner_method :mysql_config
|
||||
ChefSpec::Runner.define_runner_method :mysql_service
|
||||
ChefSpec::Runner.define_runner_method :mysql_client
|
||||
|
||||
# mysql_client_client_installation_package
|
||||
def install_mysql_client_installation_package(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:mysql_client_installation_package, :create, resource_name)
|
||||
end
|
||||
|
||||
# config
|
||||
def remove_mysql_client_installation_package(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:mysql_client_installation_package, :remove, resource_name)
|
||||
end
|
||||
|
||||
# mysql_server_server_installation_package
|
||||
def install_mysql_server_installation_package(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:mysql_server_installation_package, :install, resource_name)
|
||||
end
|
||||
|
||||
def remove_mysql_server_installation_package(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:mysql_server_installation_package, :remove, resource_name)
|
||||
end
|
||||
|
||||
#####
|
||||
# old
|
||||
#####
|
||||
|
||||
# client
|
||||
def create_mysql_client(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:mysql_client, :create, resource_name)
|
||||
end
|
||||
|
||||
def delete_mysql_client(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:mysql_client, :delete, resource_name)
|
||||
end
|
||||
|
||||
# mysql_config
|
||||
def create_mysql_config(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:mysql_config, :create, resource_name)
|
||||
end
|
||||
@ -46,12 +68,4 @@ if defined?(ChefSpec)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:mysql_service, :reload, resource_name)
|
||||
end
|
||||
|
||||
# client
|
||||
def create_mysql_client(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:mysql_client, :create, resource_name)
|
||||
end
|
||||
|
||||
def delete_mysql_client(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:mysql_client, :delete, resource_name)
|
||||
end
|
||||
end
|
||||
|
30
cookbooks/mysql/libraries/mysql_base.rb
Normal file
30
cookbooks/mysql/libraries/mysql_base.rb
Normal file
@ -0,0 +1,30 @@
|
||||
module MysqlCookbook
|
||||
class MysqlBase < Chef::Resource
|
||||
require_relative 'helpers'
|
||||
|
||||
# All resources are composites
|
||||
def whyrun_supported?
|
||||
true
|
||||
end
|
||||
|
||||
################
|
||||
# Type Constants
|
||||
################
|
||||
|
||||
Boolean = property_type(
|
||||
is: [true, false],
|
||||
default: false
|
||||
) unless defined?(Boolean)
|
||||
|
||||
###################
|
||||
# Common Properties
|
||||
###################
|
||||
property :run_group, String, default: 'mysql', desired_state: false
|
||||
property :run_user, String, default: 'mysql', desired_state: false
|
||||
property :version, String, default: lazy { default_major_version }, desired_state: false
|
||||
property :include_dir, String, default: lazy { default_include_dir }, desired_state: false
|
||||
property :major_version, String, default: lazy { major_from_full(version) }, desired_state: false
|
||||
|
||||
declare_action_class
|
||||
end
|
||||
end
|
@ -0,0 +1,31 @@
|
||||
module MysqlCookbook
|
||||
class MysqlClientInstallationPackage < MysqlBase
|
||||
# helper methods
|
||||
require_relative 'helpers'
|
||||
include MysqlCookbook::HelpersBase
|
||||
|
||||
# Resource properties
|
||||
resource_name :mysql_client_installation_package
|
||||
provides :mysql_client_installation, os: 'linux'
|
||||
provides :mysql_client, os: 'linux'
|
||||
|
||||
property :package_name, [String, Array], default: lazy { default_client_package_name }, desired_state: false
|
||||
property :package_options, [String, nil], desired_state: false
|
||||
property :package_version, [String, nil], default: nil, desired_state: false
|
||||
|
||||
# Actions
|
||||
action :create do
|
||||
package package_name do
|
||||
version package_version if package_version
|
||||
options package_options if package_options
|
||||
action :install
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
package package_name do
|
||||
action :remove
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
56
cookbooks/mysql/libraries/mysql_config.rb
Normal file
56
cookbooks/mysql/libraries/mysql_config.rb
Normal file
@ -0,0 +1,56 @@
|
||||
module MysqlCookbook
|
||||
class MysqlConfig < MysqlBase
|
||||
resource_name :mysql_config
|
||||
|
||||
property :config_name, String, name_property: true, desired_state: false
|
||||
property :cookbook, String, desired_state: false
|
||||
property :group, String, default: 'mysql', desired_state: false
|
||||
property :instance, String, default: 'default', desired_state: false
|
||||
property :owner, String, default: 'mysql', desired_state: false
|
||||
property :source, String, desired_state: false
|
||||
property :variables, [Hash], desired_state: false
|
||||
property :version, String, default: lazy { default_major_version }, desired_state: false
|
||||
|
||||
require_relative 'helpers'
|
||||
include MysqlCookbook::HelpersBase
|
||||
|
||||
provides :mysql_config
|
||||
|
||||
action :create do
|
||||
# hax because group property
|
||||
g = Chef::Resource::Group.new(new_resource.group, run_context)
|
||||
g.system true if name == 'mysql'
|
||||
resource_collection.insert g
|
||||
|
||||
user owner do
|
||||
gid owner
|
||||
system true if name == 'mysql'
|
||||
action :create
|
||||
end
|
||||
|
||||
directory include_dir do
|
||||
owner new_resource.owner
|
||||
group new_resource.group
|
||||
mode '0750'
|
||||
recursive true
|
||||
action :create
|
||||
end
|
||||
|
||||
template "#{include_dir}/#{config_name}.cnf" do
|
||||
owner new_resource.owner
|
||||
group new_resource.group
|
||||
mode '0640'
|
||||
variables(new_resource.variables)
|
||||
source new_resource.source
|
||||
cookbook cookbook
|
||||
action :create
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
file "#{include_dir}/#{config_name}.cnf" do
|
||||
action :delete
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,42 @@
|
||||
module MysqlCookbook
|
||||
class MysqlServerInstallationPackage < MysqlBase
|
||||
# Resource properties
|
||||
resource_name :mysql_server_installation_package
|
||||
provides :mysql_server_installation, os: 'linux'
|
||||
|
||||
property :package_name, String, default: lazy { default_server_package_name }, desired_state: false
|
||||
property :package_options, [String, nil], desired_state: false
|
||||
property :package_version, [String, nil], default: nil, desired_state: false
|
||||
|
||||
# helper methods
|
||||
require_relative 'helpers'
|
||||
include MysqlCookbook::HelpersBase
|
||||
|
||||
# Actions
|
||||
action :install do
|
||||
package package_name do
|
||||
version package_version if package_version
|
||||
options package_options if package_options
|
||||
notifies :install, 'package[perl-Sys-Hostname-Long]', :immediately if platform_family?('suse')
|
||||
notifies :run, 'execute[Initial DB setup script]', :immediately if platform_family?('suse')
|
||||
action :install
|
||||
end
|
||||
|
||||
package 'perl-Sys-Hostname-Long' do
|
||||
action :nothing
|
||||
end
|
||||
|
||||
execute 'Initial DB setup script' do
|
||||
environment 'INSTANCE' => new_resource.name
|
||||
command '/usr/lib/mysql/mysql-systemd-helper install'
|
||||
action :nothing
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
package package_name do
|
||||
action :remove
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
105
cookbooks/mysql/libraries/mysql_service.rb
Normal file
105
cookbooks/mysql/libraries/mysql_service.rb
Normal file
@ -0,0 +1,105 @@
|
||||
module MysqlCookbook
|
||||
require_relative 'mysql_service_base'
|
||||
class MysqlService < MysqlServiceBase
|
||||
resource_name :mysql_service
|
||||
|
||||
# installation type and service_manager
|
||||
property :install_method, %w(package auto), default: 'auto', desired_state: false
|
||||
property :service_manager, %w(sysvinit upstart systemd auto), default: 'auto', desired_state: false
|
||||
|
||||
# mysql_server_installation
|
||||
property :version, String, default: lazy { default_major_version }, desired_state: false
|
||||
property :major_version, String, default: lazy { major_from_full(version) }, desired_state: false
|
||||
property :package_name, String, default: lazy { default_package_name }, desired_state: false
|
||||
property :package_options, [String, nil], desired_state: false
|
||||
property :package_version, [String, nil], default: nil, desired_state: false
|
||||
|
||||
################
|
||||
# Helper Methods
|
||||
################
|
||||
|
||||
def copy_properties_to(to, *properties)
|
||||
properties = self.class.properties.keys if properties.empty?
|
||||
properties.each do |p|
|
||||
# If the property is set on from, and exists on to, set the
|
||||
# property on to
|
||||
if to.class.properties.include?(p) && property_is_set?(p)
|
||||
to.send(p, send(p))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action_class.class_eval do
|
||||
def installation(&block)
|
||||
case install_method
|
||||
when 'auto'
|
||||
install = mysql_server_installation(name, &block)
|
||||
when 'package'
|
||||
install = mysql_server_installation_package(name, &block)
|
||||
when 'none'
|
||||
Chef::Log.info('Skipping MySQL installation. Assuming it was handled previously.')
|
||||
return
|
||||
end
|
||||
copy_properties_to(install)
|
||||
install
|
||||
end
|
||||
|
||||
def svc_manager(&block)
|
||||
case service_manager
|
||||
when 'auto'
|
||||
svc = mysql_service_manager(name, &block)
|
||||
when 'sysvinit'
|
||||
svc = mysql_service_manager_sysvinit(name, &block)
|
||||
when 'upstart'
|
||||
svc = mysql_service_manager_upstart(name, &block)
|
||||
when 'systemd'
|
||||
svc = mysql_service_manager_systemd(name, &block)
|
||||
end
|
||||
copy_properties_to(svc)
|
||||
svc
|
||||
end
|
||||
end
|
||||
|
||||
#########
|
||||
# Actions
|
||||
#########
|
||||
|
||||
action :create do
|
||||
installation do
|
||||
action :install
|
||||
end
|
||||
|
||||
svc_manager do
|
||||
action :create
|
||||
end
|
||||
end
|
||||
|
||||
action :start do
|
||||
svc_manager do
|
||||
action :start
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
svc_manager do
|
||||
action :delete
|
||||
end
|
||||
|
||||
installation do
|
||||
action :delete
|
||||
end
|
||||
end
|
||||
|
||||
action :restart do
|
||||
svc_manager do
|
||||
action :restart
|
||||
end
|
||||
end
|
||||
|
||||
action :stop do
|
||||
svc_manager do
|
||||
action :stop
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
203
cookbooks/mysql/libraries/mysql_service_base.rb
Normal file
203
cookbooks/mysql/libraries/mysql_service_base.rb
Normal file
@ -0,0 +1,203 @@
|
||||
module MysqlCookbook
|
||||
class MysqlServiceBase < MysqlBase
|
||||
property :bind_address, String, desired_state: false
|
||||
property :charset, String, default: 'utf8', desired_state: false
|
||||
property :data_dir, String, default: lazy { default_data_dir }, desired_state: false
|
||||
property :error_log, String, default: lazy { default_error_log }, desired_state: false
|
||||
property :initial_root_password, String, default: 'ilikerandompasswords', desired_state: false
|
||||
property :instance, String, name_property: true, desired_state: false
|
||||
property :mysqld_options, Hash, default: {}, desired_state: false
|
||||
property :pid_file, String, default: lazy { default_pid_file }, desired_state: false
|
||||
property :port, [String, Integer], default: '3306', desired_state: false
|
||||
property :socket, String, default: lazy { default_socket_file }, desired_state: false
|
||||
property :tmp_dir, String, desired_state: false
|
||||
|
||||
alias socket_file socket
|
||||
|
||||
require_relative 'helpers'
|
||||
include MysqlCookbook::HelpersBase
|
||||
|
||||
# action class methods are available within the actions and work as if the coded
|
||||
# was inline the action. No messing with classes or passing in the new_resource
|
||||
declare_action_class.class_eval do
|
||||
def create_system_user
|
||||
group 'mysql' do
|
||||
action :create
|
||||
end
|
||||
|
||||
user 'mysql' do
|
||||
gid 'mysql'
|
||||
action :create
|
||||
end
|
||||
end
|
||||
|
||||
def create_config
|
||||
# require 'pry' ; binding.pry
|
||||
|
||||
# Yak shaving secion. Account for random errata.
|
||||
#
|
||||
# Turns out that mysqld is hard coded to try and read
|
||||
# /etc/mysql/my.cnf, and its presence causes problems when
|
||||
# setting up multiple services.
|
||||
file "#{prefix_dir}/etc/mysql/my.cnf" do
|
||||
action :delete
|
||||
end
|
||||
|
||||
file "#{prefix_dir}/etc/my.cnf" do
|
||||
action :delete
|
||||
end
|
||||
|
||||
# mysql_install_db is broken on 5.6.13
|
||||
link "#{prefix_dir}/usr/share/my-default.cnf" do
|
||||
to "#{etc_dir}/my.cnf"
|
||||
not_if { ::File.exist? "#{prefix_dir}/usr/share/my-default.cnf" } # FIXME: Chef bug?
|
||||
action :create
|
||||
end
|
||||
|
||||
# Support directories
|
||||
directory etc_dir do
|
||||
owner run_user
|
||||
group run_group
|
||||
mode '0750'
|
||||
recursive true
|
||||
action :create
|
||||
end
|
||||
|
||||
directory include_dir do
|
||||
owner run_user
|
||||
group run_group
|
||||
mode '0750'
|
||||
recursive true
|
||||
action :create
|
||||
end
|
||||
|
||||
directory run_dir do
|
||||
owner run_user
|
||||
group run_group
|
||||
mode '0755'
|
||||
recursive true
|
||||
action :create
|
||||
end
|
||||
|
||||
directory log_dir do
|
||||
owner run_user
|
||||
group run_group
|
||||
mode '0750'
|
||||
recursive true
|
||||
action :create
|
||||
end
|
||||
|
||||
directory data_dir do
|
||||
owner run_user
|
||||
group run_group
|
||||
mode '0750'
|
||||
recursive true
|
||||
action :create
|
||||
end
|
||||
|
||||
# Main configuration file
|
||||
template "#{etc_dir}/my.cnf" do
|
||||
source 'my.cnf.erb'
|
||||
cookbook 'mysql'
|
||||
owner run_user
|
||||
group run_group
|
||||
mode '0600'
|
||||
variables(config: new_resource)
|
||||
action :create
|
||||
end
|
||||
end
|
||||
|
||||
def initialize_database
|
||||
# initialize database and create initial records
|
||||
bash "#{name} initial records" do
|
||||
code init_records_script
|
||||
umask '022'
|
||||
returns [0, 1, 2] # facepalm
|
||||
not_if "/usr/bin/test -f #{data_dir}/mysql/user.frm"
|
||||
action :run
|
||||
end
|
||||
end
|
||||
|
||||
def delete_support_directories
|
||||
# Stop the service before removing support directories
|
||||
delete_stop_service
|
||||
|
||||
directory etc_dir do
|
||||
recursive true
|
||||
action :delete
|
||||
end
|
||||
|
||||
directory run_dir do
|
||||
recursive true
|
||||
action :delete
|
||||
end
|
||||
|
||||
directory log_dir do
|
||||
recursive true
|
||||
action :delete
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Platform specific bits
|
||||
#
|
||||
def configure_apparmor
|
||||
# Do not add these resource if inside a container
|
||||
# Only valid on Ubuntu
|
||||
return if ::File.exist?('/.dockerenv') || ::File.exist?('/.dockerinit') || node['platform'] != 'ubuntu'
|
||||
|
||||
# Apparmor
|
||||
package 'apparmor' do
|
||||
action :install
|
||||
end
|
||||
|
||||
directory '/etc/apparmor.d/local/mysql' do
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0755'
|
||||
recursive true
|
||||
action :create
|
||||
end
|
||||
|
||||
template '/etc/apparmor.d/local/usr.sbin.mysqld' do
|
||||
cookbook 'mysql'
|
||||
source 'apparmor/usr.sbin.mysqld-local.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
action :create
|
||||
notifies :restart, "service[#{instance} apparmor]", :immediately
|
||||
end
|
||||
|
||||
template '/etc/apparmor.d/usr.sbin.mysqld' do
|
||||
cookbook 'mysql'
|
||||
source 'apparmor/usr.sbin.mysqld.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
action :create
|
||||
notifies :restart, "service[#{instance} apparmor]", :immediately
|
||||
end
|
||||
|
||||
template "/etc/apparmor.d/local/mysql/#{instance}" do
|
||||
cookbook 'mysql'
|
||||
source 'apparmor/usr.sbin.mysqld-instance.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
variables(
|
||||
config: new_resource,
|
||||
mysql_name: mysql_name
|
||||
)
|
||||
action :create
|
||||
notifies :restart, "service[#{instance} apparmor]", :immediately
|
||||
end
|
||||
|
||||
service "#{instance} apparmor" do
|
||||
service_name 'apparmor'
|
||||
action :nothing
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
142
cookbooks/mysql/libraries/mysql_service_manager_systemd.rb
Normal file
142
cookbooks/mysql/libraries/mysql_service_manager_systemd.rb
Normal file
@ -0,0 +1,142 @@
|
||||
module MysqlCookbook
|
||||
class MysqlServiceManagerSystemd < MysqlServiceBase
|
||||
resource_name :mysql_service_manager_systemd
|
||||
|
||||
provides :mysql_service_manager, os: 'linux' do |_node|
|
||||
Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd)
|
||||
end
|
||||
|
||||
action :create do
|
||||
# from base
|
||||
create_system_user
|
||||
stop_system_service
|
||||
create_config
|
||||
configure_apparmor
|
||||
initialize_database
|
||||
end
|
||||
|
||||
action :start do
|
||||
# Needed for Debian / Ubuntu
|
||||
directory '/usr/libexec' do
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0755'
|
||||
action :create
|
||||
end
|
||||
|
||||
# this script is called by the main systemd unit file, and
|
||||
# spins around until the service is actually up and running.
|
||||
template "/usr/libexec/#{mysql_name}-wait-ready" do
|
||||
path "/usr/libexec/#{mysql_name}-wait-ready"
|
||||
source 'systemd/mysqld-wait-ready.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0755'
|
||||
variables(socket_file: socket_file)
|
||||
cookbook 'mysql'
|
||||
action :create
|
||||
end
|
||||
|
||||
# this is the main systemd unit file
|
||||
template "/etc/systemd/system/#{mysql_name}.service" do
|
||||
path "/etc/systemd/system/#{mysql_name}.service"
|
||||
source 'systemd/mysqld.service.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
variables(
|
||||
config: new_resource,
|
||||
etc_dir: etc_dir,
|
||||
base_dir: base_dir,
|
||||
mysqld_bin: mysqld_bin
|
||||
)
|
||||
cookbook 'mysql'
|
||||
notifies :run, "execute[#{instance} systemctl daemon-reload]", :immediately
|
||||
action :create
|
||||
end
|
||||
|
||||
# avoid 'Unit file changed on disk' warning
|
||||
execute "#{instance} systemctl daemon-reload" do
|
||||
command '/bin/systemctl daemon-reload'
|
||||
action :nothing
|
||||
end
|
||||
|
||||
# tmpfiles.d config so the service survives reboot
|
||||
template "/usr/lib/tmpfiles.d/#{mysql_name}.conf" do
|
||||
path "/usr/lib/tmpfiles.d/#{mysql_name}.conf"
|
||||
source 'tmpfiles.d.conf.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
variables(
|
||||
run_dir: run_dir,
|
||||
run_user: run_user,
|
||||
run_group: run_group
|
||||
)
|
||||
cookbook 'mysql'
|
||||
action :create
|
||||
end
|
||||
|
||||
# service management resource
|
||||
service mysql_name.to_s do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Systemd
|
||||
supports restart: true, status: true
|
||||
action [:enable, :start]
|
||||
end
|
||||
end
|
||||
|
||||
action :stop do
|
||||
# service management resource
|
||||
service mysql_name.to_s do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Systemd
|
||||
supports status: true
|
||||
action [:disable, :stop]
|
||||
only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") }
|
||||
end
|
||||
end
|
||||
|
||||
action :restart do
|
||||
# service management resource
|
||||
service mysql_name.to_s do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Systemd
|
||||
supports restart: true
|
||||
action :restart
|
||||
end
|
||||
end
|
||||
|
||||
action :reload do
|
||||
# service management resource
|
||||
service mysql_name.to_s do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Systemd
|
||||
action :reload
|
||||
end
|
||||
end
|
||||
|
||||
declare_action_class.class_eval do
|
||||
def stop_system_service
|
||||
# service management resource
|
||||
service 'mysql' do
|
||||
service_name system_service_name
|
||||
provider Chef::Provider::Service::Systemd
|
||||
supports status: true
|
||||
action [:stop, :disable]
|
||||
end
|
||||
end
|
||||
|
||||
def delete_stop_service
|
||||
# service management resource
|
||||
service mysql_name.to_s do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Systemd
|
||||
supports status: true
|
||||
action [:disable, :stop]
|
||||
only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
79
cookbooks/mysql/libraries/mysql_service_manager_sysvinit.rb
Normal file
79
cookbooks/mysql/libraries/mysql_service_manager_sysvinit.rb
Normal file
@ -0,0 +1,79 @@
|
||||
module MysqlCookbook
|
||||
class MysqlServiceManagerSysvinit < MysqlServiceBase
|
||||
resource_name :mysql_service_manager_sysvinit
|
||||
|
||||
provides :mysql_service_manager, os: 'linux'
|
||||
|
||||
action :create do
|
||||
# from base
|
||||
create_system_user
|
||||
stop_system_service
|
||||
create_config
|
||||
initialize_database
|
||||
configure_apparmor
|
||||
end
|
||||
|
||||
action :start do
|
||||
template "/etc/init.d/#{mysql_name}" do
|
||||
source 'sysvinit/mysqld.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0755'
|
||||
variables(
|
||||
config: new_resource,
|
||||
defaults_file: defaults_file,
|
||||
error_log: error_log,
|
||||
mysql_name: mysql_name,
|
||||
mysqladmin_bin: mysqladmin_bin,
|
||||
mysqld_safe_bin: mysqld_safe_bin,
|
||||
pid_file: pid_file,
|
||||
scl_name: scl_name
|
||||
)
|
||||
cookbook 'mysql'
|
||||
action :create
|
||||
end
|
||||
|
||||
service mysql_name do
|
||||
supports restart: true, status: true
|
||||
action [:enable, :start]
|
||||
end
|
||||
end
|
||||
|
||||
action :stop do
|
||||
service mysql_name do
|
||||
supports restart: true, status: true
|
||||
action [:stop]
|
||||
end
|
||||
end
|
||||
|
||||
action :restart do
|
||||
service mysql_name do
|
||||
supports restart: true
|
||||
action :restart
|
||||
end
|
||||
end
|
||||
|
||||
action :reload do
|
||||
service mysql_name do
|
||||
action :reload
|
||||
end
|
||||
end
|
||||
|
||||
declare_action_class.class_eval do
|
||||
def stop_system_service
|
||||
service system_service_name do
|
||||
supports status: true
|
||||
action [:stop, :disable]
|
||||
end
|
||||
end
|
||||
|
||||
def delete_stop_service
|
||||
service mysql_name do
|
||||
supports status: true
|
||||
action [:disable, :stop]
|
||||
only_if { ::File.exist?("#{etc_dir}/init.d/#{mysql_name}") }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
103
cookbooks/mysql/libraries/mysql_service_manager_upstart.rb
Normal file
103
cookbooks/mysql/libraries/mysql_service_manager_upstart.rb
Normal file
@ -0,0 +1,103 @@
|
||||
module MysqlCookbook
|
||||
class MysqlServiceManagerUpstart < MysqlServiceBase
|
||||
resource_name :mysql_service_manager_upstart
|
||||
|
||||
provides :mysql_service_manager, platform_family: 'debian' do |_node|
|
||||
Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) &&
|
||||
!Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd) &&
|
||||
!Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat) &&
|
||||
::File.exist?('/sbin/status') # Fix for Docker, in 7 and 8 images /sbin/status doesn't exists and Upstart provider doesn't work
|
||||
end
|
||||
|
||||
action :create do
|
||||
# from base
|
||||
create_system_user
|
||||
stop_system_service
|
||||
create_config
|
||||
configure_apparmor
|
||||
initialize_database
|
||||
end
|
||||
|
||||
action :start do
|
||||
template "/usr/sbin/#{mysql_name}-wait-ready" do
|
||||
source 'upstart/mysqld-wait-ready.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0755'
|
||||
variables(socket_file: socket_file)
|
||||
cookbook 'mysql'
|
||||
action :create
|
||||
end
|
||||
|
||||
template "/etc/init/#{mysql_name}.conf" do
|
||||
source 'upstart/mysqld.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
variables(
|
||||
defaults_file: defaults_file,
|
||||
mysql_name: mysql_name,
|
||||
run_group: run_group,
|
||||
run_user: run_user,
|
||||
socket_dir: socket_dir
|
||||
)
|
||||
cookbook 'mysql'
|
||||
action :create
|
||||
end
|
||||
|
||||
service mysql_name do
|
||||
provider Chef::Provider::Service::Upstart
|
||||
supports status: true
|
||||
action [:start]
|
||||
end
|
||||
end
|
||||
|
||||
action :stop do
|
||||
service mysql_name do
|
||||
provider Chef::Provider::Service::Upstart
|
||||
supports restart: true, status: true
|
||||
action [:stop]
|
||||
end
|
||||
end
|
||||
|
||||
action :restart do
|
||||
# With Upstart, restarting the service doesn't behave "as expected".
|
||||
# We want the post-start stanzas, which wait until the
|
||||
# service is available before returning
|
||||
#
|
||||
# http://upstart.ubuntu.com/cookbook/#restart
|
||||
service mysql_name do
|
||||
provider Chef::Provider::Service::Upstart
|
||||
action [:stop, :start]
|
||||
end
|
||||
end
|
||||
|
||||
action :reload do
|
||||
# With Upstart, reload just sends a HUP signal to the process.
|
||||
# As far as I can tell, this doesn't work the way it's
|
||||
# supposed to, so we need to actually restart the service.
|
||||
service mysql_name do
|
||||
provider Chef::Provider::Service::Upstart
|
||||
action [:stop, :start]
|
||||
end
|
||||
end
|
||||
|
||||
declare_action_class.class_eval do
|
||||
def stop_system_service
|
||||
service system_service_name do
|
||||
provider Chef::Provider::Service::Upstart
|
||||
supports status: true
|
||||
action [:stop, :disable]
|
||||
end
|
||||
end
|
||||
|
||||
def delete_stop_service
|
||||
service mysql_name do
|
||||
provider Chef::Provider::Service::Upstart
|
||||
action [:disable, :stop]
|
||||
only_if { ::File.exist?("#{etc_dir}/init/#{mysql_name}") }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,39 +0,0 @@
|
||||
require 'chef/provider/lwrp_base'
|
||||
require_relative 'helpers'
|
||||
|
||||
class Chef
|
||||
class Provider
|
||||
class MysqlClient < Chef::Provider::LWRPBase
|
||||
include MysqlCookbook::Helpers
|
||||
provides :mysql_client if defined?(provides)
|
||||
|
||||
use_inline_resources if defined?(use_inline_resources)
|
||||
|
||||
def whyrun_supported?
|
||||
true
|
||||
end
|
||||
|
||||
action :create do
|
||||
# From helpers.rb
|
||||
configure_package_repositories
|
||||
|
||||
client_package_name.each do |p|
|
||||
package "#{new_resource.name} :create #{p}" do
|
||||
package_name p
|
||||
version new_resource.version if node['platform'] == 'smartos'
|
||||
version new_resource.package_version
|
||||
action :install
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
parsed_package_name.each do |p|
|
||||
package "#{new_resource.name} :delete #{p}" do
|
||||
action :remove
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,59 +0,0 @@
|
||||
require 'chef/provider/lwrp_base'
|
||||
require_relative 'helpers'
|
||||
|
||||
class Chef
|
||||
class Provider
|
||||
class MysqlConfig < Chef::Provider::LWRPBase
|
||||
include MysqlCookbook::Helpers
|
||||
provides :mysql_config if defined?(provides)
|
||||
|
||||
use_inline_resources if defined?(use_inline_resources)
|
||||
|
||||
def whyrun_supported?
|
||||
true
|
||||
end
|
||||
|
||||
action :create do
|
||||
group "#{new_resource.name} :create #{new_resource.group}" do
|
||||
group_name new_resource.group
|
||||
system true if new_resource.name == 'mysql'
|
||||
action :create
|
||||
end
|
||||
|
||||
user "#{new_resource.name} :create #{new_resource.owner}" do
|
||||
username new_resource.owner
|
||||
gid new_resource.owner
|
||||
system true if new_resource.name == 'mysql'
|
||||
action :create
|
||||
end
|
||||
|
||||
directory "#{new_resource.name} :create #{include_dir}" do
|
||||
path include_dir
|
||||
owner new_resource.owner
|
||||
group new_resource.group
|
||||
mode '0750'
|
||||
recursive true
|
||||
action :create
|
||||
end
|
||||
|
||||
template "#{new_resource.name} :create #{include_dir}/#{new_resource.config_name}.cnf" do
|
||||
path "#{include_dir}/#{new_resource.config_name}.cnf"
|
||||
owner new_resource.owner
|
||||
group new_resource.group
|
||||
mode '0640'
|
||||
variables(new_resource.variables)
|
||||
source new_resource.source
|
||||
cookbook new_resource.cookbook
|
||||
action :create
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
file "#{new_resource.name} :delete #{include_dir}/#{new_resource.config_name}.conf" do
|
||||
path "#{include_dir}/#{new_resource.config_name}.conf"
|
||||
action :delete
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,250 +0,0 @@
|
||||
require 'chef/provider/lwrp_base'
|
||||
require_relative 'helpers'
|
||||
|
||||
class Chef
|
||||
class Provider
|
||||
class MysqlServiceBase < Chef::Provider::LWRPBase
|
||||
use_inline_resources if defined?(use_inline_resources)
|
||||
|
||||
def whyrun_supported?
|
||||
true
|
||||
end
|
||||
|
||||
# Mix in helpers from libraries/helpers.rb
|
||||
include MysqlCookbook::Helpers
|
||||
|
||||
# Service related methods referred to in the :create and :delete
|
||||
# actions need to be implemented in the init system subclasses.
|
||||
#
|
||||
# create_stop_system_service
|
||||
# delete_stop_service
|
||||
|
||||
# All other methods are found in libraries/helpers.rb
|
||||
#
|
||||
# etc_dir, run_dir, log_dir, etc
|
||||
|
||||
action :create do
|
||||
# Yum, Apt, etc. From helpers.rb
|
||||
configure_package_repositories
|
||||
|
||||
# Software installation
|
||||
package "#{new_resource.name} :create #{server_package_name}" do
|
||||
package_name server_package_name
|
||||
version parsed_version if node['platform'] == 'smartos'
|
||||
version new_resource.package_version
|
||||
action new_resource.package_action
|
||||
end
|
||||
|
||||
create_stop_system_service
|
||||
|
||||
# Apparmor
|
||||
configure_apparmor
|
||||
|
||||
# System users
|
||||
group "#{new_resource.name} :create mysql" do
|
||||
group_name 'mysql'
|
||||
action :create
|
||||
end
|
||||
|
||||
user "#{new_resource.name} :create mysql" do
|
||||
username 'mysql'
|
||||
gid 'mysql'
|
||||
action :create
|
||||
end
|
||||
|
||||
# Yak shaving secion. Account for random errata.
|
||||
#
|
||||
# Turns out that mysqld is hard coded to try and read
|
||||
# /etc/mysql/my.cnf, and its presence causes problems when
|
||||
# setting up multiple services.
|
||||
file "#{new_resource.name} :create #{prefix_dir}/etc/mysql/my.cnf" do
|
||||
path "#{prefix_dir}/etc/mysql/my.cnf"
|
||||
action :delete
|
||||
end
|
||||
|
||||
file "#{new_resource.name} :create #{prefix_dir}/etc/my.cnf" do
|
||||
path "#{prefix_dir}/etc/my.cnf"
|
||||
action :delete
|
||||
end
|
||||
|
||||
# mysql_install_db is broken on 5.6.13
|
||||
link "#{new_resource.name} :create #{prefix_dir}/usr/share/my-default.cnf" do
|
||||
target_file "#{prefix_dir}/usr/share/my-default.cnf"
|
||||
to "#{etc_dir}/my.cnf"
|
||||
action :create
|
||||
end
|
||||
|
||||
# Support directories
|
||||
directory "#{new_resource.name} :create #{etc_dir}" do
|
||||
path etc_dir
|
||||
owner new_resource.run_user
|
||||
group new_resource.run_group
|
||||
mode '0750'
|
||||
recursive true
|
||||
action :create
|
||||
end
|
||||
|
||||
directory "#{new_resource.name} :create #{include_dir}" do
|
||||
path include_dir
|
||||
owner new_resource.run_user
|
||||
group new_resource.run_group
|
||||
mode '0750'
|
||||
recursive true
|
||||
action :create
|
||||
end
|
||||
|
||||
directory "#{new_resource.name} :create #{run_dir}" do
|
||||
path run_dir
|
||||
owner new_resource.run_user
|
||||
group new_resource.run_group
|
||||
mode '0755'
|
||||
recursive true
|
||||
action :create
|
||||
end
|
||||
|
||||
directory "#{new_resource.name} :create #{log_dir}" do
|
||||
path log_dir
|
||||
owner new_resource.run_user
|
||||
group new_resource.run_group
|
||||
mode '0750'
|
||||
recursive true
|
||||
action :create
|
||||
end
|
||||
|
||||
directory "#{new_resource.name} :create #{parsed_data_dir}" do
|
||||
path parsed_data_dir
|
||||
owner new_resource.run_user
|
||||
group new_resource.run_group
|
||||
mode '0750'
|
||||
recursive true
|
||||
action :create
|
||||
end
|
||||
|
||||
# Main configuration file
|
||||
template "#{new_resource.name} :create #{etc_dir}/my.cnf" do
|
||||
path "#{etc_dir}/my.cnf"
|
||||
source 'my.cnf.erb'
|
||||
cookbook 'mysql'
|
||||
owner new_resource.run_user
|
||||
group new_resource.run_group
|
||||
mode '0600'
|
||||
variables(
|
||||
config: new_resource,
|
||||
error_log: error_log,
|
||||
include_dir: include_dir,
|
||||
lc_messages_dir: lc_messages_dir,
|
||||
pid_file: pid_file,
|
||||
socket_file: socket_file,
|
||||
tmp_dir: tmp_dir,
|
||||
data_dir: parsed_data_dir
|
||||
)
|
||||
action :create
|
||||
end
|
||||
|
||||
# initialize database and create initial records
|
||||
bash "#{new_resource.name} :create initial records" do
|
||||
code init_records_script
|
||||
returns [0, 1, 2] # facepalm
|
||||
not_if "/usr/bin/test -f #{parsed_data_dir}/mysql/user.frm"
|
||||
action :run
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
# Stop the service before removing support directories
|
||||
delete_stop_service
|
||||
|
||||
directory "#{new_resource.name} :delete #{etc_dir}" do
|
||||
path etc_dir
|
||||
recursive true
|
||||
action :delete
|
||||
end
|
||||
|
||||
directory "#{new_resource.name} :delete #{run_dir}" do
|
||||
path run_dir
|
||||
recursive true
|
||||
action :delete
|
||||
end
|
||||
|
||||
directory "#{new_resource.name} :delete #{log_dir}" do
|
||||
path log_dir
|
||||
recursive true
|
||||
action :delete
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Platform specific bits
|
||||
#
|
||||
def configure_apparmor
|
||||
# Do not add these resource if inside a container
|
||||
# Only valid on Ubuntu
|
||||
|
||||
unless ::File.exist?('/.dockerenv') || ::File.exist?('/.dockerinit')
|
||||
if node['platform'] == 'ubuntu'
|
||||
# Apparmor
|
||||
package "#{new_resource.name} :create apparmor" do
|
||||
package_name 'apparmor'
|
||||
action :install
|
||||
end
|
||||
|
||||
directory "#{new_resource.name} :create /etc/apparmor.d/local/mysql" do
|
||||
path '/etc/apparmor.d/local/mysql'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0755'
|
||||
recursive true
|
||||
action :create
|
||||
end
|
||||
|
||||
template "#{new_resource.name} :create /etc/apparmor.d/local/usr.sbin.mysqld" do
|
||||
path '/etc/apparmor.d/local/usr.sbin.mysqld'
|
||||
cookbook 'mysql'
|
||||
source 'apparmor/usr.sbin.mysqld-local.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
action :create
|
||||
notifies :restart, "service[#{new_resource.name} :create apparmor]", :immediately
|
||||
end
|
||||
|
||||
template "#{new_resource.name} :create /etc/apparmor.d/usr.sbin.mysqld" do
|
||||
path '/etc/apparmor.d/usr.sbin.mysqld'
|
||||
cookbook 'mysql'
|
||||
source 'apparmor/usr.sbin.mysqld.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
action :create
|
||||
notifies :restart, "service[#{new_resource.name} :create apparmor]", :immediately
|
||||
end
|
||||
|
||||
template "#{new_resource.name} :create /etc/apparmor.d/local/mysql/#{new_resource.instance}" do
|
||||
path "/etc/apparmor.d/local/mysql/#{new_resource.instance}"
|
||||
cookbook 'mysql'
|
||||
source 'apparmor/usr.sbin.mysqld-instance.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
variables(
|
||||
data_dir: parsed_data_dir,
|
||||
mysql_name: mysql_name,
|
||||
log_dir: log_dir,
|
||||
run_dir: run_dir,
|
||||
pid_file: pid_file,
|
||||
socket_file: socket_file
|
||||
)
|
||||
action :create
|
||||
notifies :restart, "service[#{new_resource.name} :create apparmor]", :immediately
|
||||
end
|
||||
|
||||
service "#{new_resource.name} :create apparmor" do
|
||||
service_name 'apparmor'
|
||||
action :nothing
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,91 +0,0 @@
|
||||
class Chef
|
||||
class Provider
|
||||
class MysqlServiceSmf < Chef::Provider::MysqlServiceBase
|
||||
# FIXME: we should have a service_helper to determine if the platform supports SMF similarly
|
||||
# to how we handle systemd on linux
|
||||
if defined?(provides) # foodcritic ~FC023
|
||||
provides :mysql_service, os: %w(solaris2 omnios smartos openindiana opensolaris nexentacore) do
|
||||
File.exist?('/usr/sbin/svccfg')
|
||||
end
|
||||
end
|
||||
|
||||
action :start do
|
||||
method_script_path = "/lib/svc/method/#{mysql_name}" if node['platform'] == 'omnios'
|
||||
method_script_path = "/opt/local/lib/svc/method/#{mysql_name}" if node['platform'] == 'smartos'
|
||||
|
||||
template "#{new_resource.name} :start #{method_script_path}" do
|
||||
path method_script_path
|
||||
cookbook 'mysql'
|
||||
source 'smf/svc.method.mysqld.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0555'
|
||||
variables(
|
||||
base_dir: base_dir,
|
||||
data_dir: parsed_data_dir,
|
||||
defaults_file: defaults_file,
|
||||
error_log: error_log,
|
||||
mysql_name: mysql_name,
|
||||
mysqld_bin: mysqld_bin,
|
||||
pid_file: pid_file
|
||||
)
|
||||
action :create
|
||||
end
|
||||
|
||||
smf "#{new_resource.name} :start #{mysql_name}" do
|
||||
name mysql_name
|
||||
user new_resource.run_user
|
||||
group new_resource.run_group
|
||||
start_command "#{method_script_path} start"
|
||||
end
|
||||
|
||||
service "#{new_resource.name} :start #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Solaris
|
||||
supports restart: true
|
||||
action [:enable]
|
||||
end
|
||||
end
|
||||
|
||||
action :stop do
|
||||
service "#{new_resource.name} :stop #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Solaris
|
||||
supports restart: true
|
||||
action :stop
|
||||
end
|
||||
end
|
||||
|
||||
action :restart do
|
||||
service "#{new_resource.name} :restart #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Solaris
|
||||
supports restart: true
|
||||
action :restart
|
||||
end
|
||||
end
|
||||
|
||||
action :reload do
|
||||
service "#{new_resource.name} :reload #{mysql_name}" do
|
||||
provider Chef::Provider::Service::Solaris
|
||||
service_name mysql_name
|
||||
supports reload: true
|
||||
action :reload
|
||||
end
|
||||
end
|
||||
|
||||
def create_stop_system_service
|
||||
# nothing to do here
|
||||
end
|
||||
|
||||
def delete_stop_service
|
||||
service "#{new_resource.name} :delete #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Solaris
|
||||
supports restart: true
|
||||
action :stop
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,135 +0,0 @@
|
||||
require_relative 'provider_mysql_service_base'
|
||||
|
||||
class Chef
|
||||
class Provider
|
||||
class MysqlServiceSystemd < Chef::Provider::MysqlServiceBase
|
||||
if defined?(provides) # foodcritic ~FC023
|
||||
provides :mysql_service, os: 'linux' do
|
||||
Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd)
|
||||
end
|
||||
end
|
||||
|
||||
action :start do
|
||||
# Needed for Debian / Ubuntu
|
||||
directory '/usr/libexec' do
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0755'
|
||||
action :create
|
||||
end
|
||||
|
||||
# this script is called by the main systemd unit file, and
|
||||
# spins around until the service is actually up and running.
|
||||
template "#{new_resource.name} :start /usr/libexec/#{mysql_name}-wait-ready" do
|
||||
path "/usr/libexec/#{mysql_name}-wait-ready"
|
||||
source 'systemd/mysqld-wait-ready.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0755'
|
||||
variables(socket_file: socket_file)
|
||||
cookbook 'mysql'
|
||||
action :create
|
||||
end
|
||||
|
||||
# this is the main systemd unit file
|
||||
template "#{new_resource.name} :start /lib/systemd/system/#{mysql_name}.service" do
|
||||
path "/lib/systemd/system/#{mysql_name}.service"
|
||||
source 'systemd/mysqld.service.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
variables(
|
||||
config: new_resource,
|
||||
etc_dir: etc_dir,
|
||||
base_dir: base_dir,
|
||||
mysqld_bin: mysqld_bin
|
||||
)
|
||||
cookbook 'mysql'
|
||||
notifies :run, "execute[#{new_resource.name} :start systemctl daemon-reload]", :immediately
|
||||
action :create
|
||||
end
|
||||
|
||||
# avoid 'Unit file changed on disk' warning
|
||||
execute "#{new_resource.name} :start systemctl daemon-reload" do
|
||||
command '/bin/systemctl daemon-reload'
|
||||
action :nothing
|
||||
end
|
||||
|
||||
# tmpfiles.d config so the service survives reboot
|
||||
template "#{new_resource.name} :start /usr/lib/tmpfiles.d/#{mysql_name}.conf" do
|
||||
path "/usr/lib/tmpfiles.d/#{mysql_name}.conf"
|
||||
source 'tmpfiles.d.conf.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
variables(
|
||||
run_dir: run_dir,
|
||||
run_user: new_resource.run_user,
|
||||
run_group: new_resource.run_group
|
||||
)
|
||||
cookbook 'mysql'
|
||||
action :create
|
||||
end
|
||||
|
||||
# service management resource
|
||||
service "#{new_resource.name} :start #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Systemd
|
||||
supports restart: true, status: true
|
||||
action [:enable, :start]
|
||||
end
|
||||
end
|
||||
|
||||
action :stop do
|
||||
# service management resource
|
||||
service "#{new_resource.name} :stop #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Systemd
|
||||
supports status: true
|
||||
action [:disable, :stop]
|
||||
only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") }
|
||||
end
|
||||
end
|
||||
|
||||
action :restart do
|
||||
# service management resource
|
||||
service "#{new_resource.name} :restart #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Systemd
|
||||
supports restart: true
|
||||
action :restart
|
||||
end
|
||||
end
|
||||
|
||||
action :reload do
|
||||
# service management resource
|
||||
service "#{new_resource.name} :reload #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Systemd
|
||||
action :reload
|
||||
end
|
||||
end
|
||||
|
||||
def create_stop_system_service
|
||||
# service management resource
|
||||
service "#{new_resource.name} :create mysql" do
|
||||
service_name system_service_name
|
||||
provider Chef::Provider::Service::Systemd
|
||||
supports status: true
|
||||
action [:stop, :disable]
|
||||
end
|
||||
end
|
||||
|
||||
def delete_stop_service
|
||||
# service management resource
|
||||
service "#{new_resource.name} :delete #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Systemd
|
||||
supports status: true
|
||||
action [:disable, :stop]
|
||||
only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,89 +0,0 @@
|
||||
require_relative 'provider_mysql_service_base'
|
||||
|
||||
class Chef
|
||||
class Provider
|
||||
class MysqlServiceSysvinit < Chef::Provider::MysqlServiceBase
|
||||
provides :mysql_service, os: '!windows' if defined?(provides)
|
||||
|
||||
action :start do
|
||||
template "#{new_resource.name} :start /etc/init.d/#{mysql_name}" do
|
||||
path "/etc/init.d/#{mysql_name}"
|
||||
source 'sysvinit/mysqld.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0755'
|
||||
variables(
|
||||
config: new_resource,
|
||||
defaults_file: defaults_file,
|
||||
error_log: error_log,
|
||||
mysql_name: mysql_name,
|
||||
mysqladmin_bin: mysqladmin_bin,
|
||||
mysqld_safe_bin: mysqld_safe_bin,
|
||||
pid_file: pid_file,
|
||||
scl_name: scl_name
|
||||
)
|
||||
cookbook 'mysql'
|
||||
action :create
|
||||
end
|
||||
|
||||
service "#{new_resource.name} :start #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
|
||||
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
|
||||
supports restart: true, status: true
|
||||
action [:enable, :start]
|
||||
end
|
||||
end
|
||||
|
||||
action :stop do
|
||||
service "#{new_resource.name} :stop #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
|
||||
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
|
||||
supports restart: true, status: true
|
||||
action [:stop]
|
||||
end
|
||||
end
|
||||
|
||||
action :restart do
|
||||
service "#{new_resource.name} :restart #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
|
||||
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
|
||||
supports restart: true
|
||||
action :restart
|
||||
end
|
||||
end
|
||||
|
||||
action :reload do
|
||||
service "#{new_resource.name} :reload #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
|
||||
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
|
||||
action :reload
|
||||
end
|
||||
end
|
||||
|
||||
def create_stop_system_service
|
||||
service "#{new_resource.name} :create #{system_service_name}" do
|
||||
service_name system_service_name
|
||||
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
|
||||
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
|
||||
supports status: true
|
||||
action [:stop, :disable]
|
||||
end
|
||||
end
|
||||
|
||||
def delete_stop_service
|
||||
service "#{new_resource.name} :delete #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
|
||||
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
|
||||
supports status: true
|
||||
action [:disable, :stop]
|
||||
only_if { ::File.exist?("#{etc_dir}/init.d/#{mysql_name}") }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,114 +0,0 @@
|
||||
require_relative 'provider_mysql_service_base'
|
||||
|
||||
class Chef
|
||||
class Provider
|
||||
class MysqlServiceUpstart < Chef::Provider::MysqlServiceBase
|
||||
if defined?(provides) # foodcritic ~FC023
|
||||
provides :mysql_service, os: 'linux' do
|
||||
Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) &&
|
||||
!Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat)
|
||||
end
|
||||
end
|
||||
|
||||
action :start do
|
||||
template "#{new_resource.name} :start /usr/sbin/#{mysql_name}-wait-ready" do
|
||||
path "/usr/sbin/#{mysql_name}-wait-ready"
|
||||
source 'upstart/mysqld-wait-ready.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0755'
|
||||
variables(socket_file: socket_file)
|
||||
cookbook 'mysql'
|
||||
action :create
|
||||
end
|
||||
|
||||
template "#{new_resource.name} :start /etc/init/#{mysql_name}.conf" do
|
||||
path "/etc/init/#{mysql_name}.conf"
|
||||
source 'upstart/mysqld.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
variables(
|
||||
defaults_file: defaults_file,
|
||||
mysql_name: mysql_name,
|
||||
run_group: new_resource.run_group,
|
||||
run_user: new_resource.run_user,
|
||||
socket_dir: socket_dir
|
||||
)
|
||||
cookbook 'mysql'
|
||||
action :create
|
||||
end
|
||||
|
||||
service "#{new_resource.name} :start #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Upstart
|
||||
supports status: true
|
||||
action [:start]
|
||||
end
|
||||
end
|
||||
|
||||
action :stop do
|
||||
service "#{new_resource.name} :stop #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Upstart
|
||||
supports restart: true, status: true
|
||||
action [:stop]
|
||||
end
|
||||
end
|
||||
|
||||
action :restart do
|
||||
# With Upstart, restarting the service doesn't behave "as expected".
|
||||
# We want the post-start stanzas, which wait until the
|
||||
# service is available before returning
|
||||
#
|
||||
# http://upstart.ubuntu.com/cookbook/#restart
|
||||
service "#{new_resource.name} :restart stop #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Upstart
|
||||
action :stop
|
||||
end
|
||||
|
||||
service "#{new_resource.name} :restart start #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Upstart
|
||||
action :start
|
||||
end
|
||||
end
|
||||
|
||||
action :reload do
|
||||
# With Upstart, reload just sends a HUP signal to the process.
|
||||
# As far as I can tell, this doesn't work the way it's
|
||||
# supposed to, so we need to actually restart the service.
|
||||
service "#{new_resource.name} :reload stop #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Upstart
|
||||
action :stop
|
||||
end
|
||||
|
||||
service "#{new_resource.name} :reload start #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Upstart
|
||||
action :start
|
||||
end
|
||||
end
|
||||
|
||||
def create_stop_system_service
|
||||
service "#{new_resource.name} :create #{system_service_name}" do
|
||||
service_name system_service_name
|
||||
provider Chef::Provider::Service::Upstart
|
||||
supports status: true
|
||||
action [:stop, :disable]
|
||||
end
|
||||
end
|
||||
|
||||
def delete_stop_service
|
||||
service "#{new_resource.name} :delete #{mysql_name}" do
|
||||
service_name mysql_name
|
||||
provider Chef::Provider::Service::Upstart
|
||||
action [:disable, :stop]
|
||||
only_if { ::File.exist?("#{etc_dir}/init/#{mysql_name}") }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,45 +0,0 @@
|
||||
|
||||
begin
|
||||
require 'chef/platform/provider_priority_map'
|
||||
rescue LoadError # rubocop: disable Lint/HandleExceptions
|
||||
end
|
||||
|
||||
require_relative 'provider_mysql_service_smf'
|
||||
require_relative 'provider_mysql_service_systemd'
|
||||
require_relative 'provider_mysql_service_sysvinit'
|
||||
require_relative 'provider_mysql_service_upstart'
|
||||
require_relative 'provider_mysql_config'
|
||||
require_relative 'provider_mysql_client'
|
||||
|
||||
if defined? Chef::Platform::ProviderPriorityMap
|
||||
Chef::Platform::ProviderPriorityMap.instance.priority(
|
||||
:mysql_service,
|
||||
[Chef::Provider::MysqlServiceSystemd, Chef::Provider::MysqlServiceUpstart, Chef::Provider::MysqlServiceSysvinit],
|
||||
os: 'linux'
|
||||
)
|
||||
else
|
||||
# provider mappings for Chef 11
|
||||
|
||||
# systemd service
|
||||
Chef::Platform.set platform: :fedora, version: '>= 19', resource: :mysql_service, provider: Chef::Provider::MysqlServiceSystemd
|
||||
Chef::Platform.set platform: :redhat, version: '>= 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlServiceSystemd
|
||||
Chef::Platform.set platform: :centos, version: '>= 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlServiceSystemd
|
||||
Chef::Platform.set platform: :scientific, version: '>= 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlServiceSystemd
|
||||
Chef::Platform.set platform: :oracle, version: '>= 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlServiceSystemd
|
||||
|
||||
# smf service
|
||||
Chef::Platform.set platform: :omnios, resource: :mysql_service, provider: Chef::Provider::MysqlServiceSmf
|
||||
Chef::Platform.set platform: :smartos, resource: :mysql_service, provider: Chef::Provider::MysqlServiceSmf
|
||||
|
||||
# upstart service
|
||||
Chef::Platform.set platform: :ubuntu, resource: :mysql_service, provider: Chef::Provider::MysqlServiceUpstart
|
||||
|
||||
# default service
|
||||
Chef::Platform.set resource: :mysql_service, provider: Chef::Provider::MysqlServiceSysvinit
|
||||
|
||||
# config
|
||||
Chef::Platform.set resource: :mysql_config, provider: Chef::Provider::MysqlConfig
|
||||
|
||||
# client
|
||||
Chef::Platform.set resource: :mysql_client, provider: Chef::Provider::MysqlClient
|
||||
end
|
@ -1,18 +0,0 @@
|
||||
require 'chef/resource/lwrp_base'
|
||||
|
||||
class Chef
|
||||
class Resource
|
||||
class MysqlClient < Chef::Resource::LWRPBase
|
||||
provides :mysql_client
|
||||
|
||||
self.resource_name = :mysql_client
|
||||
actions :create, :delete
|
||||
default_action :create
|
||||
|
||||
attribute :client_name, kind_of: String, name_attribute: true, required: true
|
||||
attribute :package_name, kind_of: Array, default: nil
|
||||
attribute :package_version, kind_of: String, default: nil
|
||||
attribute :version, kind_of: String, default: nil # mysql_version
|
||||
end
|
||||
end
|
||||
end
|
@ -1,22 +0,0 @@
|
||||
require 'chef/resource/lwrp_base'
|
||||
|
||||
class Chef
|
||||
class Resource
|
||||
class MysqlConfig < Chef::Resource::LWRPBase
|
||||
provides :mysql_config
|
||||
|
||||
self.resource_name = :mysql_config
|
||||
actions :create, :delete
|
||||
default_action :create
|
||||
|
||||
attribute :config_name, kind_of: String, name_attribute: true, required: true
|
||||
attribute :cookbook, kind_of: String, default: nil
|
||||
attribute :group, kind_of: String, default: 'mysql'
|
||||
attribute :instance, kind_of: String, default: 'default'
|
||||
attribute :owner, kind_of: String, default: 'mysql'
|
||||
attribute :source, kind_of: String, default: nil
|
||||
attribute :variables, kind_of: [Hash], default: nil
|
||||
attribute :version, kind_of: String, default: nil
|
||||
end
|
||||
end
|
||||
end
|
@ -1,31 +0,0 @@
|
||||
require 'chef/resource/lwrp_base'
|
||||
|
||||
class Chef
|
||||
class Resource
|
||||
class MysqlService < Chef::Resource::LWRPBase
|
||||
provides :mysql_service
|
||||
|
||||
self.resource_name = :mysql_service
|
||||
actions :create, :delete, :start, :stop, :restart, :reload
|
||||
default_action :create
|
||||
|
||||
attribute :charset, kind_of: String, default: 'utf8'
|
||||
attribute :data_dir, kind_of: String, default: nil
|
||||
attribute :initial_root_password, kind_of: String, default: 'ilikerandompasswords'
|
||||
attribute :instance, kind_of: String, name_attribute: true
|
||||
attribute :package_action, kind_of: Symbol, default: :install
|
||||
attribute :package_name, kind_of: String, default: nil
|
||||
attribute :package_version, kind_of: String, default: nil
|
||||
attribute :bind_address, kind_of: String, default: nil
|
||||
attribute :port, kind_of: [String, Integer], default: '3306'
|
||||
attribute :run_group, kind_of: String, default: 'mysql'
|
||||
attribute :run_user, kind_of: String, default: 'mysql'
|
||||
attribute :socket, kind_of: String, default: nil
|
||||
attribute :mysqld_options, kind_of: Hash, default: {}
|
||||
attribute :version, kind_of: String, default: nil
|
||||
attribute :error_log, kind_of: String, default: nil
|
||||
attribute :tmp_dir, kind_of: String, default: nil
|
||||
attribute :pid_file, kind_of: String, default: nil
|
||||
end
|
||||
end
|
||||
end
|
File diff suppressed because one or more lines are too long
@ -2,12 +2,13 @@
|
||||
/etc/<%= @mysql_name %>/conf.d/ r,
|
||||
/etc/<%= @mysql_name %>/conf.d/* r,
|
||||
/etc/<%= @mysql_name %>/my.cnf r,
|
||||
<%= @log_dir %>/ r,
|
||||
<%= @log_dir %>/* rw,
|
||||
<%= @data_dir %>/ r,
|
||||
<%= @data_dir %>/** rwk,
|
||||
<%= @run_dir %>/** rw,
|
||||
<%= @pid_file %> rw,
|
||||
<%= @socket_file %> rw,
|
||||
<%= @config.log_dir %>/ r,
|
||||
<%= @config.log_dir %>/* rw,
|
||||
<%= @config.data_dir %>/ r,
|
||||
<%= @config.data_dir %>/** rwk,
|
||||
<%= @config.run_dir %>/** rw,
|
||||
<%= @config.pid_file %> rw,
|
||||
<%= @config.socket_file %> rw,
|
||||
/tmp/<%= @mysql_name %>/ r,
|
||||
/tmp/<%= @mysql_name %>/my.sql r,
|
||||
<%= @config.tmp_dir %>/* rw,
|
||||
|
@ -35,8 +35,10 @@
|
||||
/var/log/mysql/* rw,
|
||||
/var/run/mysqld/mysqld.pid rw,
|
||||
/var/run/mysqld/mysqld.sock w,
|
||||
/var/run/mysqld/mysqld.sock.lock rw,
|
||||
/run/mysqld/mysqld.pid rw,
|
||||
/run/mysqld/mysqld.sock w,
|
||||
/run/mysqld/mysqld.sock.lock rw,
|
||||
|
||||
/sys/devices/system/cpu/ r,
|
||||
|
||||
|
@ -7,8 +7,8 @@ default-character-set = <%= @config.charset %>
|
||||
<% if @config.port %>
|
||||
port = <%= @config.port %>
|
||||
<% end %>
|
||||
<% if @socket_file %>
|
||||
socket = <%= @socket_file %>
|
||||
<% if @config.socket_file %>
|
||||
socket = <%= @config.socket_file %>
|
||||
<% end %>
|
||||
|
||||
[mysql]
|
||||
@ -20,11 +20,11 @@ default-character-set = <%= @config.charset %>
|
||||
<% if @config.run_user %>
|
||||
user = <%= @config.run_user %>
|
||||
<% end %>
|
||||
<% if @pid_file %>
|
||||
pid-file = <%= @pid_file %>
|
||||
<% if @config.pid_file %>
|
||||
pid-file = <%= @config.pid_file %>
|
||||
<% end %>
|
||||
<% if @socket_file %>
|
||||
socket = <%= @socket_file %>
|
||||
<% if @config.socket_file %>
|
||||
socket = <%= @config.socket_file %>
|
||||
<% end %>
|
||||
<% if @config.bind_address %>
|
||||
bind-address = <%= @config.bind_address %>
|
||||
@ -32,26 +32,26 @@ bind-address = <%= @config.bind_address %>
|
||||
<% if @config.port %>
|
||||
port = <%= @config.port %>
|
||||
<% end %>
|
||||
<% if @data_dir %>
|
||||
datadir = <%= @data_dir %>
|
||||
<% if @config.data_dir %>
|
||||
datadir = <%= @config.data_dir %>
|
||||
<% end %>
|
||||
<% if @tmp_dir %>
|
||||
tmpdir = <%= @tmp_dir %>
|
||||
<% if @config.tmp_dir %>
|
||||
tmpdir = <%= @config.tmp_dir %>
|
||||
<% end %>
|
||||
<% @config.mysqld_options.each do |option,value| %>
|
||||
<%= option %> = <%= value %>
|
||||
<% end %>
|
||||
<% if @lc_messages_dir %>
|
||||
lc-messages-dir = <%= @lc_messages_dir %>
|
||||
<% if @config.lc_messages_dir %>
|
||||
lc-messages-dir = <%= @config.lc_messages_dir %>
|
||||
<% end %>
|
||||
<% if @error_log %>
|
||||
log-error = <%= @error_log %>
|
||||
<% if @config.error_log %>
|
||||
log-error = <%= @config.error_log %>
|
||||
<% end %>
|
||||
<% if @include_dir %>
|
||||
!includedir <%= @include_dir %>
|
||||
<% if @config.include_dir %>
|
||||
!includedir <%= @config.include_dir %>
|
||||
<% end %>
|
||||
|
||||
[mysqld_safe]
|
||||
<% if @socket_file %>
|
||||
socket = <%= @socket_file %>
|
||||
<% if @config.socket_file %>
|
||||
socket = <%= @config.socket_file %>
|
||||
<% end %>
|
||||
|
@ -1,30 +1,56 @@
|
||||
mysql2_chef_gem CHANGELOG
|
||||
========================
|
||||
# mysql2_chef_gem CHANGELOG
|
||||
|
||||
## 2.0.1 (2017-03-28)
|
||||
|
||||
- Include usage examples for installing on a mariadb server and included a note in the readme regarding the 2.0 changes.
|
||||
|
||||
## 2.0.0 (2017-03-28)
|
||||
|
||||
- Converted the previously HWRP resources/providers to a custom resource. This changes the behavior of choosing to install on mysql or mariadb in a breaking way. Instead of specifying the providers you need to call the resources directly. Specifying mysql2_chef_gem will default to mysql, but using mariadb will require using the mysql2_chef_gem_mariadb resource directly.
|
||||
- Increase the minimum chef version to 12.5
|
||||
- Require mysql cookbook 8.2+ and build-essential cookbook 2.4+
|
||||
- Install the 0.4.5 gem by default
|
||||
- Expand test recipe to cover more scenarios
|
||||
- Switched testing to use Delivery local mode
|
||||
- Switched from kitchen-docker to kitchen-dokken and removed testing for CentOS 5 / Ubuntu 12.04 as these are both going EOL
|
||||
- Switched from Rubocop to cookstyle for linting
|
||||
- Removed yum/apt from the Berksfile
|
||||
- Remove test dependencies from the Gemfile and instead use ChefDK for testing
|
||||
|
||||
## 1.1.0 (2016-04-27)
|
||||
|
||||
- Added a chefignore file
|
||||
- Loosen the dependency on mysql cookbook to allow for the use of the latest version
|
||||
- Added source_url and issue_url metadata
|
||||
- Added long_description metadata
|
||||
- Removed the AWS based Test Kitchen testing and replaced with with kitchen-docker in Travis
|
||||
- Updated Chefspec format to remove deprecation warnings
|
||||
- Added Oracle Linux to the metadata
|
||||
|
||||
## 1.0.2 (2015-06-29)
|
||||
|
||||
1.0.2 (2015-06-29)
|
||||
------------------
|
||||
- Updating metadata to depend on mysql ~> 6.0
|
||||
|
||||
1.0.1 (2014-12-25)
|
||||
------------------
|
||||
## 1.0.1 (2014-12-25)
|
||||
|
||||
- Moving from recipe_eval in to include_recipe LWRP
|
||||
|
||||
1.0.0 (2014-12-23)
|
||||
------------------
|
||||
## 1.0.0 (2014-12-23)
|
||||
|
||||
- Replacing recipes with resources
|
||||
- Mysql and MariaDB providers for linking mysql2 gem
|
||||
- Expanded platform test coverage
|
||||
|
||||
0.1.1 (2014-09-15)
|
||||
------------------
|
||||
## 0.1.1 (2014-09-15)
|
||||
|
||||
- Correct a typo in documentation
|
||||
- Correct a test failing with Travis CI
|
||||
|
||||
0.1.0 (2014-09-15)
|
||||
------------------
|
||||
## 0.1.0 (2014-09-15)
|
||||
|
||||
- Correct documentation
|
||||
- Correct rubocop offenses
|
||||
|
||||
0.0.3 (2014-09-12)
|
||||
------------------
|
||||
## 0.0.3 (2014-09-12)
|
||||
|
||||
- Initial release (copy of mysql-chef_gem, but for mysql2)
|
||||
|
@ -1,29 +1,20 @@
|
||||
Mysql2 Chef Gem Installer Cookbook
|
||||
==================================
|
||||
# Mysql2 Chef Gem Installer Cookbook
|
||||
|
||||
[](https://travis-ci.org/sinfomicien/mysql2_chef_gem)
|
||||
[](https://travis-ci.org/sinfomicien/mysql2_chef_gem) [](https://supermarket.chef.io/cookbooks/mysql2_chef_gem)
|
||||
|
||||
mysql2_chef_gem is a library cookbook that provides an LWRP for use
|
||||
in recipes. It provides a wrapper around `chef_gem` called
|
||||
`mysql2_chef_gem` that eases the installation process, collecting the
|
||||
prerequisites and side-stepping the compilation phase arms race.
|
||||
mysql2_chef_gem is a library cookbook that provides a resource for installing the mysql2 gem against either mysql or mariadb depending on usage.
|
||||
|
||||
Scope
|
||||
-----
|
||||
This cookbook is concerned with the installation of the `mysql2`
|
||||
Rubygem into Chef's gem path. Installation into other Ruby
|
||||
environments, or installation of related gems such as `mysql` are
|
||||
outside the scope of this cookbook.
|
||||
## Scope
|
||||
|
||||
Requirements
|
||||
------------
|
||||
* Chef 11 or higher
|
||||
* Ruby 1.9 (preferably from the Chef full-stack installer)
|
||||
This cookbook is concerned with the installation of the `mysql2` Rubygem into Chef's gem path. Installation into other Ruby environments, or installation of related gems such as `mysql` are outside the scope of this cookbook.
|
||||
|
||||
Platform Support
|
||||
----------------
|
||||
The following platforms have been tested with Test Kitchen and are
|
||||
known to work.
|
||||
## Requirements
|
||||
|
||||
- Chef 12.5+
|
||||
|
||||
## Platform Support
|
||||
|
||||
The following platforms have been tested with Test Kitchen and are known to work.
|
||||
|
||||
```
|
||||
|---------------------------------------+-----+-----+-----+-----+-----|
|
||||
@ -35,27 +26,24 @@ known to work.
|
||||
|---------------------------------------+-----+-----+-----+-----+-----|
|
||||
| Mysql2ChefGem::Mysql / centos-7 | | | X | X | X |
|
||||
|---------------------------------------+-----+-----+-----+-----+-----|
|
||||
| Mysql2ChefGem::Mysql / fedora-20 | | | X | X | X |
|
||||
| Mysql2ChefGem::Mysql / fedora | | | X | X | X |
|
||||
|---------------------------------------+-----+-----+-----+-----+-----|
|
||||
| Mysql2ChefGem::Mysql / debian-7 | | | X | | |
|
||||
|---------------------------------------+-----+-----+-----+-----+-----|
|
||||
| Mysql2ChefGem::Mysql / ubuntu-10.04 | | X | | | |
|
||||
|---------------------------------------+-----+-----+-----+-----+-----|
|
||||
| Mysql2ChefGem::Mysql / ubuntu-12.04 | | | X | | |
|
||||
|---------------------------------------+-----+-----+-----+-----+-----|
|
||||
| Mysql2ChefGem::Mysql / ubuntu-14.04 | | | X | X | |
|
||||
|---------------------------------------+-----+-----+-----+-----+-----|
|
||||
| Mysql2ChefGem::Mariadb / fedora-20 | | | X | | |
|
||||
| Mysql2ChefGem::Mariadb / fedora | | | X | | |
|
||||
|---------------------------------------+-----+-----+-----+-----+-----|
|
||||
| Mysql2ChefGem::Mariadb / ubuntu-14.04 | | | X | | |
|
||||
|---------------------------------------+-----+-----+-----+-----+-----|
|
||||
```
|
||||
|
||||
Usage
|
||||
-----
|
||||
## Usage
|
||||
|
||||
Place a dependency on the mysql cookbook in your cookbook's metadata.rb
|
||||
|
||||
```ruby
|
||||
depends 'mysql2_chef_gem', '~> 1.0'
|
||||
depends 'mysql2_chef_gem'
|
||||
```
|
||||
|
||||
Then, in a recipe:
|
||||
@ -66,43 +54,61 @@ mysql2_chef_gem 'default' do
|
||||
end
|
||||
```
|
||||
|
||||
Resources Overview
|
||||
------------------
|
||||
### 2.0 Compatibility
|
||||
|
||||
In order to ensure compatibility with Chef 13, the 2.0 release of this cookbook changed the method used to specify installation against mariadb. Instead of specifying the underlying provider, you instead reference the mariadb specific resource. See the example below for the new syntax.
|
||||
|
||||
## Resources Overview
|
||||
|
||||
### mysql2_chef_gem
|
||||
|
||||
The `mysql2_chef_gem` resource the build dependencies and installation
|
||||
of the `mysql2` rubygem into Chef's Ruby environment
|
||||
The `mysql2_chef_gem` resource installs mysql client development dependencies and installs the `mysql2` rubygem into Chef's Ruby environment.
|
||||
|
||||
#### Example
|
||||
|
||||
```ruby
|
||||
mysql2_chef_gem 'default' do
|
||||
gem_version '0.3.17'
|
||||
gem_version '0.4.5'
|
||||
action :install
|
||||
end
|
||||
```
|
||||
#### Parameters
|
||||
- `gem_version` - The version of the `mysql` Rubygem to install into
|
||||
the Chef environment. Defaults to '0.3.17'
|
||||
connector libraries
|
||||
- `client_version` - The version of the mysql client libraries to
|
||||
install and link against
|
||||
|
||||
#### Properties
|
||||
|
||||
- `gem_version` - The version of the `mysql` Rubygem to install into the Chef environment. Defaults to '0.4.5' connector libraries
|
||||
- `package_version` - The version of the mysql client libraries to install and link against
|
||||
|
||||
#### Actions
|
||||
|
||||
- `:install` - Build and install the gem into the Chef environment
|
||||
- `:remove` - Delete the gem from the Chef environment
|
||||
|
||||
#### Providers
|
||||
Chef selects a default provider based on platform and version,
|
||||
but you can specify one if your platform support it.
|
||||
### mysql2_chef_gem_mariadb
|
||||
|
||||
To install the mysql2 gem against an installation of mariadb reference the `mysql2_chef_gem_mariadb` resource directly. This resource includes all the same properties of the standard `mysql2_chef_gem` resource.
|
||||
|
||||
```ruby
|
||||
mysql2_chef_gem 'default' do
|
||||
provider Chef::Provider::Mysql2ChefGem::Mariadb
|
||||
mysql2_chef_gem_mariadb 'default' do
|
||||
action :install
|
||||
end
|
||||
```
|
||||
|
||||
Authors
|
||||
-------
|
||||
- Author:: Sean OMeara (<someara@chef.io>)
|
||||
- Author:: Nicolas Blanc(<sinfomicien@gmail.com>)
|
||||
## License & Authors
|
||||
|
||||
- Author:: Sean OMeara ([someara@sean.io](mailto:someara@sean.io))
|
||||
- Author:: Tim Smith ([tsmith@chef.io](mailto:tsmith@chef.io))
|
||||
- Author:: Nicolas Blanc([sinfomicien@gmail.com](mailto:sinfomicien@gmail.com))
|
||||
|
||||
```
|
||||
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.
|
||||
```
|
||||
|
@ -1,37 +0,0 @@
|
||||
class Chef
|
||||
class Provider
|
||||
class Mysql2ChefGem
|
||||
class Mariadb < Chef::Provider::LWRPBase
|
||||
use_inline_resources if defined?(use_inline_resources)
|
||||
|
||||
def whyrun_supported?
|
||||
true
|
||||
end
|
||||
|
||||
action :install do
|
||||
recipe_eval do
|
||||
run_context.include_recipe 'build-essential::default'
|
||||
end
|
||||
|
||||
# As a recipe: must rely on global node attributes
|
||||
recipe_eval do
|
||||
run_context.include_recipe 'mariadb::client'
|
||||
end
|
||||
|
||||
gem_package 'mysql2' do
|
||||
gem_binary RbConfig::CONFIG['bindir'] + '/gem'
|
||||
version new_resource.gem_version
|
||||
action :install
|
||||
end
|
||||
end
|
||||
|
||||
action :remove do
|
||||
gem_package 'mysql2' do
|
||||
gem_binary RbConfig::CONFIG['bindir'] + '/gem'
|
||||
action :remove
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,37 +0,0 @@
|
||||
class Chef
|
||||
class Provider
|
||||
class Mysql2ChefGem
|
||||
class Mysql < Chef::Provider::LWRPBase
|
||||
include Chef::DSL::IncludeRecipe
|
||||
use_inline_resources if defined?(use_inline_resources)
|
||||
|
||||
def whyrun_supported?
|
||||
true
|
||||
end
|
||||
|
||||
action :install do
|
||||
include_recipe 'build-essential::default'
|
||||
|
||||
# As a resource: can pass version from calling recipe
|
||||
mysql_client 'default' do
|
||||
version new_resource.client_version
|
||||
action :create
|
||||
end
|
||||
|
||||
gem_package 'mysql2' do
|
||||
gem_binary RbConfig::CONFIG['bindir'] + '/gem'
|
||||
version new_resource.gem_version
|
||||
action :install
|
||||
end
|
||||
end
|
||||
|
||||
action :remove do
|
||||
gem_package 'mysql2' do
|
||||
gem_binary RbConfig::CONFIG['bindir'] + '/gem'
|
||||
action :remove
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,15 +0,0 @@
|
||||
require 'chef/resource/lwrp_base'
|
||||
|
||||
class Chef
|
||||
class Resource
|
||||
class Mysql2ChefGem < Chef::Resource::LWRPBase
|
||||
self.resource_name = :mysql2_chef_gem
|
||||
actions :install, :remove
|
||||
default_action :install
|
||||
|
||||
attribute :mysql2_chef_gem_name, kind_of: String, name_attribute: true, required: true
|
||||
attribute :gem_version, kind_of: String, default: '0.3.17'
|
||||
attribute :client_version, kind_of: String, default: nil
|
||||
end
|
||||
end
|
||||
end
|
@ -1,17 +0,0 @@
|
||||
#########
|
||||
# mysql2_chef_gem
|
||||
#########
|
||||
Chef::Platform.set platform: :amazon, resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql
|
||||
Chef::Platform.set platform: :centos, version: '< 7.0', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql
|
||||
Chef::Platform.set platform: :centos, version: '>= 7.0', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql
|
||||
Chef::Platform.set platform: :debian, resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql
|
||||
Chef::Platform.set platform: :fedora, version: '< 19', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql
|
||||
Chef::Platform.set platform: :fedora, version: '>= 19', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql
|
||||
Chef::Platform.set platform: :omnios, resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql
|
||||
Chef::Platform.set platform: :redhat, version: '< 7.0', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql
|
||||
Chef::Platform.set platform: :redhat, version: '>= 7.0', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql
|
||||
Chef::Platform.set platform: :scientific, version: '< 7.0', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql
|
||||
Chef::Platform.set platform: :scientific, version: '>= 7.0', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql
|
||||
Chef::Platform.set platform: :smartos, resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql
|
||||
Chef::Platform.set platform: :suse, resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql
|
||||
Chef::Platform.set platform: :ubuntu, resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,29 @@
|
||||
property :mysql2_chef_gem_name, String, name_attribute: true, required: true
|
||||
property :gem_version, String, default: '0.4.5'
|
||||
property :package_version, String
|
||||
|
||||
provides :mysql2_chef_gem_mariadb
|
||||
|
||||
action :install do
|
||||
recipe_eval do
|
||||
run_context.include_recipe 'build-essential::default'
|
||||
end
|
||||
|
||||
# As a recipe: must rely on global node attributes
|
||||
recipe_eval do
|
||||
run_context.include_recipe 'mariadb::client'
|
||||
end
|
||||
|
||||
gem_package 'mysql2' do
|
||||
gem_binary RbConfig::CONFIG['bindir'] + '/gem'
|
||||
version new_resource.gem_version
|
||||
action :install
|
||||
end
|
||||
end
|
||||
|
||||
action :remove do
|
||||
gem_package 'mysql2' do
|
||||
gem_binary RbConfig::CONFIG['bindir'] + '/gem'
|
||||
action :remove
|
||||
end
|
||||
end
|
29
cookbooks/mysql2_chef_gem/resources/mysql2_chef_gem_mysql.rb
Normal file
29
cookbooks/mysql2_chef_gem/resources/mysql2_chef_gem_mysql.rb
Normal file
@ -0,0 +1,29 @@
|
||||
property :mysql2_chef_gem_name, String, name_attribute: true, required: true
|
||||
property :gem_version, String, default: '0.4.5'
|
||||
property :package_version, String
|
||||
|
||||
provides :mysql2_chef_gem
|
||||
provides :mysql2_chef_gem_mysql
|
||||
|
||||
action :install do
|
||||
include_recipe 'build-essential::default'
|
||||
|
||||
# As a resource: can pass version from calling recipe
|
||||
mysql_client 'default' do
|
||||
version new_resource.package_version if new_resource.package_version
|
||||
action :create
|
||||
end
|
||||
|
||||
gem_package 'mysql2' do
|
||||
gem_binary RbConfig::CONFIG['bindir'] + '/gem'
|
||||
version new_resource.gem_version
|
||||
action :install
|
||||
end
|
||||
end
|
||||
|
||||
action :remove do
|
||||
gem_package 'mysql2' do
|
||||
gem_binary RbConfig::CONFIG['bindir'] + '/gem'
|
||||
action :remove
|
||||
end
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user