diff --git a/Berksfile b/Berksfile index 506f109..a884cb4 100644 --- a/Berksfile +++ b/Berksfile @@ -7,36 +7,33 @@ cookbook 'firewall', '~> 6.2.16' cookbook 'redisio', '~> 6.4.1' cookbook 'ruby_build', '~> 2.5.0' -cookbook 'mediawiki', - git: 'https://github.com/67P/mediawiki-cookbook.git', - ref: 'nginx' -cookbook 'postfix', '= 5.0.2' -cookbook 'php', '~> 8.0.0' -cookbook 'composer', '~> 2.7.0' -cookbook 'users', '~> 5.3.1' -cookbook 'hostname', '= 0.4.2' -cookbook 'nginx', '= 9.0.0' -cookbook 'fail2ban', '~> 7.0.4' -cookbook 'mysql', '~> 8.7.3' -# cookbook 'postgresql', '= 7.1.8' -cookbook 'apt', '~> 7.3.0' -cookbook 'git', '~> 10.0.0' -cookbook 'hostsfile', '~> 3.0.1' -cookbook 'ohai', '~> 5.2.5' -cookbook 'nodejs', '~> 7.3.1' -cookbook 'timezone_iii', '= 1.0.4' -cookbook 'ark', '>= 5.0.0' -cookbook 'logrotate', '= 2.2.0' -cookbook 'openssl', '~> 8.5.5' -cookbook 'ntp', '= 3.4.0' -cookbook 'apache2', '= 3.3.0' -cookbook 'compat_resource', '= 12.19.0' -cookbook 'homebrew', '= 3.0.0' -cookbook 'mariadb', '= 0.3.1' cookbook 'ipfs', git: 'https://gitea.kosmos.org/kosmos/ipfs-cookbook.git', ref: 'v0.7.0' -cookbook 'java', '~> 4.3.0' -cookbook 'ulimit', '~> 1.0.0' +cookbook 'mediawiki', + git: 'https://github.com/67P/mediawiki-cookbook.git', + ref: 'nginx' + +cookbook 'apache2', '= 3.3.0' +cookbook 'apt', '~> 7.3.0' +cookbook 'ark', '>= 5.0.0' +cookbook 'composer', '~> 2.7.0' +cookbook 'fail2ban', '~> 7.0.4' +cookbook 'git', '~> 10.0.0' cookbook 'golang', '~> 5.3.1' +cookbook 'hostname', '= 0.4.2' +cookbook 'hostsfile', '~> 3.0.1' +cookbook 'java', '~> 4.3.0' +cookbook 'logrotate', '= 2.2.0' +cookbook 'mysql', '~> 8.7.3' +cookbook 'nginx', '= 9.0.0' +cookbook 'nodejs', '~> 7.3.1' +cookbook 'ntp', '= 3.4.0' +cookbook 'ohai', '~> 5.2.5' +cookbook 'openssl', '~> 8.5.5' +cookbook 'php', '~> 8.0.0' +cookbook 'postfix', '= 5.0.2' +cookbook 'timezone_iii', '= 1.0.4' +cookbook 'ulimit', '~> 1.0.0' +cookbook 'users', '~> 5.3.1' cookbook 'zerotier', '~> 1.0.7' diff --git a/Berksfile.lock b/Berksfile.lock index 10b2561..cc81edd 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -2,14 +2,12 @@ DEPENDENCIES apache2 (= 3.3.0) apt (~> 7.3.0) ark (>= 5.0.0) - compat_resource (= 12.19.0) composer (~> 2.7.0) elasticsearch (~> 5.1.3) fail2ban (~> 7.0.4) firewall (~> 6.2.16) git (~> 10.0.0) golang (~> 5.3.1) - homebrew (= 3.0.0) hostname (= 0.4.2) hostsfile (~> 3.0.1) ipfs @@ -18,7 +16,6 @@ DEPENDENCIES ref: v0.7.0 java (~> 4.3.0) logrotate (= 2.2.0) - mariadb (= 0.3.1) mediawiki git: https://github.com/67P/mediawiki-cookbook.git revision: 78641e53635ba6cbd4a2a51fd597adb8fef1e8ad @@ -47,7 +44,6 @@ GRAPH mingw (>= 1.1) seven_zip (>= 0.0.0) chocolatey (3.0.0) - compat_resource (12.19.0) composer (2.7.0) apt (>= 0.0.0) php (>= 0.0.0) @@ -60,7 +56,7 @@ GRAPH git (10.0.0) golang (5.3.1) ark (>= 6.0) - homebrew (3.0.0) + homebrew (5.4.1) hostname (0.4.2) hostsfile (>= 0.0.0) hostsfile (3.0.1) @@ -70,10 +66,6 @@ GRAPH homebrew (>= 0.0.0) windows (>= 0.0.0) logrotate (2.2.0) - mariadb (0.3.1) - apt (>= 0.0.0) - yum (>= 0.0.0) - yum-epel (>= 0.0.0) mediawiki (0.5.0) apache2 (>= 0.0.0) nginx (>= 0.0.0) @@ -105,7 +97,6 @@ GRAPH ulimit (1.0.0) users (5.3.1) windows (7.0.2) - yum (7.2.0) yum-epel (4.2.3) zerotier (1.0.7) ohai (>= 0.0.0) diff --git a/cookbooks/compat_resource/CHANGELOG.md b/cookbooks/compat_resource/CHANGELOG.md deleted file mode 100644 index 7908196..0000000 --- a/cookbooks/compat_resource/CHANGELOG.md +++ /dev/null @@ -1,53 +0,0 @@ -# compat_resource Cookbook CHANGELOG - -This file is used to list changes made in each version of the compat_resource cookbook. - -## 12.19.0 (2017-04-17) - -- Suppress warning already initialized constant -- Backport yum/apt changes from 12.19 - -## 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 diff --git a/cookbooks/compat_resource/CONTRIBUTING.md b/cookbooks/compat_resource/CONTRIBUTING.md deleted file mode 100644 index ef2f2b8..0000000 --- a/cookbooks/compat_resource/CONTRIBUTING.md +++ /dev/null @@ -1,2 +0,0 @@ -Please refer to -https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD diff --git a/cookbooks/compat_resource/MAINTAINERS.md b/cookbooks/compat_resource/MAINTAINERS.md deleted file mode 100644 index 5ae0806..0000000 --- a/cookbooks/compat_resource/MAINTAINERS.md +++ /dev/null @@ -1,16 +0,0 @@ - - -# 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 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 -* [Lamont Granquist](https://github.com/lamont-granquist) - -# Maintainers -* [Jennifer Davis](https://github.com/sigje) -* [Tim Smith](https://github.com/tas50) -* [Thom May](https://github.com/thommay) -* [Lamont Granquist](https://github.com/lamont-granquist) diff --git a/cookbooks/compat_resource/README.md b/cookbooks/compat_resource/README.md deleted file mode 100644 index f5c17e5..0000000 --- a/cookbooks/compat_resource/README.md +++ /dev/null @@ -1,60 +0,0 @@ -# compat_resource cookbook - -[![Build Status](https://travis-ci.org/chef-cookbooks/compat_resource.svg?branch=master)](https://travis-ci.org/chef-cookbooks/compat_resource) [![Cookbook Version](https://img.shields.io/cookbook/v/compat_resource.svg)](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: -- Slides: - -## 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. -``` diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef.rb deleted file mode 100644 index 219b05b..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/constants.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/constants.rb deleted file mode 100644 index 4acd742..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/constants.rb +++ /dev/null @@ -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 -# 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/delayed_evaluator.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/delayed_evaluator.rb deleted file mode 100644 index 4fb687e..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/delayed_evaluator.rb +++ /dev/null @@ -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 -# 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/core.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/core.rb deleted file mode 100644 index 8e30d30..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/core.rb +++ /dev/null @@ -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 () -# 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. -# - -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/declare_resource.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/declare_resource.rb deleted file mode 100644 index 45e69dc..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/declare_resource.rb +++ /dev/null @@ -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 () -# 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/platform_introspection.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/platform_introspection.rb deleted file mode 100644 index 7886000..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/platform_introspection.rb +++ /dev/null @@ -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 () -# 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/recipe.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/recipe.rb deleted file mode 100644 index f896ec7..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/recipe.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/universal.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/universal.rb deleted file mode 100644 index 7f529f1..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/universal.rb +++ /dev/null @@ -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 () -# 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. -# - -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/lazy_module_include.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/lazy_module_include.rb deleted file mode 100644 index a6b5244..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/lazy_module_include.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/notifying_block.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/notifying_block.rb deleted file mode 100644 index 0b90e27..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/notifying_block.rb +++ /dev/null @@ -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 -# 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/params_validate.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/params_validate.rb deleted file mode 100644 index 0a16147..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/params_validate.rb +++ /dev/null @@ -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 () -# 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] 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] :regex An object, or - # list of objects, that must match the value with `regex.match(value)`. - # (See #_pv_regex) - # @option opts [Class,Array] :kind_of A class, or - # list of classes, that the value must be an instance of. (See - # #_pv_kind_of.) - # @option opts [Hash] :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] :respond_to A method - # name, or list of method names, the value must respond to. (See - # #_pv_respond_to.) - # @option opts [Symbol,Array] :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.?` All responses must be false for the value to be - # valid. - # Values which do not respond to ? 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 "`. - # - # @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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/powershell_out.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/powershell_out.rb deleted file mode 100644 index b6b56f9..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/powershell_out.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/properties.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/properties.rb deleted file mode 100644 index bdf9f7e..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/properties.rb +++ /dev/null @@ -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] 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] The type(s) of this property. - # If present, this is prepended to the `is` validation option. - # @param options [Hash] 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] :regex An object, or - # list of objects, that must match the value with `regex.match(value)`. - # @option options [Class,Array] :kind_of A class, or - # list of classes, that the value must be an instance of. - # @option options [Hash] :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] :respond_to A method - # name, or list of method names, the value must respond to. - # @option options [Symbol,Array] :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] 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] A list of property names to set as desired - # state. - # - # @return [Array] 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] A list of property names to set as the identity. - # - # @return [Array] 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/property.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/property.rb deleted file mode 100644 index 3399596..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/property.rb +++ /dev/null @@ -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 -# 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] 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] 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 `@`. - # `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 || ""}#{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 `@` - # - # @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] - # - 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] 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb deleted file mode 100644 index 7ccf87b..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_repository.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_repository.rb deleted file mode 100644 index ccc07c4..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_repository.rb +++ /dev/null @@ -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 () -# 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_update.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_update.rb deleted file mode 100644 index 677cb57..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_update.rb +++ /dev/null @@ -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 () -# 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/noop.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/noop.rb deleted file mode 100644 index 87c34e6..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/noop.rb +++ /dev/null @@ -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 () -# 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/support/yum_repo.erb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/support/yum_repo.erb deleted file mode 100644 index 6f13255..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/support/yum_repo.erb +++ /dev/null @@ -1,132 +0,0 @@ -# This file was generated by Chef -# Do NOT modify this file by hand. - -[<%= @config.repositoryid %>] -name=<%= @config.description %> -<% if @config.baseurl %> -baseurl=<%= case @config.baseurl - when Array - @config.baseurl.join("\n") - else - @config.baseurl - end %> -<% end -%> -<% if @config.cost %> -cost=<%= @config.cost %> -<% end %> -<% if @config.enabled %> -enabled=1 -<% else %> -enabled=0 -<% end %> -<% if @config.enablegroups %> -enablegroups=1 -<% end %> -<% if @config.exclude %> -exclude=<%= @config.exclude %> -<% end %> -<% if @config.failovermethod %> -failovermethod=<%= @config.failovermethod %> -<% end %> -<% if @config.fastestmirror_enabled %> -fastestmirror_enabled=1 -<% else %> -fastestmirror_enabled=0 -<% end %> -<% if @config.gpgcheck %> -gpgcheck=1 -<% else %> -gpgcheck=0 -<% end %> -<% if @config.gpgkey %> -gpgkey=<%= case @config.gpgkey - when Array - @config.gpgkey.join("\n ") - else - @config.gpgkey - end %> -<% end -%> -<% if @config.http_caching %> -http_caching=<%= @config.http_caching %> -<% end %> -<% if @config.include_config %> -include=<%= @config.include_config %> -<% end %> -<% if @config.includepkgs %> -includepkgs=<%= @config.includepkgs %> -<% end %> -<% if @config.keepalive %> -keepalive=1 -<% end %> -<% if @config.metadata_expire %> -metadata_expire=<%= @config.metadata_expire %> -<% end %> -<% if @config.mirrorlist %> -mirrorlist=<%= @config.mirrorlist %> -<% end %> -<% if @config.mirror_expire %> -mirror_expire=<%= @config.mirror_expire %> -<% end %> -<% if @config.mirrorlist_expire %> -mirrorlist_expire=<%= @config.mirrorlist_expire %> -<% end %> -<% if @config.priority %> -priority=<%= @config.priority %> -<% end %> -<% if @config.proxy %> -proxy=<%= @config.proxy %> -<% end %> -<% if @config.proxy_username %> -proxy_username=<%= @config.proxy_username %> -<% end %> -<% if @config.proxy_password %> -proxy_password=<%= @config.proxy_password %> -<% end %> -<% if @config.username %> -username=<%= @config.username %> -<% end %> -<% if @config.password %> -password=<%= @config.password %> -<% end %> -<% if @config.repo_gpgcheck %> -repo_gpgcheck=1 -<% end %> -<% if @config.max_retries %> -retries=<%= @config.max_retries %> -<% end %> -<% if @config.report_instanceid %> -report_instanceid=<%= @config.report_instanceid %> -<% end %> -<% if @config.skip_if_unavailable %> -skip_if_unavailable=1 -<% end %> -<% if @config.sslcacert %> -sslcacert=<%= @config.sslcacert %> -<% end %> -<% if @config.sslclientcert %> -sslclientcert=<%= @config.sslclientcert %> -<% end %> -<% if @config.sslclientkey %> -sslclientkey=<%= @config.sslclientkey %> -<% end %> -<% unless @config.sslverify.nil? %> -sslverify=<%= ( @config.sslverify ) ? 'true' : 'false' %> -<% end %> -<% if @config.timeout %> -timeout=<%= @config.timeout %> -<% end %> -<% if @config.options -%> -<% @config.options.each do |key, value| -%> -<%= key %>=<%= - case value - when Array - value.join("\n ") - when TrueClass - '1' - when FalseClass - '0' - else - value - end %> -<% end -%> -<% end -%> diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/systemd_unit.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/systemd_unit.rb deleted file mode 100644 index 1024cb8..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/systemd_unit.rb +++ /dev/null @@ -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 () -# 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/yum_repository.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/yum_repository.rb deleted file mode 100644 index 51453d2..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/yum_repository.rb +++ /dev/null @@ -1,136 +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 () -# 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 - # clean the repo cache first - declare_resource(:execute, "yum clean all #{new_resource.repositoryid}") do - command "yum clean all --disablerepo=* --enablerepo=#{new_resource.repositoryid}" - only_if "yum repolist all | grep -P '^#{new_resource.repositoryid}([ \t]|$)'" - end - - declare_resource(:file, "/etc/yum.repos.d/#{new_resource.repositoryid}.repo") do - action :delete - notifies :create, "ruby_block[yum-cache-reload-#{new_resource.repositoryid}]", :immediately - 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource.rb deleted file mode 100644 index e5c9a14..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/action_class.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/action_class.rb deleted file mode 100644 index 20ff8e5..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/action_class.rb +++ /dev/null @@ -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 ("} action #{action ? action.inspect : ""}" - 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/apt_repository.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/apt_repository.rb deleted file mode 100644 index bedfd3e..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/apt_repository.rb +++ /dev/null @@ -1,65 +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 () -# 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 - - default_action :add - allowed_actions :add, :remove - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/apt_update.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/apt_update.rb deleted file mode 100644 index 9acd9ae..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/apt_update.rb +++ /dev/null @@ -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 () -# 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 - - property :frequency, Integer, default: 86_400 - - default_action :periodic - allowed_actions :update, :periodic - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/systemd_unit.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/systemd_unit.rb deleted file mode 100644 index 5f9f458..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/systemd_unit.rb +++ /dev/null @@ -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 () -# 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/yum_repository.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/yum_repository.rb deleted file mode 100644 index 97cf23a..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/yum_repository.rb +++ /dev/null @@ -1,97 +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 () -# 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, Array], 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 :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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource_builder.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource_builder.rb deleted file mode 100644 index 688e856..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource_builder.rb +++ /dev/null @@ -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 () -# 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/mixin/properties.rb b/cookbooks/compat_resource/files/lib/chef_compat/mixin/properties.rb deleted file mode 100644 index a3920d1..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/mixin/properties.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches.rb deleted file mode 100644 index 9ac83e8..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef.rb deleted file mode 100644 index 9669f6a..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef.rb +++ /dev/null @@ -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<= 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/node.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/node.rb deleted file mode 100644 index 93379b0..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/node.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/property.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/property.rb deleted file mode 100644 index 2308d32..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/property.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/provider.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/provider.rb deleted file mode 100644 index 591cedb..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/provider.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/recipe.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/recipe.rb deleted file mode 100644 index 7c4c8be..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/recipe.rb +++ /dev/null @@ -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 () -# 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. -# - -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:: A list of tags - # - # === Returns - # true:: If all the parameters are present - # false:: 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:: A list of tags - # - # === Returns - # tags:: 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/recipe_hook.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/recipe_hook.rb deleted file mode 100644 index 24aa20f..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/recipe_hook.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource.rb deleted file mode 100644 index d61b60b..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource/lwrp_base.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource/lwrp_base.rb deleted file mode 100644 index 5f098fd..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource/lwrp_base.rb +++ /dev/null @@ -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<) -# 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection.rb deleted file mode 100644 index 4f07489..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection.rb +++ /dev/null @@ -1,103 +0,0 @@ -# -# Author:: Adam Jacob () -# 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. -# - -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_list.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_list.rb deleted file mode 100644 index dfbd442..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_list.rb +++ /dev/null @@ -1,49 +0,0 @@ -# -# Author:: Tyler Ball () -# 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_set.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_set.rb deleted file mode 100644 index bcead10..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_set.rb +++ /dev/null @@ -1,49 +0,0 @@ -# -# Author:: Tyler Ball () -# 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/run_context.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/run_context.rb deleted file mode 100644 index 03c9d60..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/run_context.rb +++ /dev/null @@ -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 () -# Author:: Christopher Walters () -# Author:: Tim Hinderliter () -# 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 - # => - # - 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 - # => - # - 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 - # => - # - 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb deleted file mode 100644 index 9add7a8..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb +++ /dev/null @@ -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 () -# Author:: Christopher Walters () -# Author:: Tim Hinderliter () -# 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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/property.rb b/cookbooks/compat_resource/files/lib/chef_compat/property.rb deleted file mode 100644 index be21113..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/property.rb +++ /dev/null @@ -1,6 +0,0 @@ -require 'chef_compat/copied_from_chef/chef/property' - -module ChefCompat - class Property < ChefCompat::CopiedFromChef::Chef::Property - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/recipe.rb b/cookbooks/compat_resource/files/lib/chef_compat/recipe.rb deleted file mode 100644 index 86e39d9..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/recipe.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/resource.rb b/cookbooks/compat_resource/files/lib/chef_compat/resource.rb deleted file mode 100644 index bcf0fdb..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/resource.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/files/lib/chef_compat/resource/lwrp_base.rb b/cookbooks/compat_resource/files/lib/chef_compat/resource/lwrp_base.rb deleted file mode 100644 index 2ebb98f..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/resource/lwrp_base.rb +++ /dev/null @@ -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<= 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 diff --git a/cookbooks/compat_resource/libraries/autoload.rb b/cookbooks/compat_resource/libraries/autoload.rb deleted file mode 100644 index db52cfc..0000000 --- a/cookbooks/compat_resource/libraries/autoload.rb +++ /dev/null @@ -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 diff --git a/cookbooks/compat_resource/metadata.json b/cookbooks/compat_resource/metadata.json deleted file mode 100644 index 1df2f5d..0000000 --- a/cookbooks/compat_resource/metadata.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"compat_resource","version":"12.19.0","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[![Build Status](https://travis-ci.org/chef-cookbooks/compat_resource.svg?branch=master)](https://travis-ci.org/chef-cookbooks/compat_resource) [![Cookbook Version](https://img.shields.io/cookbook/v/compat_resource.svg)](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: \n- Slides: \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":[]} \ No newline at end of file diff --git a/cookbooks/homebrew/.markdownlint-cli2.yaml b/cookbooks/homebrew/.markdownlint-cli2.yaml new file mode 100644 index 0000000..6fa8e77 --- /dev/null +++ b/cookbooks/homebrew/.markdownlint-cli2.yaml @@ -0,0 +1,5 @@ +config: + ul-indent: false # MD007 + line-length: false # MD013 + no-duplicate-heading: false # MD024 + reference-links-images: false # MD052 diff --git a/cookbooks/homebrew/CHANGELOG.md b/cookbooks/homebrew/CHANGELOG.md index b63b898..d179af1 100644 --- a/cookbooks/homebrew/CHANGELOG.md +++ b/cookbooks/homebrew/CHANGELOG.md @@ -2,6 +2,177 @@ This file is used to list changes made in each version of the homebrew cookbook. +## 5.4.1 - *2023-06-01* + +## 5.4.0 - *2023-04-24* + +- Add temporary sudoers entry to fix homebrew installation + +## 5.3.8 - *2023-04-16* + +Standardise files with files in sous-chefs/repo-management + +## 5.3.7 - *2023-04-04* + +- Sous Chefs adoption +- Update lint-unit workflow to 2.0.2 +- Set unified_mode for all resources + - Require Chef 15.3+ for unified_mode +- Standardise files with files in sous-chefs/repo-management + +## 5.3.6 - *2023-04-01* + +- Standardise files with files in sous-chefs/repo-management + +## 5.3.5 - *2023-03-02* + +- Standardise files with files in sous-chefs/repo-management + +## 5.3.4 - *2023-02-20* + +- Standardise files with files in sous-chefs/repo-management + +## 5.3.4 - *2023-02-20* + +- Standardise files with files in sous-chefs/repo-management + +## 5.3.3 - *2023-02-14* + +- Standardise files with files in sous-chefs/repo-management + +## 5.3.2 - *2022-12-15* + +- Standardise files with files in sous-chefs/repo-management +- Fix workflow CI + +## 5.3.1 - *2022-02-10* + +- Standardise files with files in sous-chefs/repo-management +- Remove delivery folder + +## 5.3.0 - *2021-12-21* + +- Update to support Apple M1 silicon (arm64) Homebrew install location (`/opt/homebrew`) + - Add HomebrewWrapper.repository_path() for homebrew_tap resource idempotency + - Add HomebrewWrapper.repository_path() helper for Apple M1 silicon (arm64) + - Remove deprecated `--full` option for Homebrew (Breaking upstream CLI change!) + - Add chefspec tests for Apple M1 silicon Homebrew path helper + - Add InSpec tests for macOS M1 / arm64 and x86_64 + - Set `use_sudo: false` for InSpec tests to work properly + - Convert hardcoded /usr/local to use install_path() for M1 /opt/homebrew support + - Add Homebrew.install_path() helper for Apple M1 silicon (arm64) + +## 5.2.2 - *2021-08-30* + +- Standardise files with files in sous-chefs/repo-management + +## 5.2.1 - *2021-06-01* + +- Standardise files with files in sous-chefs/repo-management + +## 5.2.0 - *2021-01-24* + +- Sous Chefs Adoption +- Standardise files with files in sous-chefs/repo-management + +## 5.1.1 (2021-01-04) + +- Update to use --cask instead of cask command for compatibility with newer homebrew releases- [@tas50](https://github.com/tas50) +- resolved cookstyle error: resources/cask.rb:23:1 warning: `ChefDeprecations/ResourceUsesOnlyResourceName` +- resolved cookstyle error: resources/tap.rb:23:1 warning: `ChefDeprecations/ResourceUsesOnlyResourceName` + +## 5.1.0 (2020-05-15) + +- Rename the kitchen config - [@tas50](https://github.com/tas50) +- Cookstyle fixes - [@tas50](https://github.com/tas50) +- OS X -> macOS in the readme - [@tas50](https://github.com/tas50) +- Require Chef 12.15+ - [@tas50](https://github.com/tas50) +- Update default install script from ruby to bash - [@bbros-dev](https://github.com/bbros-dev) +- Resole chefspec failures - [@tas50](https://github.com/tas50) + +## 5.0.8 (2018-10-04) + +- Updates homebrew cask tap to homebrew/cask +- Updates URLs to the homebrew cask repository + +## 5.0.7 (2018-09-26) + +- Fix cask resource running each chef-client run + +## 5.0.6 (2018-09-26) + +- Avoid CHEF-25 Deprecation warnings by making the tap/cask resources no-ops on modern chef-client releases + +## 5.0.5 (2018-09-04) + +- Update name of macos in kitchen config +- Add deprecation notice for the homebrew_tap and homebrew_cask resources. These resources are now built into Chef 14 and they will be removed from this cookbook when Chef 13 goes EOL, April 2019. + +## 5.0.4 (2018-03-16) + +- Fix backwards logic in the cask install action + +## 5.0.3 (2018-03-09) + +- Resolve method missing errors in the library + +## 5.0.2 (2018-03-09) + +- Remove some legacy logic around the Chef Homebrew user module +- Use lazy to prevent compilation failures on non-macOS platforms + +## 5.0.1 (2018-03-08) + +- Added a cask_name and tap_name property to the cask/tap resources. These are name_properties which allow you to set the tap/cask name to something other than the resources name. Handy for avoiding resource cloning. + +## 5.0.0 (2018-03-08) + +- Added a new homebrew_path property to cask/tap for the homebrew binary +- Added a new owner property to cash/tap for setting the homebrew owner +- Converted execute resources in the resources to converge_by and shellout to provide better converge messaging in line with other core Chef resources= +- Renamed the :uninstall action in the cask resource to :remove. This aligns with other chef package resources. The previous action will continue to function. +- Fully documented the resource actions and properties in the readme +- Removed deprecated taps out of the test recipe +- Removed the ChefSpec matchers that are now autogenerated by ChefSpec in modern releases of ChefDK. If this causes failures you need to upgrade ChefDK + +## 4.3.0 (2018-01-13) + +- Allow Cask name to be scoped to tap +- Disable Foodcrtiic's FC108 since it doesn't apply here +- Automatically install caskroom/cask in the cask resource. This eliminates the need for the cask recipe. +- Resolve Chef 14 deprecation warnings + +## 4.2.2 (2018-01-13) + +- Fix failures in the cask resource +- Improve inspec output for file mode test + +## 4.2.1 (2018-01-13) + +- Remove double shellout from a bad merge +- Test on modern macOS releases +- Use full file modes throughout the recipes +- Add 2 retries for downloading the homebrew script in case it fails + +## 4.2.0 (2017-05-30) + +- Remove class_eval and require Chef 12.7+ + +## 4.1.0 (2017-04-25) + +- Extend the tap resource to use the --full option. See the readme for details and examples + +## 4.0.0 (2017-04-19) + +- Convert the tap and cask resources from LWRPs to custom resources which simplifies the code and fixes an incompatibility with Chef 13 +- Uses the homebrew_owner as the user to check if a cask has been casked +- Fixed the location of the tap dir to properly prevent trying to install a tap twice +- Refactor the mixin to be a simpler helper that is easier to test +- Resolved failures in the Chefspecs on Travis +- Test with Local Delivery and not Rake +- Use standardize Apache 2 license string +- Only check if homebrew exists once in the default recipe + ## 3.0.0 (2016-12-19) - The homebrew package provider has been removed from this cookbook. It ships with Chef 12.0+. This cookbook now requires a minimum of Chef 12.1 or later. @@ -134,7 +305,7 @@ Bug Fixes: ## v1.7.0 (2014-06-26) -# 38 - Add homebrew::cask recipe +- Add homebrew::cask recipe (#38) ## v1.6.6 (2014-05-29) @@ -169,13 +340,13 @@ Bug Fixes: ### Bug -- **[COOK-3589](https://tickets.chef.io/browse/COOK-3589)** - Add homebrew as the default package manager on OS X Server +- [COOK-3589] - Add homebrew as the default package manager on OS X Server ## v1.4.0 ### Bug -- **[COOK-3283](https://tickets.chef.io/browse/COOK-3283)** - Support running homebrew cookbook as root user, with sudo, or a non-privileged user +- [COOK-3283] - Support running homebrew cookbook as root user, with sudo, or a non-privileged user ## v1.3.2 diff --git a/cookbooks/homebrew/CONTRIBUTING.md b/cookbooks/homebrew/CONTRIBUTING.md deleted file mode 100644 index ef2f2b8..0000000 --- a/cookbooks/homebrew/CONTRIBUTING.md +++ /dev/null @@ -1,2 +0,0 @@ -Please refer to -https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD diff --git a/cookbooks/yum/LICENSE b/cookbooks/homebrew/LICENSE similarity index 100% rename from cookbooks/yum/LICENSE rename to cookbooks/homebrew/LICENSE diff --git a/cookbooks/homebrew/MAINTAINERS.md b/cookbooks/homebrew/MAINTAINERS.md deleted file mode 100644 index 645ed14..0000000 --- a/cookbooks/homebrew/MAINTAINERS.md +++ /dev/null @@ -1,15 +0,0 @@ - - -# 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 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) - -# Maintainers -* [Jennifer Davis](https://github.com/sigje) -* [Tim Smith](https://github.com/tas50) -* [Thom May](https://github.com/thommay) diff --git a/cookbooks/homebrew/README.md b/cookbooks/homebrew/README.md index b87382a..fe82ad7 100644 --- a/cookbooks/homebrew/README.md +++ b/cookbooks/homebrew/README.md @@ -1,9 +1,19 @@ # Homebrew Cookbook -[![Build Status](https://travis-ci.org/chef-cookbooks/homebrew.svg?branch=master)](http://travis-ci.org/chef-cookbooks/homebrew) [![Cookbook Version](https://img.shields.io/cookbook/v/homebrew.svg)](https://supermarket.chef.io/cookbooks/homebrew) +[![Cookbook Version](https://img.shields.io/cookbook/v/homebrew.svg)](https://supermarket.chef.io/cookbooks/homebrew) +[![CI State](https://github.com/sous-chefs/homebrew/workflows/ci/badge.svg)](https://github.com/sous-chefs/homebrew/actions?query=workflow%3Aci) +[![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers) +[![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) +[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) This cookbook installs [Homebrew](http://brew.sh/) and provides resources for working with taps and casks +Note: The `homebrew_tap` and `homebrew_cask` resources shipped in Chef 14.0. When Chef 15.0 is released in April 2019 these resources will be removed from this cookbook as all users should be on 14.0 or later. + +## Maintainers + +This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit [sous-chefs.org](https://sous-chefs.org/) or come chat with us on the Chef Community Slack in [#sous-chefs](https://chefcommunity.slack.com/messages/C2V7B88SF). + ## Requirements ### Platforms @@ -12,59 +22,52 @@ This cookbook installs [Homebrew](http://brew.sh/) and provides resources for wo ### Chef -- Chef 12.1+ +- Chef 12.7+ ### Cookbooks - none -## Attributes - -- `node['homebrew']['owner']` - The user that will own the Homebrew installation and packages. Setting this will override the default behavior which is to use the non-privileged user that has invoked the Chef run (or the `SUDO_USER` if invoked with sudo). The default is `nil`. -- `node['homebrew']['auto-update']` - Whether the default recipe should automatically update Homebrew each run or not. The default is `true` to maintain compatibility. Set to false or nil to disable. Note that disabling this feature may cause formula to not work. -- `node['homebrew']['formulas']` - An Array of formula that should be installed using Homebrew by default, used only in the `homebrew::install_formulas` recipe. - - - To install the most recent version, include just the recipe name: `- simple_formula` - - To install a specific version, specify both its name and version: - - ``` - - name: special-version-formula - version: 1.2.3 - ``` - - - To install the HEAD of a formula, specify both its name and `head: true`: - - ``` - - name: head-tracking-formula - head: true - ``` - - - To provide other options, specify both its name and options - - ``` - - name: formula-with-options - options: --with-option-1 --with-other-option - ``` - -- `node['homebrew']['casks']` - An Array of casks that should be installed using brew cask by default, used only in the `homebrew::install_casks` recipe. - -- `node['homebrew']['taps']` - An Array of taps that should be installed using brew tap by default, used only in the `homebrew::install_taps` recipe. - -## Resources (provider) +## Resources ### homebrew_tap -LWRP for `brew tap`, a Homebrew command used to add additional formula repositories. From the `brew` man page: +Resource for `brew tap`, a Homebrew command used to add additional formula repositories. From the `brew` man page: ```text -tap [tap] - Tap a new formula repository from GitHub, or list existing taps. +brew tap [--full] user/repo [URL] + Tap a formula repository. - tap is of the form user/repo, e.g. brew tap homebrew/dupes. + With URL unspecified, taps a formula repository from GitHub using HTTPS. + Since so many taps are hosted on GitHub, this command is a shortcut for + tap user/repo https://github.com/user/homebrew-repo. + + With URL specified, taps a formula repository from anywhere, using + any transport protocol that git handles. The one-argument form of tap + simplifies but also limits. This two-argument command makes no + assumptions, so taps can be cloned from places other than GitHub and + using protocols other than HTTPS, e.g., SSH, GIT, HTTP, FTP(S), RSYNC. + + By default, the repository is cloned as a shallow copy (--depth=1), but + if --full is passed, a full clone will be used. To convert a shallow copy + to a full copy, you can retap passing --full without first untapping. ``` Default action is `:tap` which enables the repository. Use `:untap` to disable a tapped repository. +#### Actions + +- `:tap` (default) - Add a tap +- `:untap` - Remove a tap + +#### Properties + +- `:tap_name` - Optional name property to override the resource name value +- `:url` - Optional URL to the tap +- `:full` - Perform a full clone rather than a shallow clone on the tap (default: false) +- `:homebrew_path` - the path to the homebrew binary (default: '/opt/homebrew/bin/brew') +- `:owner` - the owner of the homebrew installation (default: calculated based on existing files) + #### Examples ```ruby @@ -73,75 +76,114 @@ homebrew_tap 'homebrew/dupes' homebrew_tap 'homebrew/dupes' do action :untap end + +homebrew_tap "Let's install homebrew/dupes" do + tap_name 'homebrew/dupes' + url 'https://github.com/homebrew/homebrew-dupes.git' + full true +end ``` ### homebrew_cask -LWRP for `brew cask`, a Homebrew-style CLI workflow for the administration of Mac applications distributed as binaries. It's implemented as a homebrew "external command" called cask. +Resource for `brew cask`, a Homebrew-style CLI workflow for the administration of Mac applications distributed as binaries. It's implemented as a homebrew "external command" called cask. -[homebrew-cask on GitHub](https://github.com/caskroom/homebrew-cask) +[homebrew-cask on GitHub](https://github.com/Homebrew/homebrew-cask) -#### Prerequisites +#### Actions -You must have the homebrew-cask repository tapped. +- `:install` (default) - install an Application +- `:remove` - remove an Application. + +#### Properties + +- `:cask_name` - Optional name property to override the resource name value +- `:options` - options to pass to the brew CLI during installation +- `:install_cask` - auto install cask tap if necessary (default: true) +- `:homebrew_path` - the path to the homebrew binary (default: '/opt/homebrew/bin/brew') +- `:owner` - the owner of the homebrew installation (default: calculated based on existing files) + +#### Examples ```ruby -homebrew_tap 'caskroom/cask' -``` +homebrew_cask 'google-chrome' -And then install the homebrew cask package before using this LWRP. - -```ruby -package "brew-cask" do - action :install - end -``` - -You can include the `homebrew::cask` recipe to do this. - -### Examples - -```ruby -homebrew_cask "google-chrome" - -homebrew_cask "google-chrome" do - action :uncask +homebrew_cask "Let's remove google-chrome" do + cask_name 'google-chrome' + install_cask false + action :remove end ``` -Default action is `:cask` which installs the Application binary . Use `:uncask` to uninstall a an Application. +[View the list of available Casks](https://github.com/Homebrew/homebrew-cask/tree/master/Casks) -[View the list of available Casks](https://github.com/caskroom/homebrew-cask/tree/master/Casks) +## Attributes -# Usage +- `node['homebrew']['owner']` - The user that will own the Homebrew installation and packages. Setting this will override the default behavior which is to use the non-privileged user that has invoked the Chef run (or the `SUDO_USER` if invoked with sudo). The default is `nil`. +- `node['homebrew']['auto-update']` - Whether the default recipe should automatically update Homebrew each run or not. The default is `true` to maintain compatibility. Set to false or nil to disable. Note that disabling this feature may cause formula to not work. +- `node['homebrew']['formulas']` - An Array of formula that should be installed using Homebrew by default, used only in the `homebrew::install_formulas` recipe. -We strongly recommend that you put "recipe[homebrew]" in your node's run list, to ensure that it is available on the system and that Homebrew itself gets installed. Putting an explicit dependency in the metadata will cause the cookbook to be downloaded and the library loaded, thus resulting in changing the package provider on Mac OS X, so if you have systems you want to use the default (Mac Ports), they would be changed to Homebrew. + - To install the most recent version, include just the recipe name: `- simple_formula` + - To install a specific version, specify both its name and version: -The default recipe also ensures that Homebrew is installed and up to date if the auto update attribute (above) is true (default). + ```yaml + - name: special-version-formula + version: 1.2.3 + ``` -## License and Authors + - To install the HEAD of a formula, specify both its name and `head: true`: -This cookbook is maintained by CHEF. The original author, maintainer and copyright holder is Graeme Mathieson. The cookbook remains licensed under the Apache License version 2. + ```yaml + - name: head-tracking-formula + head: true + ``` -[Original blog post by Graeme](https://woss.name/articles/converging-your-home-directory-with-chef/) + - To provide other options, specify both its name and options -Author:: Graeme Mathieson ([mathie@woss.name](mailto:mathie@woss.name)) + ```yaml + - name: formula-with-options + options: --with-option-1 --with-other-option + ``` -Author:: Joshua Timberman ([joshua@chef.io](mailto:joshua@chef.io)) +- `node['homebrew']['casks']` - An Array of casks that should be installed using brew cask by default, used only in the `homebrew::install_casks` recipe. -```text -Copyright:: 2011, Graeme Mathieson -Copyright:: 2012-2016, Chef Software, Inc. +- `node['homebrew']['taps']` - An Array of taps that should be installed using brew tap by default, used only in the `homebrew::install_taps` recipe. For example: -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 + ```ruby + [ + 'homebrew/science', + # 'tap' is the only required key for the Hash + { 'tap' => 'homebrew/dupes', 'url' => 'https://github.com', 'full' => true } + ] + ``` - http://www.apache.org/licenses/LICENSE-2.0 +## Usage -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. -``` +We strongly recommend that you put "recipe[homebrew]" in your node's run list, to ensure that it is available on the system and that Homebrew itself gets installed. Putting an explicit dependency in the metadata will cause the cookbook to be downloaded and the library loaded, thus resulting in changing the package provider on macOS, so if you have systems you want to use the default (Mac Ports), they would be changed to Homebrew. + +The default recipe also ensures that Homebrew is installed and up to date if the auto-update attribute (above) is true (default). + +## Contributors + +This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) + +### Backers + +Thank you to all our backers! + +![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40) + +### Sponsors + +Support this project by becoming a sponsor. Your logo will show up here with a link to your website. + +![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100) diff --git a/cookbooks/homebrew/attributes/default.rb b/cookbooks/homebrew/attributes/default.rb index 67245a6..e60aca7 100644 --- a/cookbooks/homebrew/attributes/default.rb +++ b/cookbooks/homebrew/attributes/default.rb @@ -4,7 +4,7 @@ # Cookbook:: homebrew # Attributes:: default # -# Copyright:: 2011-2016, Chef Software, Inc. +# Copyright:: 2011-2019, 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. @@ -24,6 +24,6 @@ default['homebrew']['auto-update'] = true default['homebrew']['casks'] = [] default['homebrew']['formulas'] = node['homebrew']['formula'] || [] default['homebrew']['taps'] = [] -default['homebrew']['installer']['url'] = 'https://raw.githubusercontent.com/Homebrew/install/master/install' +default['homebrew']['installer']['url'] = 'https://raw.githubusercontent.com/Homebrew/install/master/install.sh' default['homebrew']['installer']['checksum'] = nil default['homebrew']['enable-analytics'] = true diff --git a/cookbooks/yum/chefignore b/cookbooks/homebrew/chefignore similarity index 98% rename from cookbooks/yum/chefignore rename to cookbooks/homebrew/chefignore index cc170ea..a27b0b2 100644 --- a/cookbooks/yum/chefignore +++ b/cookbooks/homebrew/chefignore @@ -61,7 +61,7 @@ Dangerfile examples/* features/* Guardfile -kitchen.yml* +kitchen*.yml mlc_config.json Procfile Rakefile diff --git a/cookbooks/homebrew/libraries/helpers.rb b/cookbooks/homebrew/libraries/helpers.rb new file mode 100644 index 0000000..1699163 --- /dev/null +++ b/cookbooks/homebrew/libraries/helpers.rb @@ -0,0 +1,99 @@ +# +# Author:: Joshua Timberman () +# Author:: Graeme Mathieson () +# Cookbook:: homebrew +# Library:: helpers +# +# Copyright:: 2011-2019, 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. +# + +class HomebrewUserWrapper + require 'chef/mixin/homebrew_user' + include Chef::Mixin::HomebrewUser +end + +module Homebrew + extend self + + require 'mixlib/shellout' + include Chef::Mixin::ShellOut + + def self.included(base) + base.extend(Homebrew) + end + + def install_path + arm64_test = shell_out('sysctl -n hw.optional.arm64') + if arm64_test.stdout.chomp == '1' + '/opt/homebrew' + else + '/usr/local' + end + end + + def repository_path + arm64_test = shell_out('sysctl -n hw.optional.arm64') + if arm64_test.stdout.chomp == '1' + '/opt/homebrew' + else + '/usr/local/Homebrew' + end + end + + def exist? + Chef::Log.debug('Checking to see if the homebrew binary exists') + ::File.exist?("#{HomebrewWrapper.new.install_path}/bin/brew") + end + + def owner + @owner ||= begin + # once we only support 14.0 we can switch this to find_homebrew_username + require 'etc' + ::Etc.getpwuid(HomebrewUserWrapper.new.find_homebrew_uid).name + rescue Chef::Exceptions::CannotDetermineHomebrewOwner + calculate_owner + end.tap do |owner| + Chef::Log.debug("Homebrew owner is #{owner}") + end + end + + private + + def calculate_owner + owner = homebrew_owner_attr || sudo_user || current_user + if owner == 'root' + raise Chef::Exceptions::User, + "Homebrew owner is 'root' which is not supported. " \ + "To set an explicit owner, please set node['homebrew']['owner']." + end + owner + end + + def homebrew_owner_attr + Chef.node['homebrew']['owner'] + end + + def sudo_user + ENV['SUDO_USER'] + end + + def current_user + ENV['USER'] + end +end unless defined?(Homebrew) + +class HomebrewWrapper + include Homebrew +end diff --git a/cookbooks/homebrew/libraries/homebrew_mixin.rb b/cookbooks/homebrew/libraries/homebrew_mixin.rb deleted file mode 100644 index e292214..0000000 --- a/cookbooks/homebrew/libraries/homebrew_mixin.rb +++ /dev/null @@ -1,63 +0,0 @@ -# -# Author:: Joshua Timberman () -# Author:: Graeme Mathieson () -# Cookbook:: homebrew -# Libraries:: homebrew_mixin -# -# Copyright:: 2011-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. -# - -class Chef12HomebrewUser - include Chef::Mixin::HomebrewUser -end - -module Homebrew - # Homebrew - module Mixin - def homebrew_owner - require 'etc' - @homebrew_owner ||= ::Etc.getpwuid(Chef12HomebrewUser.new.find_homebrew_uid).name - rescue Chef::Exceptions::CannotDetermineHomebrewOwner - @homebrew_owner ||= calculate_owner - end - - private - - def calculate_owner - owner = homebrew_owner_attr || sudo_user || current_user - if owner == 'root' - raise Chef::Exceptions::User, - "Homebrew owner is 'root' which is not supported. " \ - "To set an explicit owner, please set node['homebrew']['owner']." - end - owner - end - - def homebrew_owner_attr - node['homebrew']['owner'] - end - - def sudo_user - ENV['SUDO_USER'] - end - - def current_user - ENV['USER'] - end - end -end - -Chef::Resource.send(:include, Homebrew::Mixin) -Chef::Recipe.send(:include, Homebrew::Mixin) diff --git a/cookbooks/homebrew/libraries/matchers.rb b/cookbooks/homebrew/libraries/matchers.rb deleted file mode 100644 index 67d1d88..0000000 --- a/cookbooks/homebrew/libraries/matchers.rb +++ /dev/null @@ -1,28 +0,0 @@ -if defined?(ChefSpec) - ChefSpec.define_matcher :homebrew_package - - def tap_homebrew_tap(tap) - ChefSpec::Matchers::ResourceMatcher.new(:homebrew_tap, :tap, tap) - end - - def untap_homebrew_tap(tap) - ChefSpec::Matchers::ResourceMatcher.new(:homebrew_tap, :untap, tap) - end - - def cask_homebrew_cask(cask) - ChefSpec::Matchers::ResourceMatcher.new(:homebrew_cask, :cask, cask) - end - - def uncask_homebrew_cask(cask) - ChefSpec::Matchers::ResourceMatcher.new(:homebrew_cask, :uncask, cask) - end - - def install_homebrew_cask(cask) - ChefSpec::Matchers::ResourceMatcher.new(:homebrew_cask, :install, cask) - end - - def uninstall_homebrew_cask(cask) - ChefSpec::Matchers::ResourceMatcher.new(:homebrew_cask, :uninstall, cask) - end - -end diff --git a/cookbooks/homebrew/metadata.json b/cookbooks/homebrew/metadata.json index e69fd81..8ea519a 100644 --- a/cookbooks/homebrew/metadata.json +++ b/cookbooks/homebrew/metadata.json @@ -1 +1,36 @@ -{"name":"homebrew","version":"3.0.0","description":"Install Homebrew and includes resources for working with taps and casks","long_description":"# Homebrew Cookbook\n\n[![Build Status](https://travis-ci.org/chef-cookbooks/homebrew.svg?branch=master)](http://travis-ci.org/chef-cookbooks/homebrew) [![Cookbook Version](https://img.shields.io/cookbook/v/homebrew.svg)](https://supermarket.chef.io/cookbooks/homebrew)\n\nThis cookbook installs [Homebrew](http://brew.sh/) and provides resources for working with taps and casks\n\n## Requirements\n\n### Platforms\n\n- macOS\n\n### Chef\n\n- Chef 12.1+\n\n### Cookbooks\n\n- none\n\n## Attributes\n\n- `node['homebrew']['owner']` - The user that will own the Homebrew installation and packages. Setting this will override the default behavior which is to use the non-privileged user that has invoked the Chef run (or the `SUDO_USER` if invoked with sudo). The default is `nil`.\n- `node['homebrew']['auto-update']` - Whether the default recipe should automatically update Homebrew each run or not. The default is `true` to maintain compatibility. Set to false or nil to disable. Note that disabling this feature may cause formula to not work.\n- `node['homebrew']['formulas']` - An Array of formula that should be installed using Homebrew by default, used only in the `homebrew::install_formulas` recipe.\n\n - To install the most recent version, include just the recipe name: `- simple_formula`\n - To install a specific version, specify both its name and version:\n\n ```\n - name: special-version-formula\n version: 1.2.3\n ```\n\n - To install the HEAD of a formula, specify both its name and `head: true`:\n\n ```\n - name: head-tracking-formula\n head: true\n ```\n\n - To provide other options, specify both its name and options\n\n ```\n - name: formula-with-options\n options: --with-option-1 --with-other-option\n ```\n\n- `node['homebrew']['casks']` - An Array of casks that should be installed using brew cask by default, used only in the `homebrew::install_casks` recipe.\n\n- `node['homebrew']['taps']` - An Array of taps that should be installed using brew tap by default, used only in the `homebrew::install_taps` recipe.\n\n## Resources (provider)\n\n### homebrew_tap\n\nLWRP for `brew tap`, a Homebrew command used to add additional formula repositories. From the `brew` man page:\n\n```text\ntap [tap]\n Tap a new formula repository from GitHub, or list existing taps.\n\n tap is of the form user/repo, e.g. brew tap homebrew/dupes.\n```\n\nDefault action is `:tap` which enables the repository. Use `:untap` to disable a tapped repository.\n\n#### Examples\n\n```ruby\nhomebrew_tap 'homebrew/dupes'\n\nhomebrew_tap 'homebrew/dupes' do\n action :untap\nend\n```\n\n### homebrew_cask\n\nLWRP for `brew cask`, a Homebrew-style CLI workflow for the administration of Mac applications distributed as binaries. It's implemented as a homebrew \"external command\" called cask.\n\n[homebrew-cask on GitHub](https://github.com/caskroom/homebrew-cask)\n\n#### Prerequisites\n\nYou must have the homebrew-cask repository tapped.\n\n```ruby\nhomebrew_tap 'caskroom/cask'\n```\n\nAnd then install the homebrew cask package before using this LWRP.\n\n```ruby\npackage \"brew-cask\" do\n action :install\n end\n```\n\nYou can include the `homebrew::cask` recipe to do this.\n\n### Examples\n\n```ruby\nhomebrew_cask \"google-chrome\"\n\nhomebrew_cask \"google-chrome\" do\n action :uncask\nend\n```\n\nDefault action is `:cask` which installs the Application binary . Use `:uncask` to uninstall a an Application.\n\n[View the list of available Casks](https://github.com/caskroom/homebrew-cask/tree/master/Casks)\n\n# Usage\n\nWe strongly recommend that you put \"recipe[homebrew]\" in your node's run list, to ensure that it is available on the system and that Homebrew itself gets installed. Putting an explicit dependency in the metadata will cause the cookbook to be downloaded and the library loaded, thus resulting in changing the package provider on Mac OS X, so if you have systems you want to use the default (Mac Ports), they would be changed to Homebrew.\n\nThe default recipe also ensures that Homebrew is installed and up to date if the auto update attribute (above) is true (default).\n\n## License and Authors\n\nThis cookbook is maintained by CHEF. The original author, maintainer and copyright holder is Graeme Mathieson. The cookbook remains licensed under the Apache License version 2.\n\n[Original blog post by Graeme](https://woss.name/articles/converging-your-home-directory-with-chef/)\n\nAuthor:: Graeme Mathieson ([mathie@woss.name](mailto:mathie@woss.name))\n\nAuthor:: Joshua Timberman ([joshua@chef.io](mailto:joshua@chef.io))\n\n```text\nCopyright:: 2011, Graeme Mathieson\nCopyright:: 2012-2016, Chef Software, Inc. \n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"mac_os_x":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{"homebrew":"Install Homebrew"}} \ No newline at end of file +{ + "name": "homebrew", + "description": "Install Homebrew and includes resources for working with taps and casks", + "long_description": "", + "maintainer": "Sous Chefs", + "maintainer_email": "help@sous-chefs.org", + "license": "Apache-2.0", + "platforms": { + "mac_os_x": ">= 0.0.0" + }, + "dependencies": { + + }, + "providing": { + + }, + "recipes": { + + }, + "version": "5.4.1", + "source_url": "https://github.com/sous-chefs/homebrew", + "issues_url": "https://github.com/sous-chefs/homebrew/issues", + "privacy": false, + "chef_versions": [ + [ + ">= 15.3" + ] + ], + "ohai_versions": [ + + ], + "gems": [ + + ], + "eager_load_libraries": true +} diff --git a/cookbooks/homebrew/metadata.rb b/cookbooks/homebrew/metadata.rb new file mode 100644 index 0000000..9af47f4 --- /dev/null +++ b/cookbooks/homebrew/metadata.rb @@ -0,0 +1,11 @@ +name 'homebrew' +maintainer 'Sous Chefs' +maintainer_email 'help@sous-chefs.org' +license 'Apache-2.0' +description 'Install Homebrew and includes resources for working with taps and casks' +version '5.4.1' +supports 'mac_os_x' + +source_url 'https://github.com/sous-chefs/homebrew' +issues_url 'https://github.com/sous-chefs/homebrew/issues' +chef_version '>= 15.3' diff --git a/cookbooks/homebrew/providers/cask.rb b/cookbooks/homebrew/providers/cask.rb deleted file mode 100644 index dc7126a..0000000 --- a/cookbooks/homebrew/providers/cask.rb +++ /dev/null @@ -1,47 +0,0 @@ -# -# Cookbook:: homebrew -# Providers:: cask -# -# Copyright:: 2011-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. -# - -include ::Homebrew::Mixin - -use_inline_resources - -def whyrun_supported? - true -end - -action :install do - execute "installing cask #{new_resource.name}" do - command "/usr/local/bin/brew cask install #{new_resource.name} #{new_resource.options}" - user homebrew_owner - environment lazy { { 'HOME' => ::Dir.home(homebrew_owner), 'USER' => homebrew_owner } } - not_if { new_resource.casked? } - end -end - -action :uninstall do - execute "uninstalling cask #{new_resource.name}" do - command "/usr/local/bin/brew cask uninstall #{new_resource.name}" - user homebrew_owner - environment lazy { { 'HOME' => ::Dir.home(homebrew_owner), 'USER' => homebrew_owner } } - only_if { new_resource.casked? } - end -end - -alias_method :action_cask, :action_install -alias_method :action_uncask, :action_uninstall diff --git a/cookbooks/homebrew/providers/tap.rb b/cookbooks/homebrew/providers/tap.rb deleted file mode 100644 index fd04df8..0000000 --- a/cookbooks/homebrew/providers/tap.rb +++ /dev/null @@ -1,58 +0,0 @@ -# -# Author:: Joshua Timberman () -# Author:: Graeme Mathieson () -# Cookbook:: homebrew -# Providers:: tap -# -# Copyright:: 2011-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. -# - -include ::Homebrew::Mixin - -use_inline_resources - -def load_current_resource - @tap = Chef::Resource::HomebrewTap.new(new_resource.name) - tap_dir = @tap.name.gsub('/', '/homebrew-') - - Chef::Log.debug("Checking whether we've already tapped #{new_resource.name}") - if ::File.directory?("/usr/local/Library/Taps/#{tap_dir}") - @tap.tapped true - else - @tap.tapped false - end -end - -action :tap do - unless @tap.tapped - execute "tapping #{new_resource.name}" do - command "/usr/local/bin/brew tap #{new_resource.name}" - environment lazy { { 'HOME' => ::Dir.home(homebrew_owner), 'USER' => homebrew_owner } } - not_if "/usr/local/bin/brew tap | grep #{new_resource.name}" - user homebrew_owner - end - end -end - -action :untap do - if @tap.tapped - execute "untapping #{new_resource.name}" do - command "/usr/local/bin/brew untap #{new_resource.name}" - environment lazy { { 'HOME' => ::Dir.home(homebrew_owner), 'USER' => homebrew_owner } } - only_if "/usr/local/bin/brew tap | grep #{new_resource.name}" - user homebrew_owner - end - end -end diff --git a/cookbooks/homebrew/recipes/cask.rb b/cookbooks/homebrew/recipes/cask.rb index 38148e6..9f61a08 100644 --- a/cookbooks/homebrew/recipes/cask.rb +++ b/cookbooks/homebrew/recipes/cask.rb @@ -2,7 +2,7 @@ # Cookbook:: homebrew # Recipes:: cask # -# Copyright:: 2014-2016, Chef Software, Inc +# Copyright:: 2014-2019, 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. @@ -17,10 +17,10 @@ # limitations under the License. # -homebrew_tap 'caskroom/cask' +homebrew_tap 'homebrew/cask' directory '/Library/Caches/Homebrew/Casks' do - owner homebrew_owner - mode '775' + owner Homebrew.owner + mode '0775' only_if { ::Dir.exist?('/Library/Caches/Homebrew') } end diff --git a/cookbooks/homebrew/recipes/default.rb b/cookbooks/homebrew/recipes/default.rb index feab10e..39c0aab 100644 --- a/cookbooks/homebrew/recipes/default.rb +++ b/cookbooks/homebrew/recipes/default.rb @@ -4,7 +4,7 @@ # Cookbook:: homebrew # Recipe:: default # -# Copyright:: 2011-2016, Chef Software, Inc. +# Copyright:: 2011-2019, 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. @@ -19,29 +19,50 @@ # limitations under the License. # -homebrew_go = "#{Chef::Config[:file_cache_path]}/homebrew_go" +unless Homebrew.exist? + homebrew_go = "#{Chef::Config[:file_cache_path]}/homebrew_go" -Chef::Log.debug("Homebrew owner is '#{homebrew_owner}'") + # Grant Homebrew install script permission to execute + # without passing a sudo password. Deletes itself at + # the end of a successful run. + sudo 'nopasswd_homebrew_installer' do + user Homebrew.owner + commands [ + homebrew_go, + '/bin/chmod', + '/bin/mkdir', + '/bin/rm', + '/usr/bin/chgrp', + '/usr/bin/install', + '/usr/bin/touch', + '/usr/bin/xcode-select', + '/usr/sbin/chown', + '/usr/sbin/softwareupdate', + ] + nopasswd true + action :create + notifies :delete, 'sudo[nopasswd_homebrew_installer]', :delayed + end -remote_file homebrew_go do - source node['homebrew']['installer']['url'] - checksum node['homebrew']['installer']['checksum'] unless node['homebrew']['installer']['checksum'].nil? - mode '755' - not_if { ::File.exist? '/usr/local/bin/brew' } -end + remote_file homebrew_go do + source node['homebrew']['installer']['url'] + checksum node['homebrew']['installer']['checksum'] unless node['homebrew']['installer']['checksum'].nil? + mode '0755' + retries 2 + end -execute 'install homebrew' do - command homebrew_go - environment lazy { { 'HOME' => ::Dir.home(homebrew_owner), 'USER' => homebrew_owner } } - user homebrew_owner - not_if { ::File.exist? '/usr/local/bin/brew' } + execute 'install homebrew' do + command homebrew_go + environment lazy { { 'HOME' => ::Dir.home(Homebrew.owner), 'USER' => Homebrew.owner, 'NONINTERACTIVE' => '1' } } + user Homebrew.owner + end end execute 'set analytics' do - environment lazy { { 'HOME' => ::Dir.home(homebrew_owner), 'USER' => homebrew_owner } } - user homebrew_owner - command "/usr/local/bin/brew analytics #{node['homebrew']['enable-analytics'] ? 'on' : 'off'}" - only_if { shell_out('/usr/local/bin/brew analytics state', user: homebrew_owner).stdout.include?('enabled') != node['homebrew']['enable-analytics'] } + environment lazy { { 'HOME' => ::Dir.home(Homebrew.owner), 'USER' => Homebrew.owner } } + user Homebrew.owner + command lazy { "#{HomebrewWrapper.new.install_path}/bin/brew analytics #{node['homebrew']['enable-analytics'] ? 'on' : 'off'}" } + only_if { shell_out("#{HomebrewWrapper.new.install_path}/bin/brew analytics state", user: Homebrew.owner).stdout.include?('enabled') != node['homebrew']['enable-analytics'] } end if node['homebrew']['auto-update'] @@ -50,8 +71,8 @@ if node['homebrew']['auto-update'] end execute 'update homebrew from github' do - environment lazy { { 'HOME' => ::Dir.home(homebrew_owner), 'USER' => homebrew_owner } } - user homebrew_owner - command '/usr/local/bin/brew update || true' + environment lazy { { 'HOME' => ::Dir.home(Homebrew.owner), 'USER' => Homebrew.owner } } + user Homebrew.owner + command lazy { "#{HomebrewWrapper.new.install_path}/bin/brew update || true" } end end diff --git a/cookbooks/homebrew/recipes/install_casks.rb b/cookbooks/homebrew/recipes/install_casks.rb index 3635e17..f66941c 100644 --- a/cookbooks/homebrew/recipes/install_casks.rb +++ b/cookbooks/homebrew/recipes/install_casks.rb @@ -2,7 +2,7 @@ # Cookbook:: homebrew # Recipe:: install_casks # -# Copyright:: 2014-2016, Chef Software, Inc +# Copyright:: 2014-2019, 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. @@ -17,8 +17,6 @@ # limitations under the License. # -include_recipe 'homebrew::cask' - node['homebrew']['casks'].each do |cask| homebrew_cask cask end diff --git a/cookbooks/homebrew/recipes/install_formulas.rb b/cookbooks/homebrew/recipes/install_formulas.rb index ca13679..4e7db79 100644 --- a/cookbooks/homebrew/recipes/install_formulas.rb +++ b/cookbooks/homebrew/recipes/install_formulas.rb @@ -2,7 +2,7 @@ # Cookbook:: homebrew # Recipes:: install_casks # -# Copyright:: 2014-2016, Chef Software, Inc +# Copyright:: 2014-2019, 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. diff --git a/cookbooks/homebrew/recipes/install_taps.rb b/cookbooks/homebrew/recipes/install_taps.rb index 950165c..7cb4d0d 100644 --- a/cookbooks/homebrew/recipes/install_taps.rb +++ b/cookbooks/homebrew/recipes/install_taps.rb @@ -2,7 +2,7 @@ # Cookbook:: homebrew # Recipes:: install_taps # -# Copyright:: 2015-2016, Chef Software, Inc +# Copyright:: 2015-2019, 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. @@ -20,5 +20,14 @@ include_recipe 'homebrew' node['homebrew']['taps'].each do |tap| - homebrew_tap tap + if tap.is_a?(String) + homebrew_tap tap + elsif tap.is_a?(Hash) + raise unless tap.key?('tap') + homebrew_tap tap['tap'] do + url tap['url'] if tap.key?('url') + end + else + raise + end end diff --git a/cookbooks/homebrew/renovate.json b/cookbooks/homebrew/renovate.json new file mode 100644 index 0000000..7e7a8ba --- /dev/null +++ b/cookbooks/homebrew/renovate.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["config:base"], + "packageRules": [{ + "groupName": "Actions", + "matchUpdateTypes": ["patch", "pin", "digest"], + "automerge": true, + "addLabels": ["Release: Patch", "Skip: Announcements"] + }, + { + "groupName": "Actions", + "matchUpdateTypes": ["major"], + "automerge": false, + "addLabels": ["Release: Patch", "Skip: Announcements"] + } + ] +} diff --git a/cookbooks/homebrew/resources/cask.rb b/cookbooks/homebrew/resources/cask.rb index 797a0d9..c4d2053 100644 --- a/cookbooks/homebrew/resources/cask.rb +++ b/cookbooks/homebrew/resources/cask.rb @@ -1,14 +1,68 @@ -actions :cask, :uncask, :install, :uninstall -default_action :install +# +# Author:: Joshua Timberman () +# Author:: Graeme Mathieson () +# Cookbook:: homebrew +# Resources:: cask +# +# Copyright:: 2011-2019, 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. +# -attribute :name, - name_attribute: true, - kind_of: String, - regex: /^[\w-]+$/ +chef_version_for_provides '< 14.0' if respond_to?(:chef_version_for_provides) -attribute :options, - kind_of: String +property :cask_name, String, regex: %r{^[\w/-]+$}, name_property: true +property :options, String +property :install_cask, [true, false], default: true +property :homebrew_path, String, default: lazy { "#{HomebrewWrapper.new.install_path}/bin/brew" } +property :owner, String, default: lazy { Homebrew.owner } # lazy to prevent breaking compilation on non-macOS platforms -def casked? - shell_out('/usr/local/bin/brew cask list 2>/dev/null').stdout.split.include?(name) +action :install do + homebrew_tap 'homebrew/cask' if new_resource.install_cask + + unless casked? + converge_by("install cask #{new_resource.name} #{new_resource.options}") do + shell_out!("#{new_resource.homebrew_path} install --cask #{new_resource.name} #{new_resource.options}", + user: new_resource.owner, + env: { 'HOME' => ::Dir.home(new_resource.owner), 'USER' => new_resource.owner }, + cwd: ::Dir.home(new_resource.owner)) + end + end +end + +action :remove do + homebrew_tap 'homebrew/cask' if new_resource.install_cask + + if casked? + converge_by("uninstall cask #{new_resource.name}") do + shell_out!("#{new_resource.homebrew_path} uninstall --cask #{new_resource.name}", + user: new_resource.owner, + env: { 'HOME' => ::Dir.home(new_resource.owner), 'USER' => new_resource.owner }, + cwd: ::Dir.home(new_resource.owner)) + end + end +end + +action_class do + alias_method :action_cask, :action_install + alias_method :action_uncask, :action_remove + alias_method :action_uninstall, :action_remove + + def casked? + unscoped_name = new_resource.name.split('/').last + shell_out!("#{new_resource.homebrew_path} list --cask 2>/dev/null", + user: new_resource.owner, + env: { 'HOME' => ::Dir.home(new_resource.owner), 'USER' => new_resource.owner }, + cwd: ::Dir.home(new_resource.owner)).stdout.split.include?(unscoped_name) + end end diff --git a/cookbooks/homebrew/resources/tap.rb b/cookbooks/homebrew/resources/tap.rb index f7a8c99..8f67124 100644 --- a/cookbooks/homebrew/resources/tap.rb +++ b/cookbooks/homebrew/resources/tap.rb @@ -4,7 +4,7 @@ # Cookbook:: homebrew # Resources:: tap # -# Copyright:: 2011-2016, Chef Software, Inc. +# Copyright:: 2011-2019, 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. @@ -19,13 +19,37 @@ # limitations under the License. # -actions :tap, :untap -default_action :tap +chef_version_for_provides '< 14.0' if respond_to?(:chef_version_for_provides) -attribute :name, - name_attribute: true, - kind_of: String, - regex: %r{^[\w-]+(?:\/[\w-]+)+$} +property :tap_name, String, name_property: true, regex: %r{^[\w-]+(?:\/[\w-]+)+$} +property :url, String +property :full, [true, false], default: false +property :homebrew_path, String, default: lazy { "#{HomebrewWrapper.new.install_path}/bin/brew" } +property :owner, String, default: lazy { Homebrew.owner } # lazy to prevent breaking compilation on non-macOS platforms -attribute :tapped, - kind_of: [TrueClass, FalseClass] +action :tap do + unless tapped?(new_resource.name) + converge_by("tap #{new_resource.name}") do + shell_out!("#{new_resource.homebrew_path} tap #{new_resource.full ? '--full' : ''} #{new_resource.name} #{new_resource.url || ''}", + user: new_resource.owner, + env: { 'HOME' => ::Dir.home(new_resource.owner), 'USER' => new_resource.owner }, + cwd: ::Dir.home(new_resource.owner)) + end + end +end + +action :untap do + if tapped?(new_resource.name) + converge_by("untap #{new_resource.name}") do + shell_out!("#{new_resource.homebrew_path} untap #{new_resource.name}", + user: new_resource.owner, + env: { 'HOME' => ::Dir.home(new_resource.owner), 'USER' => new_resource.owner }, + cwd: ::Dir.home(new_resource.owner)) + end + end +end + +def tapped?(name) + tap_dir = name.gsub('/', '/homebrew-') + ::File.directory?("#{HomebrewWrapper.new.repository_path}/Library/Taps/#{tap_dir}") +end diff --git a/cookbooks/mariadb/CHANGELOG.md b/cookbooks/mariadb/CHANGELOG.md deleted file mode 100644 index d19b938..0000000 --- a/cookbooks/mariadb/CHANGELOG.md +++ /dev/null @@ -1,132 +0,0 @@ -mariadb CHANGELOG -================= - -This file is used to list changes made in each version of the mariadb cookbook. - -0.3.1 ------ -- [BUG #76] - Service is restarted every run if not localhost -- [BUG #73] - Fix directory permissions regression -- [BUG #69] - Update repository.rb to be able to manage Scientific Linux -- [BUG #57] - Add user and password to correct debian-grants -- [ENH #71] - Add xtrabackup-v2 support for SST Method -- [ENH #62] - Allow Galera cluster nodes to be configured when using Chef Solo -- [ENH #64] - Add a vagrant config to test a galera cluster -- [BUG #66] - mariadb_configuration template uses current cookbook as template source -- [BUG #68] - Correct service name inconsistency on CentOS 7 - -0.3.0 ------- -- [ENH] - Add support for using operating system shipped mariadb packages - -0.2.12 ------- -- [BUG #39] - Push gpg key adds through http/80 - Helps with firewalled installs -- [ENH #46] - Add cookbook attribute on configuration lwrp -- [ENH #47] - Allow to pass true for unary options -- [BUG #48] - Load the needed plugins at startup - -0.2.11 ------- -- [ENH #38] - Add CentOS support -- [ENH #40] - Add sensitive flag to resource that deal with passwords -- [BUG #43] - Fix convert TypeError in the replication provider - -0.2.10 ------- -- [BUG] - Audit Plugin test and installation - Correct bad notifies, and stdout test - -0.2.9 ------ -- [BUG #36] - Audit plugin installation can crash mariadb server - -0.2.8 ------ -- [BUG #30] - When using galera, nodes were not sorted, applying configuration change too often -- [BUG #31] - ChefSpec coverage was not 100% -- [BUG #28] - Remove the only_if to mysql service -- [BUG #29] - Add a switch to not launch audit plugin install, when already installed -- [ENH] - Add a switch to separate server install and audit install when needed -- [ENH] - Add a rule to authorize line length to be 120 characters long - -0.2.7 ------ -- [BUG #24] - Fix convert TypeError in the replication provider -- [BUG #25] - Data are now moved when default datadir is changed -- [ENH #21] - Add audit_plugin management - -0.2.6 ------ -- [BUG #18] - Fix provider mariadb_replication compilation error -- [DOCS] - Complete Changelog, and correct README - -0.2.5 ------ -- [ENH #16] - Add a LWRP to manage replication slave -- [ENH #17] - Be able to not install development files within client recipe -- [ENH #11] - Fix the galera root password preseed -- [BUG #12] - Fix the debian-sys-maint user creation/password change -- [BUG #6] - Can change the apt repository base_url when the default one fail -- [TEST] - Add new tests for the new features (galera,development files install,replication LWRP) -- [DOCS] - Complete Changelog, and add new features explanations into README - -0.2.4 ------ -- [BUG #10] - Correct a FC004 broken rule -- [BUG #9] - Correct foodcritic tests (add --epic-fail any to be sure it fails when a broken rule is detected) - -0.2.3 ------ -- [BUG #4] - Add a real management of mysql root password -- [ENH #5] - Now restart mysql service when port is changed -- [ENH #7] - Remove or add root remote access via attribute -- [DOCS] - Complete documentations -- [TEST] - Add a lot of chefspec and kitchen/serverspec tests - -0.2.2 ------ -- [sinfomicien] - Correct repository install under debian family -- [sinfomicien] - Correct client install to add dev files -- [sinfomicien] - Correct and add multiples tests - -0.2.1 ------ -- [sinfomicien] - Use stove to package (remove PaxHeaders.*) - -0.2.0 ------ -- [sinfomicien] - Add rpm/yum management -- [sinfomicien] - Refactor the whole recipes list and management to ease it -- [sinfomicien] - Correct the Documentation -- [sinfomicien] - Rename the provider (from extraconf to configuration), and add matchers to it -- [sinfomicien] - Add a recipe to manage client only installation -- [sinfomicien] - Refactor all tests to manage new platform (centos/redhat/fedora) - -0.1.8 ------ -- [sinfomicien] - Add ignore-failure to debian grants correct, as it can break on initial setup - -0.1.7 ------ -- [sinfomicien] - Correct a typo (unnecessary call to run_command) - -0.1.6 ------ -- [sinfomicien] - improve Galera configuration management -- [sinfomicien] - Add new rspec tests -- [sinfomicien] - Create Kitchen test suite - -0.1.5 ------ -- [sinfomicien] - improve attributes management - -0.1.4 ------ -- [sinfomicien] - adapt galera55 recipe to use a generic galera recipe -- [sinfomicien] - use a generic galera recipe to create the galera10 recipe -- [sinfomicien] - Improve documentation - - -0.1.0 ------ -- [sinfomicien] - Initial release of mariadb diff --git a/cookbooks/mariadb/README.md b/cookbooks/mariadb/README.md deleted file mode 100644 index 01fdaea..0000000 --- a/cookbooks/mariadb/README.md +++ /dev/null @@ -1,207 +0,0 @@ -MariaDB Cookbook -================ - -[![Build Status](https://travis-ci.org/sinfomicien/mariadb.png)](https://travis-ci.org/sinfomicien/mariadb) - -Description ------------ - -This cookbook contains all the stuffs to install and configure a mariadb server on a dpkg/apt compliant system (typically debian), or a rpm/yum compliant system (typically centos) - - -Requirements ------------- - -#### repository -- `mariadb` - This cookbook need that you have a valid apt repository installed with the mariadb official packages - -#### packages -- `percona-xtrabackup` - if you want to use the xtrabckup SST Auth for galera cluster. -- `socat` - if you want to use the xtrabckup SST Auth for galera cluster. -- `rsync` - if you want to use the rsync SST Auth for galera cluster. -- `debconf-utils` - if you use debian platform family. - -#### operating system -- `debian` - this cookbook is fully tested on debian -- `ubuntu` - not fully tested on ubuntu, but should work -- `centos` - not fully tested on centos, but should work - -Attributes ----------- - -#### mariadb::default - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KeyTypeDescriptionDefault
['mariadb']['install']['version']StringVersion to install (currently 10.0 et 5.5)10.0
['mariadb']['use_default_repository']BooleanWether to install MariaDB default repository or not. If you don't have a local repo containing packages, put it to truefalse
['mariadb']['server_root_password']Stringlocal root password
['mariadb']['forbid_remote_root']BooleanWether to activate root remote accesstrue
['mariadb']['allow_root_pass_change']BooleanWether to allow the recipe to change root password after the first installfalse
['mariadb']['client']['development_files']BooleanWether to install development files in client recipetrue
['mariadb']['apt_repository']['base_url']StringThe http base url to use when installing from default repository'ftp.igh.cnrs.fr/pub/mariadb/repo'
['mariadb']['install']['prefer_os_package']BooleanIndicator for preferring use packages shipped by running osfalse
- -Usage ------ - -To install a default server for mariadb choose the version you want (MariaDB 5.5 or 10, galera or not), then call the recipe accordingly. - -List of availables recipes: - -- mariadb::default (just call server recipe with default options) -- mariadb::server -- mariadb::galera -- mariadb::client - -Please be ware that by default, the root password is empty! If you want have changed it use the `node['mariadb']['server_root_password']` attribute to put a correct value. And by default the remote root access is not activated. Use `node['mariadb']['forbid_remote_root']` attribute to change it. - -Sometimes, the default apt repository used for apt does not work (see issue #6). In this case, you need to choose another mirror which worki (pick it from mariadb website), and put the http base url in the attribute `node['mariadb']['apt_repository']['base_url']`. - -#### mariadb::galera - -When installing the mariadb::galera on debian recipe, You have to take care of one specific attribute: -`node['mariadb']['debian']['password']` which default to 'please-change-me' -As wee need to have the same password for this user on the whole cluster nodes... We will change the default install one by the content of this attribute. - -#### mariadb::client - -By default this recipe install the client, and all needed packages to develop client application. If you do not want to install development files when installing client package, -set the attribute `node['mariadb']['client']['development_files']` to false. - -Providers ----------- - -This recipe define 2 providers: -- `Chef::Provider::Mariadb::Configuration` shortcut resource `mariadb_configuration` -- `Chef::Provider::Mariadb::Replication` shortcut resource `mariadb_replication` - -#### mariadb_configuration - -Mainly use for internal purpose. You can use it to create a new configuration file into configuration dir. You have to define 2 variables `section` and `option`. -Where `section` is the configuration section, and `option` is a hash of key/value. The name of the resource is used as base for the filename. - -Example: -```ruby -mariadb_configuration 'fake' do - section 'mysqld' - option {foo: 'bar'} -end -``` -will become the file fake.cnf in the include dir (depend on your platform), which contain: -``` -[mysqld] -foo=bar -``` - -If the value start with a '#', then it's considered as a comment, and the value is printed as is (without the key) - -Example: -```ruby -mariadb_configuration 'fake' do - section 'mysqld' - option {comment1: '# Here i am', foo: bar} -end -``` -will become the file fake.cnf in the include dir (depend on your platform), which contain: -``` -[mysqld] -# Here i am -foo=bar -``` - -#### mariadb_replication - -This LWRP is used to manage replication setup on a host. To use this LWRP, the node need to have the mysql binary installed (via the mariadb::client or mariadb::server or mariadb::galera recipe). -It have 4 actions: -- add - to add a new replication setup (become a slave) -- stop - to stop the slave replication -- start - to start the slave replication -- remove - to remove the slave replication configuration - -The resource name need to be 'default' if your don't want to use a named connection (multi source replication in MariaDB 10). - -So by default the provider try to use the local instance of mysql, with the current user and no password. If you want to change, you have to define `host`, `port`, `user` or `password` - -```ruby -mariadb_replication 'default' do - user 'root' - password 'fakepass' - host 'fakehost' - action :stop -end -``` -will stop the replication on the host `fakehost` using the user `root` and password `fakepass` to connect to. - -When you add a replication configuration, you have to define at least 4 values `master_host`, `master_user`, `master_password` and `master_use_gtid`. And if you don't want the GTID support, you have to define also `master_log_file` and `master_log_pos` - -Example: -```ruby -mariadb_replication 'usefull_conn_name' do - master_host 'server1' - master_user 'slave_user' - master_password 'slave_password' - master_use_gtid 'current_pos' - action :add -end -``` - -Contributing ------------- - -1. Fork the repository on Github -2. Create a named feature branch (like `add_component_x`) -3. Write your change -4. Write tests for your change (if applicable) -5. Run the tests, ensuring they all pass -6. Submit a Pull Request using Github - -License and Authors -------------------- -Authors: -Nicolas Blanc diff --git a/cookbooks/mariadb/attributes/default.rb b/cookbooks/mariadb/attributes/default.rb deleted file mode 100644 index 7523035..0000000 --- a/cookbooks/mariadb/attributes/default.rb +++ /dev/null @@ -1,164 +0,0 @@ -# platform dependent attributes -case node['platform'] -when 'redhat', 'centos', 'fedora', 'scientific', 'amazon' - default['mariadb']['configuration']['path'] = '/etc' - default['mariadb']['configuration']['includedir'] = '/etc/my.cnf.d' - default['mariadb']['mysqld']['socket'] = '/var/lib/mysql/mysql.sock' - default['mariadb']['client']['socket'] = '/var/lib/mysql/mysql.sock' - default['mariadb']['mysqld_safe']['socket'] = '/var/lib/mysql/mysql.sock' -else - default['mariadb']['configuration']['path'] = '/etc/mysql' - default['mariadb']['configuration']['includedir'] = '/etc/mysql/conf.d' - default['mariadb']['mysqld']['socket'] = '/var/run/mysqld/mysqld.sock' - default['mariadb']['mysqld']['pid_file'] = '/var/run/mysqld/mysqld.pid' - default['mariadb']['client']['socket'] = '/var/run/mysqld/mysqld.sock' - default['mariadb']['mysqld_safe']['socket'] = '/var/run/mysqld/mysqld.sock' -end - -# -# mysqld default configuration -# -default['mariadb']['forbid_remote_root'] = true -default['mariadb']['server_root_password'] = '' -default['mariadb']['allow_root_pass_change'] = false -if node['platform'] == 'centos' - default['mariadb']['mysqld']['service_name'] = 'mariadb' -else - default['mariadb']['mysqld']['service_name'] = 'mysql' -end -default['mariadb']['mysqld']['user'] = 'mysql' -default['mariadb']['mysqld']['port'] = '3306' -default['mariadb']['mysqld']['basedir'] = '/usr' -default['mariadb']['mysqld']['default_datadir'] = '/var/lib/mysql' -# if different from previous value, datadir will be moved after install -default['mariadb']['mysqld']['datadir'] = '/var/lib/mysql' -default['mariadb']['mysqld']['tmpdir'] = '/var/tmp' -default['mariadb']['mysqld']['lc_messages_dir'] = '/usr/share/mysql' -default['mariadb']['mysqld']['lc_messages'] = 'en_US' -default['mariadb']['mysqld']['skip_external_locking'] = 'true' -default['mariadb']['mysqld']['bind_address'] = '127.0.0.1' -default['mariadb']['mysqld']['max_connections'] = '100' -default['mariadb']['mysqld']['connect_timeout'] = '5' -default['mariadb']['mysqld']['wait_timeout'] = '600' -default['mariadb']['mysqld']['max_allowed_packet'] = '16M' -default['mariadb']['mysqld']['thread_cache_size'] = '128' -default['mariadb']['mysqld']['sort_buffer_size'] = '4M' -default['mariadb']['mysqld']['bulk_insert_buffer_size'] = '16M' -default['mariadb']['mysqld']['tmp_table_size'] = '32M' -default['mariadb']['mysqld']['max_heap_table_size'] = '32M' -default['mariadb']['mysqld']['myisam_recover'] = 'BACKUP' -default['mariadb']['mysqld']['key_buffer_size'] = '128M' -# if not defined default is 2000 -default['mariadb']['mysqld']['open_files_limit'] = '' -default['mariadb']['mysqld']['table_open_cache'] = '400' -default['mariadb']['mysqld']['myisam_sort_buffer_size'] = '512M' -default['mariadb']['mysqld']['concurrent_insert'] = '2' -default['mariadb']['mysqld']['read_buffer_size'] = '2M' -default['mariadb']['mysqld']['read_rnd_buffer_size'] = '1M' -default['mariadb']['mysqld']['query_cache_limit'] = '128K' -default['mariadb']['mysqld']['query_cache_size'] = '64M' -# if not defined default is ON -default['mariadb']['mysqld']['query_cache_type'] = '' -default['mariadb']['mysqld']['default_storage_engine'] = 'InnoDB' -default['mariadb']['mysqld']['options'] = {} - -# -# InnoDB default configuration -# -# if not defined default is 50M -default['mariadb']['innodb']['log_file_size'] = '' -default['mariadb']['innodb']['bps_percentage_memory'] = false -default['mariadb']['innodb']['buffer_pool_size'] = '256M' -default['mariadb']['innodb']['log_buffer_size'] = '8M' -default['mariadb']['innodb']['file_per_table'] = '1' -default['mariadb']['innodb']['open_files'] = '400' -default['mariadb']['innodb']['io_capacity'] = '400' -default['mariadb']['innodb']['flush_method'] = 'O_DIRECT' -default['mariadb']['innodb']['options'] = {} - -# -# Galera default configuration -# -default['mariadb']['galera']['cluster_name'] = 'galera_cluster' -default['mariadb']['galera']['cluster_search_query'] = '' -default['mariadb']['galera']['wsrep_sst_method'] = 'rsync' -default['mariadb']['galera']['wsrep_provider'] = \ - '/usr/lib/galera/libgalera_smm.so' -default['mariadb']['galera']['options'] = {} - -# Node format: [{ :name => "mariadb_1", fqdn: "33.33.33.11"}] -default['mariadb']['galera']['cluster_nodes'] = [] - -# -# Replication default configuration -# -default['mariadb']['replication']['server_id'] = '' -default['mariadb']['replication']['log_bin'] = \ - '/var/log/mysql/mariadb-bin' -default['mariadb']['replication']['log_bin_index'] = \ - '/var/log/mysql/mariadb-bin.index' -default['mariadb']['replication']['expire_logs_days'] = '10' -default['mariadb']['replication']['max_binlog_size'] = '100M' -default['mariadb']['replication']['options'] = {} - -# -# mysqldump default configuration -# -default['mariadb']['mysqldump']['quick'] = 'true' -default['mariadb']['mysqldump']['quote_names'] = 'true' -default['mariadb']['mysqldump']['max_allowed_packet'] = '16M' - -# -# isamchk default configuration -default['mariadb']['isamchk']['key_buffer'] = '16M' - -# -# mysqld_safe default configuration -# -default['mariadb']['mysqld_safe']['options'] = {} - -# -# client default configuration -# -default['mariadb']['client']['port'] = 3306 -default['mariadb']['client']['options'] = {} -default['mariadb']['client']['development_files'] = true - -# -# debian specific configuration -# -default['mariadb']['debian']['user'] = 'debian-sys-maint' -default['mariadb']['debian']['password'] = 'please-change-me' -default['mariadb']['debian']['host'] = 'localhost' - -# -# mariadb default install configuration -# -# install valid value is 'package', -# hope to have 'from_source' in the near future -default['mariadb']['install']['type'] = 'package' -default['mariadb']['install']['version'] = '10.0' -default['mariadb']['install']['prefer_os_package'] = false - -# -# package(apt or yum) default configuration -# -default['mariadb']['use_default_repository'] = false -default['mariadb']['apt_repository']['base_url'] = \ - 'ftp.igh.cnrs.fr/pub/mariadb/repo' - -# -# MariaDB Plugins enabling -# -default['mariadb']['plugins_options']['auto_install'] = true -# Enabling Plugin Installation -default['mariadb']['plugins']['audit'] = false -# Load Plugins in .cnf (plugin-loadi variable) -default['mariadb']['plugins_loading']['audit'] = 'server_audit=server_audit.so' - -# Default Configuration -default['mariadb']['audit_plugin']['server_audit_events'] = '' -default['mariadb']['audit_plugin']['server_audit_output_type'] = 'file' -# Syslog (require server_audit_output_type = syslog) -default['mariadb']['audit_plugin']['server_audit_syslog_facility'] = 'LOG_USER' -default['mariadb']['audit_plugin']['server_audit_syslog_priority'] = 'LOG_INFO' diff --git a/cookbooks/mariadb/libraries/mariadb_helper.rb b/cookbooks/mariadb/libraries/mariadb_helper.rb deleted file mode 100644 index 8e8e706..0000000 --- a/cookbooks/mariadb/libraries/mariadb_helper.rb +++ /dev/null @@ -1,78 +0,0 @@ -# MariaDB is a module containing mariadb cookbook helper -module MariaDB - # Helper module for mariadb cookbook - module Helper - require 'socket' - require 'timeout' - - def do_port_connect(ip, port) - s = TCPSocket.new(ip, port) - s.close - true - rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH - false - end - - def port_open?(ip, port) - begin - Timeout.timeout(5) do - return do_port_connect(ip, port) - end - rescue Timeout::Error - false - end - false - end - - # Trying to determine if we need to restart the mysql service - def mariadb_service_restart_required?(ip, port, _socket) - restart = false - restart = true unless port_open?(ip, port) - restart - end - - # Helper to determine if running operating system shipped a package for - # mariadb server & client. No galera shipped in any os yet. - # @param [String] os_platform Indicate operating system type, e.g. centos - # @param [String] os_version Indicate operating system version, e.g. 7.0 - def os_package_provided?(os_platform, os_version) - package_provided = false - case os_platform - when 'centos', 'redhat' - package_provided = true if os_version.to_i == 7 - when 'fedora' - package_provided = true if os_version.to_i >= 19 - end - package_provided - end - - # Helper to determine mariadb server service name shipped by native package - # If no native package available on this platform, return nil - # @param [String] os_platform Indicate operating system type, e.g. centos - # @param [String] os_version Indicate operating system version, e.g. 7.0 - def os_service_name(os_platform, os_version) - return nil unless os_package_provided?(os_platform, os_version) - service_name = 'mariadb' - if os_platform == 'fedora' && os_version.to_i >= 19 - service_name = 'mysqld' - end - service_name - end - - # Helper to determine whether to use os native package - # @param [Boolean] prefer_os Indicate whether to prefer os native package - # @param [String] os_platform Indicate operating system type, e.g. centos - # @param [String] os_version Indicate operating system version, e.g. 7.0 - def use_os_native_package?(prefer_os, os_platform, os_version) - return false unless prefer_os - if os_package_provided?(os_platform, os_version) - true - else - Chef::Log.warn 'prefer_os_package detected, but no native mariadb'\ - " package available on #{os_platform}-#{os_version}."\ - ' Fall back to use community package.' - false - end - end - end -end diff --git a/cookbooks/mariadb/libraries/matchers.rb b/cookbooks/mariadb/libraries/matchers.rb deleted file mode 100644 index 91f1cc1..0000000 --- a/cookbooks/mariadb/libraries/matchers.rb +++ /dev/null @@ -1,21 +0,0 @@ -if defined?(ChefSpec) - def add_mariadb_configuration(resource_name) - ChefSpec::Matchers::ResourceMatcher - .new(:mariadb_configuration, :add, resource_name) - end - - def remove_mariadb_configuration(resource_name) - ChefSpec::Matchers::ResourceMatcher - .new(:mariadb_configuration, :remove, resource_name) - end - - def add_mariadb_replication(resource_name) - ChefSpec::Matchers::ResourceMatcher - .new(:mariadb_replication, :add, resource_name) - end - - def remove_mariadb_replication(resource_name) - ChefSpec::Matchers::ResourceMatcher - .new(:mariadb_replication, :remove, resource_name) - end -end diff --git a/cookbooks/mariadb/metadata.json b/cookbooks/mariadb/metadata.json deleted file mode 100644 index 049ad57..0000000 --- a/cookbooks/mariadb/metadata.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"mariadb","version":"0.3.1","description":"Installs/Configures MariaDB","long_description":"MariaDB Cookbook\n================\n\n[![Build Status](https://travis-ci.org/sinfomicien/mariadb.png)](https://travis-ci.org/sinfomicien/mariadb)\n\nDescription\n-----------\n\nThis cookbook contains all the stuffs to install and configure a mariadb server on a dpkg/apt compliant system (typically debian), or a rpm/yum compliant system (typically centos)\n\n\nRequirements\n------------\n\n#### repository\n- `mariadb` - This cookbook need that you have a valid apt repository installed with the mariadb official packages\n\n#### packages\n- `percona-xtrabackup` - if you want to use the xtrabckup SST Auth for galera cluster.\n- `socat` - if you want to use the xtrabckup SST Auth for galera cluster.\n- `rsync` - if you want to use the rsync SST Auth for galera cluster.\n- `debconf-utils` - if you use debian platform family.\n\n#### operating system\n- `debian` - this cookbook is fully tested on debian\n- `ubuntu` - not fully tested on ubuntu, but should work\n- `centos` - not fully tested on centos, but should work\n\nAttributes\n----------\n\n#### mariadb::default\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
KeyTypeDescriptionDefault
['mariadb']['install']['version']StringVersion to install (currently 10.0 et 5.5)10.0
['mariadb']['use_default_repository']BooleanWether to install MariaDB default repository or not. If you don't have a local repo containing packages, put it to truefalse
['mariadb']['server_root_password']Stringlocal root password
['mariadb']['forbid_remote_root']BooleanWether to activate root remote accesstrue
['mariadb']['allow_root_pass_change']BooleanWether to allow the recipe to change root password after the first installfalse
['mariadb']['client']['development_files']BooleanWether to install development files in client recipetrue
['mariadb']['apt_repository']['base_url']StringThe http base url to use when installing from default repository'ftp.igh.cnrs.fr/pub/mariadb/repo'
['mariadb']['install']['prefer_os_package']BooleanIndicator for preferring use packages shipped by running osfalse
\n\nUsage\n-----\n\nTo install a default server for mariadb choose the version you want (MariaDB 5.5 or 10, galera or not), then call the recipe accordingly.\n\nList of availables recipes:\n\n- mariadb::default (just call server recipe with default options)\n- mariadb::server\n- mariadb::galera\n- mariadb::client\n\nPlease be ware that by default, the root password is empty! If you want have changed it use the `node['mariadb']['server_root_password']` attribute to put a correct value. And by default the remote root access is not activated. Use `node['mariadb']['forbid_remote_root']` attribute to change it.\n\nSometimes, the default apt repository used for apt does not work (see issue #6). In this case, you need to choose another mirror which worki (pick it from mariadb website), and put the http base url in the attribute `node['mariadb']['apt_repository']['base_url']`.\n\n#### mariadb::galera\n\nWhen installing the mariadb::galera on debian recipe, You have to take care of one specific attribute:\n`node['mariadb']['debian']['password']` which default to 'please-change-me'\nAs wee need to have the same password for this user on the whole cluster nodes... We will change the default install one by the content of this attribute.\n\n#### mariadb::client\n\nBy default this recipe install the client, and all needed packages to develop client application. If you do not want to install development files when installing client package,\nset the attribute `node['mariadb']['client']['development_files']` to false. \n\nProviders\n----------\n\nThis recipe define 2 providers:\n- `Chef::Provider::Mariadb::Configuration` shortcut resource `mariadb_configuration`\n- `Chef::Provider::Mariadb::Replication` shortcut resource `mariadb_replication`\n\n#### mariadb_configuration\n\nMainly use for internal purpose. You can use it to create a new configuration file into configuration dir. You have to define 2 variables `section` and `option`.\nWhere `section` is the configuration section, and `option` is a hash of key/value. The name of the resource is used as base for the filename.\n\nExample:\n```ruby\nmariadb_configuration 'fake' do\n section 'mysqld'\n option {foo: 'bar'}\nend\n```\nwill become the file fake.cnf in the include dir (depend on your platform), which contain:\n```\n[mysqld]\nfoo=bar\n```\n\nIf the value start with a '#', then it's considered as a comment, and the value is printed as is (without the key)\n\nExample:\n```ruby\nmariadb_configuration 'fake' do\n section 'mysqld'\n option {comment1: '# Here i am', foo: bar}\nend\n```\nwill become the file fake.cnf in the include dir (depend on your platform), which contain:\n```\n[mysqld]\n# Here i am\nfoo=bar\n```\n\n#### mariadb_replication\n\nThis LWRP is used to manage replication setup on a host. To use this LWRP, the node need to have the mysql binary installed (via the mariadb::client or mariadb::server or mariadb::galera recipe).\nIt have 4 actions:\n- add - to add a new replication setup (become a slave)\n- stop - to stop the slave replication\n- start - to start the slave replication\n- remove - to remove the slave replication configuration\n\nThe resource name need to be 'default' if your don't want to use a named connection (multi source replication in MariaDB 10).\n\nSo by default the provider try to use the local instance of mysql, with the current user and no password. If you want to change, you have to define `host`, `port`, `user` or `password`\n\n```ruby\nmariadb_replication 'default' do\n user 'root'\n password 'fakepass'\n host 'fakehost'\n action :stop\nend\n```\nwill stop the replication on the host `fakehost` using the user `root` and password `fakepass` to connect to.\n\nWhen you add a replication configuration, you have to define at least 4 values `master_host`, `master_user`, `master_password` and `master_use_gtid`. And if you don't want the GTID support, you have to define also `master_log_file` and `master_log_pos`\n\nExample:\n```ruby\nmariadb_replication 'usefull_conn_name' do\n master_host 'server1'\n master_user 'slave_user'\n master_password 'slave_password'\n master_use_gtid 'current_pos'\n action :add\nend\n```\n\nContributing\n------------\n\n1. Fork the repository on Github\n2. Create a named feature branch (like `add_component_x`)\n3. Write your change\n4. Write tests for your change (if applicable)\n5. Run the tests, ensuring they all pass\n6. Submit a Pull Request using Github\n\nLicense and Authors\n-------------------\nAuthors:\nNicolas Blanc \n","maintainer":"Nicolas Blanc","maintainer_email":"sinfomicien@gmail.com","license":"Apache 2.0","platforms":{"ubuntu":">= 0.0.0","debian":">= 7.0","centos":">= 6.4","redhat":">= 7.0"},"dependencies":{"apt":">= 0.0.0","yum":">= 0.0.0","yum-epel":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{}} \ No newline at end of file diff --git a/cookbooks/mariadb/providers/configuration.rb b/cookbooks/mariadb/providers/configuration.rb deleted file mode 100644 index 46adea3..0000000 --- a/cookbooks/mariadb/providers/configuration.rb +++ /dev/null @@ -1,38 +0,0 @@ -# -# Cookbook Name:: mariadb -# Provider:: configuration -# - -use_inline_resources if defined?(use_inline_resources) - -def whyrun_supported? - true -end - -action :add do - variables_hash = { - section: new_resource.section, - options: new_resource.option - } - template node['mariadb']['configuration']['includedir'] + \ - '/' + new_resource.name + '.cnf' do - source 'conf.d.generic.erb' - owner 'root' - group 'mysql' - mode '0640' - cookbook 'mariadb' - variables variables_hash - end -end - -action :remove do - if ::File.exist?(node['mariadb']['configuration']['includedir'] + \ - '/' + new_resource.name + '.cnf') - Chef::Log.info "Removing #{new_resource.name} repository from " + \ - node['mariadb']['configuration']['includedir'] - file node['mariadb']['configuration']['includedir'] + \ - '/' + new_resource.name + '.cnf' do - action :delete - end - end -end diff --git a/cookbooks/mariadb/providers/replication.rb b/cookbooks/mariadb/providers/replication.rb deleted file mode 100644 index 6470023..0000000 --- a/cookbooks/mariadb/providers/replication.rb +++ /dev/null @@ -1,105 +0,0 @@ -# -# Cookbook Name:: mariadb -# Provider:: replication -# - -use_inline_resources if defined?(use_inline_resources) - -def whyrun_supported? - true -end - -def get_mysql_command(host, port, user, password) - mysql_command = '/usr/bin/mysql' - mysql_command += ' -h ' + host unless host.nil? - mysql_command += ' -P ' + port unless port.nil? - mysql_command += ' -u ' + user unless user.nil? - mysql_command += ' -p' + password unless password.nil? - mysql_command -end - -action :add do - if new_resource.master_host.nil? || new_resource.master_user.nil? || - new_resource.master_password.nil? - fail '[ERROR] When adding a slave, you have to define master_host' \ - ' master_user and master_password !' - end - sql_string = 'CHANGE MASTER ' - sql_string += '\'' + new_resource.name + \ - '\' ' if new_resource.name != 'default' - sql_string += 'TO ' - sql_string += 'MASTER_HOST=\'' + new_resource.master_host + '\', ' - sql_string += 'MASTER_PORT=' + new_resource.master_port.to_s + \ - ', ' unless new_resource.master_port.nil? - sql_string += 'MASTER_USER=\'' + new_resource.master_user + '\', ' - sql_string += 'MASTER_PASSWORD=\'' + new_resource.master_password + '\'' - if new_resource.master_use_gtid == 'no' - # Use non GTID replication setup - if new_resource.master_log_file.nil? || new_resource.master_log_pos.nil? - fail '[ERROR] When adding a slave without GTID, you have to' \ - 'define master_log_file and master_log_pos !' - end - unless new_resource.master_log_file.nil? - sql_string += ', MASTER_LOG_FILE=\'' + \ - new_resource.master_log_file + '\'' - sql_string += ', MASTER_LOG_POS=' + new_resource.master_log_pos.to_s - end - else - # Use GTID replication - sql_string += ', MASTER_USE_GTID=' + new_resource.master_use_gtid + ';' - end - execute 'add_replication_from_master_' + new_resource.name do - # Add sensitive true when foodcritic #233 fixed - command '/bin/echo "' + sql_string + '" | ' + get_mysql_command( - new_resource.host, - new_resource.port, - new_resource.user, - new_resource.password - ) - action :run - end -end - -action :remove do - execute 'remove_replication_from_master_' + new_resource.name do - # Add sensitive true when foodcritic #233 fixed - command '/bin/echo "STOP SLAVE \'' + new_resource.name + '\'; ' \ - 'RESET SLAVE \'' + new_resource.name + '\' ALL' \ - ';" | ' + get_mysql_command( - new_resource.host, - new_resource.port, - new_resource.user, - new_resource.password - ) - end -end - -action :start do - command_master_connection = ' \'' + new_resource.name + \ - '\'' unless new_resource.name == 'default' - execute 'start_replication_from_master_' + new_resource.name do - # Add sensitive true when foodcritic #233 fixed - command '/bin/echo "START SLAVE' + command_master_connection + ';' \ - '" | ' + get_mysql_command( - new_resource.host, - new_resource.port, - new_resource.user, - new_resource.password - ) - end -end - -action :stop do - command_master_connection = ' \'' + new_resource.name + \ - '\'' unless new_resource.name == 'default' - execute 'start_replication_from_master_' + new_resource.name do - # Add sensitive true when foodcritic #233 fixed - command '/bin/echo "STOP SLAVE' + command_master_connection + ';' \ - '" | ' + get_mysql_command( - new_resource.host, - new_resource.port, - new_resource.user, - new_resource.password - ) - end -end diff --git a/cookbooks/mariadb/recipes/_audit_plugin.rb b/cookbooks/mariadb/recipes/_audit_plugin.rb deleted file mode 100644 index 9b8d030..0000000 --- a/cookbooks/mariadb/recipes/_audit_plugin.rb +++ /dev/null @@ -1,53 +0,0 @@ -# Prepare Configuration File -audit_plugin_options = {} - -audit_plugin_options['comment1'] = '#' -audit_plugin_options['comment2'] = '# * MariaDB Audit Plugin' -audit_plugin_options['comment3'] = '#' - -audit_plugin_options['server_audit_events'] = \ - node['mariadb']['audit_plugin']['server_audit_events'] -audit_plugin_options['server_audit_output_type'] = \ - node['mariadb']['audit_plugin']['server_audit_output_type'] -audit_plugin_options['server_audit_syslog_facility'] = \ - node['mariadb']['audit_plugin']['server_audit_syslog_facility'] -audit_plugin_options['server_audit_syslog_priority'] = \ - node['mariadb']['audit_plugin']['server_audit_syslog_priority'] - -audit_plugin_options['enable'] = '#server_audit_logging = ON' - -# Install the MariaDB Audit Plugin -execute 'install_mariadb_audit_plugin' do - command '/usr/bin/mysql -e "INSTALL PLUGIN server_audit '\ - 'SONAME \'server_audit\';"' - notifies :run, 'execute[configure_mariadb_audit_plugin]', :immediately - not_if do - cmd = Mixlib::ShellOut.new('/usr/bin/mysql -u root -B -N -e "SELECT 1 '\ - 'FROM information_schema.plugins '\ - 'WHERE PLUGIN_NAME = \'SERVER_AUDIT\''\ - 'AND PLUGIN_STATUS = \'ACTIVE\';"') - cmd.run_command - cmd.stdout.to_i == 1 - end -end - -# Configure (Dynamic) -execute 'configure_mariadb_audit_plugin' do - command 'echo "SET GLOBAL server_audit_events=\'' + \ - node['mariadb']['audit_plugin']['server_audit_events'] + '\';' \ - 'SET GLOBAL server_audit_output_type=\'' + \ - node['mariadb']['audit_plugin']['server_audit_output_type'] + '\';' \ - 'SET GLOBAL server_audit_syslog_facility=\'' + \ - node['mariadb']['audit_plugin']['server_audit_syslog_facility'] + '\';' \ - 'SET GLOBAL server_audit_syslog_priority=\'' + \ - node['mariadb']['audit_plugin']['server_audit_syslog_priority'] + '\';"' \ - '| /usr/bin/mysql' - action :nothing -end - -# Create Configuration File -mariadb_configuration 'audit_plugin' do - section 'mysqld' - option audit_plugin_options - action :add -end diff --git a/cookbooks/mariadb/recipes/_debian_galera.rb b/cookbooks/mariadb/recipes/_debian_galera.rb deleted file mode 100644 index 63531ea..0000000 --- a/cookbooks/mariadb/recipes/_debian_galera.rb +++ /dev/null @@ -1,55 +0,0 @@ -# -# Cookbook Name:: mariadb -# Recipe:: _debian_galera -# -# Copyright 2014, blablacar.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. -# - -# To be sure that debconf is installed -package 'debconf-utils' do - action :install -end - -# Preseed Debian Package -# (but test for resource, as it can be declared by apt recipe) -begin - resources(directory: '/var/cache/local/preseeding') -rescue Chef::Exceptions::ResourceNotFound - directory '/var/cache/local/preseeding' do - owner 'root' - group 'root' - mode '0755' - recursive true - end -end - -template '/var/cache/local/preseeding/mariadb-galera-server.seed' do - source 'mariadb-server.seed.erb' - owner 'root' - group 'root' - mode '0600' - variables(package_name: 'mariadb-galera-server') - notifies :run, 'execute[preseed mariadb-galera-server]', :immediately -end - -execute 'preseed mariadb-galera-server' do - command '/usr/bin/debconf-set-selections ' \ - '/var/cache/local/preseeding/mariadb-galera-server.seed' - action :nothing -end - -package "mariadb-galera-server-#{node['mariadb']['install']['version']}" do - action :install -end diff --git a/cookbooks/mariadb/recipes/_debian_server.rb b/cookbooks/mariadb/recipes/_debian_server.rb deleted file mode 100644 index 4c17531..0000000 --- a/cookbooks/mariadb/recipes/_debian_server.rb +++ /dev/null @@ -1,55 +0,0 @@ -# -# Cookbook Name:: mariadb -# Recipe:: _debian_server -# -# Copyright 2014, blablacar.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. -# - -# To be sure that debconf is installed -package 'debconf-utils' do - action :install -end - -# Preseed Debian Package -# (but test for resource, as it can be declared by apt recipe) -begin - resources(directory: '/var/cache/local/preseeding') -rescue Chef::Exceptions::ResourceNotFound - directory '/var/cache/local/preseeding' do - owner 'root' - group 'root' - mode '0755' - recursive true - end -end - -template '/var/cache/local/preseeding/mariadb-server.seed' do - source 'mariadb-server.seed.erb' - owner 'root' - group 'root' - mode '0600' - variables(package_name: 'mariadb-server') - notifies :run, 'execute[preseed mariadb-server]', :immediately -end - -execute 'preseed mariadb-server' do - command '/usr/bin/debconf-set-selections ' \ - '/var/cache/local/preseeding/mariadb-server.seed' - action :nothing -end - -package "mariadb-server-#{node['mariadb']['install']['version']}" do - action :install -end diff --git a/cookbooks/mariadb/recipes/_redhat_galera.rb b/cookbooks/mariadb/recipes/_redhat_galera.rb deleted file mode 100644 index 8d725db..0000000 --- a/cookbooks/mariadb/recipes/_redhat_galera.rb +++ /dev/null @@ -1,49 +0,0 @@ -# -# Cookbook Name:: mariadb -# Recipe:: _redhat_galera -# -# Copyright 2014, blablacar.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. -# - -# To force removing of mariadb-libs on CentOS >= 7 -package 'MariaDB-shared' do - action :install -end - -package 'MariaDB-Galera-server' do - action :install - notifies :create, 'directory[/var/log/mysql]', :immediately - notifies :start, 'service[mysql]', :immediately - notifies :run, 'execute[change first install root password]', :immediately -end - -directory '/var/log/mysql' do - action :nothing - user 'mysql' - group 'mysql' - mode '0755' -end - -service 'mysql' do - action :nothing -end - -execute 'change first install root password' do - # Add sensitive true when foodcritic #233 fixed - command '/usr/bin/mysqladmin -u root password \'' + \ - node['mariadb']['server_root_password'] + '\'' - action :nothing - not_if { node['mariadb']['server_root_password'].empty? } -end diff --git a/cookbooks/mariadb/recipes/_redhat_server.rb b/cookbooks/mariadb/recipes/_redhat_server.rb deleted file mode 100644 index 4c0805a..0000000 --- a/cookbooks/mariadb/recipes/_redhat_server.rb +++ /dev/null @@ -1,48 +0,0 @@ -# -# Cookbook Name:: mariadb -# Recipe:: _redhat_server -# -# Copyright 2014, blablacar.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. -# - -# To force removing of mariadb-libs on CentOS >= 7 -package 'MariaDB-shared' do - action :install -end - -package 'MariaDB-server' do - action :install - notifies :create, 'directory[/var/log/mysql]', :immediately - notifies :start, 'service[mysql]', :immediately - notifies :run, 'execute[change first install root password]', :immediately -end - -directory '/var/log/mysql' do - action :nothing - user 'mysql' - group 'mysql' - mode '0755' -end - -execute 'change first install root password' do - # Add sensitive true when foodcritic #233 fixed - command '/usr/bin/mysqladmin -u root password \'' + \ - node['mariadb']['server_root_password'] + '\'' - action :nothing - not_if { node['mariadb']['server_root_password'].empty? } -end - -# Default policy for RH and fedora is to name it mysql -node.set['mariadb']['mysqld']['service_name'] = 'mysql' diff --git a/cookbooks/mariadb/recipes/_redhat_server_native.rb b/cookbooks/mariadb/recipes/_redhat_server_native.rb deleted file mode 100644 index 527a371..0000000 --- a/cookbooks/mariadb/recipes/_redhat_server_native.rb +++ /dev/null @@ -1,45 +0,0 @@ -# -# Cookbook Name:: mariadb -# Recipe:: _redhat_server_native -# -# 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. -# -# This recipe is for install and configure os shipped mariadb package - -Chef::Recipe.send(:include, MariaDB::Helper) - -service_name = os_service_name(node['platform'], node['platform_version']) -node.set['mariadb']['mysqld']['service_name'] = service_name\ - unless service_name.nil? - -package 'mariadb-server' do - action :install - notifies :enable, 'service[mysql]' -end - -directory '/var/log/mysql' do - action :create - user 'mysql' - group 'mysql' - mode '0755' - notifies :start, 'service[mysql]', :immediately - notifies :run, 'execute[change first install root password]', :immediately -end - -execute 'change first install root password' do - # Add sensitive true when foodcritic #233 fixed - command '/usr/bin/mysqladmin -u root password \'' + \ - node['mariadb']['server_root_password'] + '\'' - action :nothing - not_if { node['mariadb']['server_root_password'].empty? } -end diff --git a/cookbooks/mariadb/recipes/client.rb b/cookbooks/mariadb/recipes/client.rb deleted file mode 100644 index a1296d2..0000000 --- a/cookbooks/mariadb/recipes/client.rb +++ /dev/null @@ -1,89 +0,0 @@ -# -# Cookbook Name:: mariadb -# Recipe:: client -# -# Copyright 2014, blablacar.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. -# - -Chef::Recipe.send(:include, MariaDB::Helper) -case node['mariadb']['install']['type'] -when 'package' - use_os_package = use_os_native_package?( - node['mariadb']['install']['prefer_os_package'], - node['platform'], - node['platform_version']) - - include_recipe "#{cookbook_name}::repository" unless use_os_package - - case node['platform_family'] - when 'rhel' - # On CentOS at least, there's a conflict between MariaDB and mysql-libs - package 'mysql-libs' do - action :remove - not_if { use_os_package } - end - - # rubocop:disable BlockNesting - if use_os_package - if node['mariadb']['client']['development_files'] - node.default['mariadb']['client']['packages'] = \ - %w(mariadb mariadb-devel) - else - node.default['mariadb']['client']['packages'] = \ - %w(mariadb) - end - else - if node['mariadb']['client']['development_files'] - node.default['mariadb']['client']['packages'] = \ - %w(MariaDB-client MariaDB-devel) - else - node.default['mariadb']['client']['packages'] = \ - %w(MariaDB-client) - end - end - # rubocop:enable BlockNesting - when 'fedora' - if node['mariadb']['client']['development_files'] - node.default['mariadb']['client']['packages'] = \ - %w(mariadb mariadb-devel) - else - node.default['mariadb']['client']['packages'] = \ - %w(mariadb) - end - when 'suse' - if node['mariadb']['client']['development_files'] - node.default['mariadb']['client']['packages'] = \ - %w(mariadb-community-server-client libmariadbclient-devel) - else - node.default['mariadb']['client']['packages'] = \ - %w(mariadb-community-server-client) - end - when 'debian' - if node['mariadb']['client']['development_files'] - node.default['mariadb']['client']['packages'] = \ - %W(mariadb-client-#{node['mariadb']['install']['version']} - libmariadbclient-dev) - else - node.default['mariadb']['client']['packages'] = \ - %W(mariadb-client-#{node['mariadb']['install']['version']}) - end - end - - node['mariadb']['client']['packages'].each do |name| - package name - end -when 'from_source' - # To be filled as soon as possible -end diff --git a/cookbooks/mariadb/recipes/config.rb b/cookbooks/mariadb/recipes/config.rb deleted file mode 100644 index 33ce0e1..0000000 --- a/cookbooks/mariadb/recipes/config.rb +++ /dev/null @@ -1,95 +0,0 @@ -# -# Cookbook Name:: mariadb -# Recipe:: config -# -# Copyright 2014, blablacar.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. -# - -template node['mariadb']['configuration']['path'] + '/my.cnf' do - source 'my.cnf.erb' - owner 'root' - group 'root' - mode '0644' -end - -innodb_options = {} - -innodb_options['comment1'] = '#' -innodb_options['comment2'] = '# * InnoDB' -innodb_options['comment3'] = '#' -innodb_options['comment4'] = '# InnoDB is enabled by default with a 10MB ' \ - 'datafile in /var/lib/mysql/.' -innodb_options['comment5'] = '# Read the manual for more InnoDB ' \ - 'related options. There are many!' - -innodb_options['innodb_log_file_size_comment1'] = '# you can\'t just ' \ - 'change log file size, ' \ - 'requires special procedure' -if node['mariadb']['innodb']['log_file_size'].empty? - innodb_options['innodb_log_file_size'] = '#innodb_log_file_size = 50M' -else - innodb_options['innodb_log_file_size'] = \ - node['mariadb']['innodb']['log_file_size'] -end -if node['mariadb']['innodb']['bps_percentage_memory'] - innodb_options['innodb_buffer_pool_size'] = ( - ( - node['mariadb']['innodb']['buffer_pool_size'].to_f * - (node['memory']['total'][0..-3].to_i / 1024) - ).round).to_s + 'M' -else - innodb_options['innodb_buffer_pool_size'] = \ - node['mariadb']['innodb']['buffer_pool_size'] -end -innodb_options['innodb_log_buffer_size'] = \ - node['mariadb']['innodb']['log_buffer_size'] -innodb_options['innodb_file_per_table'] = \ - node['mariadb']['innodb']['file_per_table'] -innodb_options['innodb_open_files'] = node['mariadb']['innodb']['open_files'] -innodb_options['innodb_io_capacity'] = \ - node['mariadb']['innodb']['io_capacity'] -innodb_options['innodb_flush_method'] = \ - node['mariadb']['innodb']['flush_method'] -node['mariadb']['innodb']['options'].each do |key, value| - innodb_options[key] = value -end - -mariadb_configuration 'innodb' do - section 'mysqld' - option innodb_options - action :add -end - -replication_opts = {} - -replication_opts['log_bin'] = node['mariadb']['replication']['log_bin'] -replication_opts['log_bin_index'] = \ - node['mariadb']['replication']['log_bin_index'] -replication_opts['expire_logs_days'] = \ - node['mariadb']['replication']['expire_logs_days'] -replication_opts['max_binlog_size'] = \ - node['mariadb']['replication']['max_binlog_size'] -unless node['mariadb']['replication']['server_id'].empty? - replication_opts['server-id'] = node['mariadb']['replication']['server_id'] -end -node['mariadb']['replication']['options'].each do |key, value| - replication_opts[key] = value -end - -mariadb_configuration 'replication' do - section 'mysqld' - option replication_opts - action :add -end diff --git a/cookbooks/mariadb/recipes/default.rb b/cookbooks/mariadb/recipes/default.rb deleted file mode 100644 index 7edcd87..0000000 --- a/cookbooks/mariadb/recipes/default.rb +++ /dev/null @@ -1,20 +0,0 @@ -# -# Cookbook Name:: mariadb -# Recipe:: default -# -# Copyright 2014, blablacar.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. -# - -include_recipe "#{cookbook_name}::server" diff --git a/cookbooks/mariadb/recipes/galera.rb b/cookbooks/mariadb/recipes/galera.rb deleted file mode 100644 index df98265..0000000 --- a/cookbooks/mariadb/recipes/galera.rb +++ /dev/null @@ -1,179 +0,0 @@ -# -# Cookbook Name:: mariadb -# Recipe:: galera -# -# Copyright 2014, blablacar.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. -# - -case node['mariadb']['install']['type'] -when 'package' - # include MariaDB repositories - include_recipe "#{cookbook_name}::repository" - - case node['platform'] - when 'debian', 'ubuntu' - include_recipe "#{cookbook_name}::_debian_galera" - when 'redhat', 'centos', 'fedora', 'scientific', 'amazon' - include_recipe "#{cookbook_name}::_redhat_galera" - end -when 'from_source' - # To be filled as soon as possible -end - -if node['mariadb']['galera']['wsrep_sst_method'] == 'rsync' - package 'rsync' do - action :install - end -else - if node['mariadb']['galera']['wsrep_sst_method'] =~ /^xtrabackup(-v2)?/ - package 'percona-xtrabackup' do - action :install - end - - package 'socat' do - action :install - end - end -end - -include_recipe "#{cookbook_name}::config" - -galera_cluster_nodes = [] -if !node['mariadb'].attribute?('rspec') && Chef::Config[:solo] - if node['mariadb']['galera']['cluster_nodes'].empty? - Chef::Log.warn('By default this recipe uses search (unsupported by Chef Solo).' \ - ' Nodes may manually be configured as attributes.') - else - galera_cluster_nodes = node['mariadb']['galera']['cluster_nodes'] - end -else - if node['mariadb']['galera']['cluster_search_query'].empty? - galera_cluster_nodes = search( - :node, \ - "mariadb_galera_cluster_name:#{node['mariadb']['galera']['cluster_name']}" - ) - else - galera_cluster_nodes = search 'node', node['mariadb']['galera']['cluster_search_query'] - log 'Chef search results' do - message "Searching for \"#{node['mariadb']['galera']['cluster_search_query']}\" \ - resulted in \"#{galera_cluster_nodes}\" ..." - end - end - # Sort Nodes by fqdn - galera_cluster_nodes.sort! { |x, y| x[:fqdn] <=> y[:fqdn] } -end - -first = true -gcomm = 'gcomm://' -galera_cluster_nodes.each do |lnode| - next unless lnode.name != node.name - gcomm += ',' unless first - gcomm += lnode['fqdn'] - first = false -end - -galera_options = {} - -galera_options['wsrep_cluster_address'] = gcomm -galera_options['wsrep_cluster_name'] = \ - node['mariadb']['galera']['cluster_name'] -galera_options['wsrep_sst_method'] = \ - node['mariadb']['galera']['wsrep_sst_method'] -if node['mariadb']['galera'].attribute?('wsrep_sst_auth') - galera_options['wsrep_sst_auth'] = \ - node['mariadb']['galera']['wsrep_sst_auth'] -end -galera_options['wsrep_provider'] = \ - node['mariadb']['galera']['wsrep_provider'] -galera_options['wsrep_slave_threads'] = node['cpu']['total'] * 4 -node['mariadb']['galera']['options'].each do |key, value| - galera_options[key] = value -end - -mariadb_configuration 'galera' do - section 'mysqld' - option galera_options - action :add -end - -# -# Under debian system we have to change the debian-sys-maint default password. -# This password is the same for the overall cluster. -# -if platform?('debian', 'ubuntu') - template '/etc/mysql/debian.cnf' do - sensitive true - source 'debian.cnf.erb' - owner 'root' - group 'root' - mode '0600' - end - - grants_command = 'mysql -r -B -N -u root ' - - if node['mariadb']['server_root_password'].is_a?(String) - grants_command += '--password=\'' + \ - node['mariadb']['server_root_password'] + '\' ' - end - - grants_command += '-e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ' \ - 'DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, ' \ - 'INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY ' \ - 'TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, ' \ - 'REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ' \ - 'ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON ' \ - ' *.* TO \'' + node['mariadb']['debian']['user'] + \ - '\'@\'' + node['mariadb']['debian']['host'] + '\' ' \ - 'IDENTIFIED BY \'' + \ - node['mariadb']['debian']['password'] + '\' WITH GRANT ' \ - 'OPTION"' - - execute 'correct-debian-grants' do - # Add sensitive true when foodcritic #233 fixed - command grants_command - action :run - only_if do - cmd = Mixlib::ShellOut.new("/usr/bin/mysql --user=\"" + \ - node['mariadb']['debian']['user'] + \ - "\" --password=\"" + node['mariadb']['debian']['password'] + \ - "\" -r -B -N -e \"SELECT 1\"") - cmd.run_command - cmd.error? - end - ignore_failure true - end -end - -# -# NOTE: You cannot use the following code to restart Mariadb when in Galera mode. -# When your SST is longer than a chef run... -# ==> chef-client try to restart the service each time it run <== -# - -# restart the service if needed -# workaround idea from https://github.com/stissot -# -# Chef::Resource::Execute.send(:include, MariaDB::Helper) -# execute 'mariadb-service-restart-needed' do -# command 'true' -# only_if do -# mariadb_service_restart_required?( -# node['mariadb']['mysqld']['bind-address'], -# node['mariadb']['mysqld']['port'], -# node['mariadb']['mysqld']['socket'] -# ) -# end -# notifies :restart, 'service[mysql]', :immediately -# end diff --git a/cookbooks/mariadb/recipes/plugins.rb b/cookbooks/mariadb/recipes/plugins.rb deleted file mode 100644 index 5a722bc..0000000 --- a/cookbooks/mariadb/recipes/plugins.rb +++ /dev/null @@ -1,3 +0,0 @@ -node['mariadb']['plugins'].each do |plugin, enable| - include_recipe "#{cookbook_name}::_" + plugin + '_plugin' if enable -end diff --git a/cookbooks/mariadb/recipes/repository.rb b/cookbooks/mariadb/recipes/repository.rb deleted file mode 100644 index e8081eb..0000000 --- a/cookbooks/mariadb/recipes/repository.rb +++ /dev/null @@ -1,42 +0,0 @@ -case node['platform'] -when 'debian', 'ubuntu' - install_method = 'apt' -when 'redhat', 'centos', 'fedora', 'scientific', 'amazon' - install_method = 'yum' -end - -if node['mariadb']['use_default_repository'] - case install_method - when 'apt' - include_recipe 'apt::default' - - apt_repository "mariadb-#{node['mariadb']['install']['version']}" do - uri 'http://' + node['mariadb']['apt_repository']['base_url'] + '/' + \ - node['mariadb']['install']['version'] + '/' + node['platform'] - distribution node['lsb']['codename'] - components ['main'] - keyserver 'hkp://keyserver.ubuntu.com:80' - key '0xcbcb082a1bb943db' - end - when 'yum' - include_recipe 'yum::default' - - if node['platform'] == 'redhat' || node['platform'] == 'scientific' - target_platform = "rhel#{node['platform_version'].to_i}" - else - target_platform = "#{node['platform']}#{node['platform_version'].to_i}" - end - yum_repository "mariadb-#{node['mariadb']['install']['version']}" do - description 'MariaDB Official Repository' - baseurl 'http://yum.mariadb.org/' + \ - node['mariadb']['install']['version'] + "/#{target_platform}-amd64" - gpgkey 'https://yum.mariadb.org/RPM-GPG-KEY-MariaDB' - action :create - end - - case node['platform'] - when 'redhat', 'centos', 'scientific' - include_recipe 'yum-epel::default' - end - end -end diff --git a/cookbooks/mariadb/recipes/server.rb b/cookbooks/mariadb/recipes/server.rb deleted file mode 100644 index aa5db89..0000000 --- a/cookbooks/mariadb/recipes/server.rb +++ /dev/null @@ -1,130 +0,0 @@ -# -# Cookbook Name:: mariadb -# Recipe:: server -# -# Copyright 2014, blablacar.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. -# - -Chef::Recipe.send(:include, MariaDB::Helper) -case node['mariadb']['install']['type'] -when 'package' - if use_os_native_package?(node['mariadb']['install']['prefer_os_package'], - node['platform'], node['platform_version']) - # currently, no releases with apt (e.g. ubuntu) ship mariadb - # only provide one type of server here (with yum support) - include_recipe "#{cookbook_name}::_redhat_server_native" - else - include_recipe "#{cookbook_name}::repository" - - case node['platform'] - when 'debian', 'ubuntu' - include_recipe "#{cookbook_name}::_debian_server" - when 'redhat', 'centos', 'fedora', 'scientific', 'amazon' - include_recipe "#{cookbook_name}::_redhat_server" - end - end -when 'from_source' - # To be filled as soon as possible -end - -include_recipe "#{cookbook_name}::config" - -service 'mysql' do - service_name node['mariadb']['mysqld']['service_name'] - supports restart: true - action :nothing -end - -# move the datadir if needed -if node['mariadb']['mysqld']['datadir'] != - node['mariadb']['mysqld']['default_datadir'] - - bash 'move-datadir' do - user 'root' - code <<-EOH - /bin/cp -a #{node['mariadb']['mysqld']['default_datadir']}/* \ - #{node['mariadb']['mysqld']['datadir']} && - /bin/rm -r #{node['mariadb']['mysqld']['default_datadir']} && - /bin/ln -s #{node['mariadb']['mysqld']['datadir']} \ - #{node['mariadb']['mysqld']['default_datadir']} - EOH - action :nothing - end - - directory node['mariadb']['mysqld']['datadir'] do - owner 'mysql' - group 'mysql' - mode 00750 - action :create - notifies :stop, 'service[mysql]', :immediately - notifies :run, 'bash[move-datadir]', :immediately - notifies :start, 'service[mysql]', :immediately - only_if { !File.symlink?(node['mariadb']['mysqld']['default_datadir']) } - end -end - -# restart the service if needed -# workaround idea from https://github.com/stissot -Chef::Resource::Execute.send(:include, MariaDB::Helper) -execute 'mariadb-service-restart-needed' do - command 'true' - only_if do - mariadb_service_restart_required?( - node['mariadb']['mysqld']['bind_address'], - node['mariadb']['mysqld']['port'], - node['mariadb']['mysqld']['socket'] - ) - end - notifies :restart, 'service[mysql]', :immediately -end - -if node['mariadb']['allow_root_pass_change'] - # Used to change root password after first install - # Still experimental - if node['mariadb']['server_root_password'].empty? - md5 = Digest::MD5.hexdigest('empty') - else - md5 = Digest::MD5.hexdigest(node['mariadb']['server_root_password']) - end - - file '/etc/mysql_root_change' do - content md5 - action :create - notifies :run, 'execute[install-grants]', :immediately - end -end - -if node['mariadb']['allow_root_pass_change'] || - node['mariadb']['forbid_remote_root'] - execute 'install-grants' do - # Add sensitive true when foodcritic #233 fixed - command '/bin/bash /etc/mariadb_grants \'' + \ - node['mariadb']['server_root_password'] + '\'' - only_if { File.exist?('/etc/mariadb_grants') } - action :nothing - end - - template '/etc/mariadb_grants' do - sensitive true - source 'mariadb_grants.erb' - owner 'root' - group 'root' - mode '0600' - notifies :run, 'execute[install-grants]', :immediately - end -end - -# MariaDB Plugins -include_recipe "#{cookbook_name}::plugins" if node['mariadb']['plugins_options']['auto_install'] diff --git a/cookbooks/mariadb/resources/configuration.rb b/cookbooks/mariadb/resources/configuration.rb deleted file mode 100644 index 57e458a..0000000 --- a/cookbooks/mariadb/resources/configuration.rb +++ /dev/null @@ -1,13 +0,0 @@ -# -# Cookbook Name:: mariadb -# Resource:: configuration -# - -actions :add, :remove -default_action :add - -# name of the extra conf file, used for .cnf filename -attribute :conf_name, kind_of: String, name_attribute: true -attribute :section, kind_of: String -attribute :option, kind_of: Hash, default: {} -attribute :cookbook, kind_of: String, default: nil diff --git a/cookbooks/mariadb/resources/replication.rb b/cookbooks/mariadb/resources/replication.rb deleted file mode 100644 index afb0462..0000000 --- a/cookbooks/mariadb/resources/replication.rb +++ /dev/null @@ -1,22 +0,0 @@ -# -# Cookbook Name:: mariadb -# Resource:: replication -# - -actions :add, :remove, :start, :stop -default_action :add - -# name of the extra conf file, used for .cnf filename -attribute :connection_name, kind_of: String, name_attribute: true -attribute :host, kind_of: [String, NilClass], default: nil -attribute :port, kind_of: [String, NilClass], default: nil -attribute :user, kind_of: [String, NilClass], default: nil -attribute :password, kind_of: [String, NilClass], default: nil -attribute :master_host, kind_of: [String, NilClass], default: nil -attribute :master_user, kind_of: [String, NilClass], default: nil -attribute :master_password, kind_of: [String, NilClass], default: nil -attribute :master_connect_retry, kind_of: [String, NilClass], default: nil -attribute :master_port, kind_of: [Integer, NilClass], default: nil -attribute :master_log_pos, kind_of: [Integer, NilClass], default: nil -attribute :master_log_file, kind_of: [String, NilClass], default: nil -attribute :master_use_gtid, kind_of: String, default: 'no' diff --git a/cookbooks/mariadb/templates/default/conf.d.generic.erb b/cookbooks/mariadb/templates/default/conf.d.generic.erb deleted file mode 100644 index 56af4e1..0000000 --- a/cookbooks/mariadb/templates/default/conf.d.generic.erb +++ /dev/null @@ -1,19 +0,0 @@ -# DEPLOYED BY CHEF -[<%= @section -%>] -<% @options.each do | option_name, option_value |-%> - <% if option_value.to_s == 'true' -%> -<%= option_name %> - <% else -%> - <% if option_value.kind_of?(String) && option_value.start_with?('#') -%> -<%= option_value %> - <% else -%> - <% if option_value.kind_of?(Array) -%> - <% option_value.each do | option_value_array_value | -%> -<%= option_name -%> = <%= option_value_array_value %> - <% end -%> - <% else -%> -<%= option_name -%> = <%= option_value %> - <% end -%> - <% end -%> - <% end -%> -<% end -%> diff --git a/cookbooks/mariadb/templates/default/debian.cnf.erb b/cookbooks/mariadb/templates/default/debian.cnf.erb deleted file mode 100644 index b7fb3f6..0000000 --- a/cookbooks/mariadb/templates/default/debian.cnf.erb +++ /dev/null @@ -1,12 +0,0 @@ -# Automatically generated for Debian scripts (Managed by CHEF). DO NOT TOUCH! -[client] -host = <%= node['mariadb']['debian']['host'] %> -user = <%= node['mariadb']['debian']['user'] %> -password = <%= node['mariadb']['debian']['password'] %> -socket = <%= node['mariadb']['client']['socket'] %> -[mysql_upgrade] -host = <%= node['mariadb']['debian']['host'] %> -user = <%= node['mariadb']['debian']['user'] %> -password = <%= node['mariadb']['debian']['password'] %> -socket = <%= node['mariadb']['mysqld_safe']['socket'] %> -basedir = <%= node['mariadb']['mysqld']['basedir'] %> diff --git a/cookbooks/mariadb/templates/default/mariadb-server.seed.erb b/cookbooks/mariadb/templates/default/mariadb-server.seed.erb deleted file mode 100644 index eddb939..0000000 --- a/cookbooks/mariadb/templates/default/mariadb-server.seed.erb +++ /dev/null @@ -1,13 +0,0 @@ -<% -# Value obtained via the debconf-get-selections tool on debian wheezy -pack_w_version = @package_name + '-' + node['mariadb']['install']['version'] --%> -<%= pack_w_version %> mysql-server/root_password_again select <%= node['mariadb']['server_root_password'] %> -<%= pack_w_version %> mysql-server/root_password select <%= node['mariadb']['server_root_password'] %> -<%= pack_w_version %> mysql-server/error_setting_password boolean false -<%= pack_w_version %> mysql-server-5.1/nis_warning note -<%= pack_w_version %> mysql-server-5.1/start_on_boot boolean true -<%= pack_w_version %> <%= pack_w_version %>/really_downgrade boolean false -<%= pack_w_version %> mysql-server-5.1/postrm_remove_databases boolean false -<%= pack_w_version %> mysql-server/password_mismatch boolean false -<%= pack_w_version %> mysql-server/no_upgrade_when_using_ndb boolean true diff --git a/cookbooks/mariadb/templates/default/mariadb_grants.erb b/cookbooks/mariadb/templates/default/mariadb_grants.erb deleted file mode 100644 index 6eda39d..0000000 --- a/cookbooks/mariadb/templates/default/mariadb_grants.erb +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -# Generated by CHEF -# Local modification will be overriden - -<% if node['mariadb']['allow_root_pass_change'] -%> -<% if node['mariadb']['server_root_password'].empty? -%> -/usr/bin/mysqladmin -u root password "$1" -<% else -%> -/usr/bin/mysqladmin -u root -p'<%= node['mariadb']['server_root_password'] %>' password "$1" -<% end -%> - -<% end -%> -password_flag="" -if [ "$1" ]; then - password_flag="-p$1" -fi - -<% if node['mariadb']['forbid_remote_root'] -%> -user_exist=`/usr/bin/mysql -u root ${password_flag} -D mysql -r -B -N -e "SELECT user from user where user = 'root' and host = '%'"` -if [ $user_exist == 'root' ]; then - /bin/echo "DROP USER 'root'@'%';" | /usr/bin/mysql -u root ${password_flag} -fi -<% else -%> -/bin/echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '<%= node['mariadb']['server_root_password'] %>' WITH GRANT OPTION;" | /usr/bin/mysql -u root ${password_flag} -<% end -%> diff --git a/cookbooks/mariadb/templates/default/my.cnf.erb b/cookbooks/mariadb/templates/default/my.cnf.erb deleted file mode 100644 index 4b78c25..0000000 --- a/cookbooks/mariadb/templates/default/my.cnf.erb +++ /dev/null @@ -1,191 +0,0 @@ -# DEPLOYED BY CHEF -# MariaDB database server configuration file. -# -# You can copy this file to one of: -# - "/etc/mysql/my.cnf" to set global options, -# - "~/.my.cnf" to set user-specific options. -# -# One can use all long options that the program supports. -# Run program with --help to get a list of available options and with -# --print-defaults to see which it would actually understand and use. -# -# For explanations see -# http://dev.mysql.com/doc/mysql/en/server-system-variables.html - -# This will be passed to all mysql clients -# It has been reported that passwords should be enclosed with ticks/quotes -# escpecially if they contain "#" chars... -# Remember to edit /etc/mysql/debian.cnf when changing the socket location. -[client] -port = <%= node['mariadb']['client']['port'] %> -socket = <%= node['mariadb']['client']['socket'] %> -<% if node['mariadb']['client'].attribute?('host') && !node['mariadb']['client']['host'].nil? %> -host = <%= node['mariadb']['client']['host'] %> -<% end %> - -# Here is entries for some specific programs -# The following values assume you have at least 32M ram - -# This was formally known as [safe_mysqld]. Both versions are currently parsed. -[mysqld_safe] -socket = <%= node['mariadb']['mysqld_safe']['socket'] %> -nice = 0 - -[mysqld] -# -# * Basic Settings -# -user = <%= node['mariadb']['mysqld']['user'] %> -<% if node['mariadb']['mysqld'].attribute?('pid_file') %> -pid-file = <%= node['mariadb']['mysqld']['pid_file'] %> -<% end %> -socket = <%= node['mariadb']['mysqld']['socket'] %> -port = <%= node['mariadb']['mysqld']['port'] %> -basedir = <%= node['mariadb']['mysqld']['basedir'] %> -datadir = <%= node['mariadb']['mysqld']['default_datadir'] %> -tmpdir = <%= node['mariadb']['mysqld']['tmpdir'] %> -lc_messages_dir = <%= node['mariadb']['mysqld']['lc_messages_dir'] %> -lc_messages = <%= node['mariadb']['mysqld']['lc_messages'] %> -<% if node['mariadb']['mysqld']['skip_external_locking'] == 'true' -%> -skip-external-locking -<% end -%> -# -# Instead of skip-networking the default is now to listen only on -# localhost which is more compatible and is not less secure. -<% unless node['mariadb']['mysqld']['bind_address'].nil? or node['mariadb']['mysqld']['bind_address'].empty? -%> -bind-address = <%= node['mariadb']['mysqld']['bind_address'] %> -<% end -%> -# -# * Fine Tuning -# -max_connections = <%= node['mariadb']['mysqld']['max_connections'] %> -connect_timeout = <%= node['mariadb']['mysqld']['connect_timeout'] %> -wait_timeout = <%= node['mariadb']['mysqld']['wait_timeout'] %> -max_allowed_packet = <%= node['mariadb']['mysqld']['max_allowed_packet'] %> -thread_cache_size = <%= node['mariadb']['mysqld']['thread_cache_size'] %> -sort_buffer_size = <%= node['mariadb']['mysqld']['sort_buffer_size'] %> -bulk_insert_buffer_size = <%= node['mariadb']['mysqld']['bulk_insert_buffer_size'] %> -tmp_table_size = <%= node['mariadb']['mysqld']['tmp_table_size'] %> -max_heap_table_size = <%= node['mariadb']['mysqld']['max_heap_table_size'] %> -# -# * MyISAM -# -# This replaces the startup script and checks MyISAM tables if needed -# the first time they are touched. On error, make copy and try a repair. -myisam_recover = <%= node['mariadb']['mysqld']['myisam_recover'] %> -key_buffer_size = <%= node['mariadb']['mysqld']['key_buffer_size'] %> -<% if node['mariadb']['mysqld']['open_files_limit'].empty? -%> -#open-files-limit = 2000 -<% else -%> -open-files-limit = <%= node['mariadb']['mysqld']['open_files_limit'] %> -<% end -%> -table_open_cache = <%= node['mariadb']['mysqld']['table_open_cache'] %> -myisam_sort_buffer_size = <%= node['mariadb']['mysqld']['myisam_sort_buffer_size'] %> -concurrent_insert = <%= node['mariadb']['mysqld']['concurrent_insert'] %> -read_buffer_size = <%= node['mariadb']['mysqld']['read_buffer_size'] %> -read_rnd_buffer_size = <%= node['mariadb']['mysqld']['read_rnd_buffer_size'] %> -# -# * Query Cache Configuration -# -# Cache only tiny result sets, so we can fit more in the query cache. -query_cache_limit = <%= node['mariadb']['mysqld']['query_cache_limit'] %> -query_cache_size = <%= node['mariadb']['mysqld']['query_cache_size'] %> -# for more write intensive setups, set to DEMAND or OFF -<% if node['mariadb']['mysqld']['query_cache_type'].empty? -%> -#query_cache_type = DEMAND -<% else -%> -query_cache_type = <%= node['mariadb']['mysqld']['query_cache_type'] %> -<% end -%> -# -# * Logging and Replication -# -# Both location gets rotated by the cronjob. -# Be aware that this log type is a performance killer. -# As of 5.1 you can enable the log at runtime! -#general_log_file = /var/log/mysql/mysql.log -#general_log = 1 -# -# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf. -# -# we do want to know about network errors and such -log_warnings = 2 -# -# Enable the slow query log to see queries with especially long duration -#slow_query_log[={0|1}] -slow_query_log_file = /var/log/mysql/mariadb-slow.log -long_query_time = 10 -#log_slow_rate_limit = 1000 -log_slow_verbosity = query_plan - -#log-queries-not-using-indexes -#log_slow_admin_statements -# -# The following can be used as easy to replay backup logs or for replication. -# note: if you are setting up a replication slave, see README.Debian about -# other settings you may need to change. -#report_host = master1 -#auto_increment_increment = 2 -#auto_increment_offset = 1 -# not fab for performance, but safer -#sync_binlog = 1 -# slaves -#relay_log = /var/log/mysql/relay-bin -#relay_log_index = /var/log/mysql/relay-bin.index -#relay_log_info_file = /var/log/mysql/relay-bin.info -#log_slave_updates -#read_only -# -# If applications support it, this stricter sql_mode prevents some -# mistakes like inserting invalid dates etc. -#sql_mode = NO_ENGINE_SUBSTITUTION,TRADITIONAL - -default_storage_engine = <%= node['mariadb']['mysqld']['default_storage_engine'] %> - -# -# * Security Features -# -# Read the manual, too, if you want chroot! -# chroot = /var/lib/mysql/ -# -# For generating SSL certificates I recommend the OpenSSL GUI "tinyca". -# -# ssl-ca=/etc/mysql/cacert.pem -# ssl-cert=/etc/mysql/server-cert.pem -# ssl-key=/etc/mysql/server-key.pem - -<% if node['mariadb']['mysqld'].key?('options') -%> -<% node['mariadb']['mysqld']['options'].each { |key, value| -%> -<%= key %> = <%= value %> -<% } -%> -<% end -%> - -# -# * Plugins Options -# -<% plugin_load = [] -%> -<% node['mariadb']['plugins_loading'].each { |plugin, loading| -%> - <% plugin_load.push(loading) if node['mariadb']['plugins'][plugin] %> -<% } -%> -plugin-load = <%= plugin_load.join(';') %> - -[mysqldump] -<% if node['mariadb']['mysqldump']['quick'].empty? -%> -quick -<% end -%> -<% if node['mariadb']['mysqldump']['quote_names'].empty? -%> -quote-names -<% end -%> -max_allowed_packet = <%= node['mariadb']['mysqldump']['max_allowed_packet'] %> - -[mysql] -#no-auto-rehash # faster start of mysql but no tab completition - -[isamchk] -key_buffer = <%= node['mariadb']['isamchk']['key_buffer'] %> - -# -# * IMPORTANT: Additional settings that can override those from this file! -# The files must end with '.cnf', otherwise they'll be ignored. -# -!includedir <%= node['mariadb']['configuration']['includedir'] %>/ - diff --git a/cookbooks/yum/CHANGELOG.md b/cookbooks/yum/CHANGELOG.md deleted file mode 100644 index 38ea170..0000000 --- a/cookbooks/yum/CHANGELOG.md +++ /dev/null @@ -1,391 +0,0 @@ -# yum Cookbook CHANGELOG - -This file is used to list changes made in each version of the yum cookbook. - -## 7.2.0 - *2021-09-29* - -- Add `dnf_module` resource for managing DNF modules on RHEL 8+ / Fedora - -## 7.1.0 - *2021-08-29* - -- Add support for DNF (Yum v4) property `install_weak_deps` (#193) - -## 7.0.1 - *2021-08-26* - -- Standardise files with files in sous-chefs/repo-management (#191) - -## 7.0.0 - *2021-08-13* - -- Enable `unified_mode` for Chef 17 compatibility -- Remove deprecated `dnf_yum_compat` recipe - -## 6.1.1 - *2021-06-01* - -## 6.1.0 - *2021-03-24* - -- complete ip_resolve additions started in 6.0.0 - -## 6.0.0 - *2021-01-20* - -- Sous Chefs Adoption -- Cookstyle fixes -- Various testing fixes -- Standardise files with files in sous-chefs/repo-management -- Adding proper distroverpkg assignment for Oracle Linux -- Require 13+ -- Remove RHEL5 references -- Mark `dnf_yum_compat` recipe deprecated -- Add EL8 support - -## 5.1.0 (2017-08-04) - -- Avoid spec deprecation warnings -- Use an empty string `releasever` to lock an Amazon Linux AMI to its current verison - -## 5.0.1 (2017-04-06) - -- Switch from Rake testing to Local Delivery -- Rename kitchen-docker to kitchen-dokken -- Update apache2 license string -- use true/false vs. TrueClass and FalseClass in the resource - -## 5.0.0 (2017-02-12) - -### Breaking changes - -- Removed the yum_repository resource and instead require chef-client 12.14 or later, which has the yum repository functionality built in. This resolves Chef 13 compatibility warnings for any cookbook with the yum cookbook. - -### Other changes - -- Convert yum_globalconfig from an LWRP to a custom resource - -## 4.2.0 (2017-02-12) - -- Make cache in the DNF compat recipe -- Fix `fastestmirror_enabled`. -- Require Chef 12.1 not 12.0 -- Convert to Inspec - -## 4.1.0 (2016-10-21) - -- Purge yum cache before removing a repo not after - -## 4.0.0 (2016-09-06) - -- Remove support for Chef 11 - -## 3.13.0 (2016-09-06) - -- Add deprecation warning for add/remove actions, which were replaced with create/delete in Yum 3.0 -- Remove support for Chef 10 - -## v3.12.0 (2016-08-25) - -- Fixing baseurl to support multiple urls -- Modify releasever attribute for Amazon to match Amazon's default policy for releasever - -## v3.11.0 (2016-06-01) - -- Install yum at compile time in the dnf compatibility recipe -- Add IBM zlinux as a supported platform in the metadata -- Use cookstyle instead of rubocop to provide a consistent linting experience - -## v3.10.0 (2016-02-04) - -- Add a new sensitive attribute to the repository resource so prevent writing the diff of the config to Chef output / logs -- Update testing dependencies and remove the Guardfile / Guard dependencies - -## v3.9.0 (2016-01-14) - -- Added dnf_yum_compat recipe to ensure yum is installed on Fedora systems for Chef package resource compatibility. This will no longer be necessary when native dnf package support ships in chef-client. - -## v3.8.2 (2015-10-28) - -- # 141 - Replace clean_headers with clean_metadata - -## v3.8.1 (2015-10-28) - -- Fixing up Chef13 deprecation warnings - -## v3.8.0 (2015-10-13) - -- adding clean_headers boolean property to yum_resource -- restoring Chef 10 backwards compat for the sake of ChefSpec -- (unique resource names needed to avoid cloning) -- Fixing localpkg_gpgcheck values - -## v3.7.1 (2015-09-08) - -- # 135 - reverting "yum clean headers" as it breaks dnf compat - -## v3.7.0 (2015-09-05) - -- Adding deltarpm toggle -- Cleaning 'headers' rather than 'all' - -## v3.6.3 (2015-07-13) - -- Normalizing sslverify option rendering behavior -- Setting default value on the resource to nil -- Explictly setting string to render in template if value is supplied -- Behavior should default to "True", per man page - -## v3.6.2 (2015-07-13) - -- Adding -y to makecache, to import key when repo_gpgcheck = true. -- Accepting Integer value for max_retries - -## v3.6.1 (2015-06-04) - -- Executing yum clean before makecache -- Adding repo_gpgcheck - -## v3.6.0 (2015-04-23) - -- Adding "yum clean" before "yum makecache" in yum_repository :create -- Adding why_run support to yum_globalconfig - -## v3.5.4 (2015-04-07) - -- Changing tolerant config line to stringified integer - -## v3.5.3 (2015-01-16) - -- Adding reposdir to globalconfig template - -## v3.5.2 (2014-12-24) - -- Fixing redhat-release detection for Redhat 7 - -## v3.5.1 (2014-11-24) - -- Reverting management of ca-certificates because EL5 was broken - -## v3.5.0 (2014-11-24) - -- Adding management of ca-certificates package to yum_repository provider - -## v3.4.1 (2014-10-29) - -- Run yum-makecache only_if new_resource.enabled -- Allow setting of reposdir in global yum config and man page -- Change default 'obsoletes' behavior to match yum defaults - -## v3.4.0 (2014-10-15) - -- Dynamically generate the new_resource attributes - -## v3.3.2 (2014-09-11) - -- Fix globalconfig resource param for http_caching - -## v3.3.1 (2014-09-04) - -- Fix issue with sslverify if set to false -- Add fancy badges - -## v3.3.0 (2014-09-03) - -- Adding tuning attributes for all supported resource parameters -- Adding options hash parameter -- Adding (real) rhel-6.5 and centos-7.0 to test-kitchen coverage -- Updating regex for mirror_expire and mirrorlist_expire to include /^\d+[mhd]$/ -- Updating README so keepcache reflects reality (defaults to false) -- Changing 'obsoletes' behavior in globalconfig resource to match -- default behavior. (now defaults to nil, yum defaults to false) -- Adding makecache action to repository resource -- Adding mode parameter to repository resource. Defaults to '0644'. - -## v3.2.4 (2014-08-20) - -- # 82 - Adding a makecache parameter - -## v3.2.2 (2014-06-11) - -- # 77 - Parameter default to be Trueclass instead of "1" - -- # 78 - add releasever parameter - -## v3.2.0 (2014-04-09) - -- [COOK-4510] - Adding username and password parameters to node attributes -- [COOK-4518] - Fix Scientific Linux distroverpkg - -## v3.1.6 (2014-03-27) - -- [COOK-4463] - support multiple GPG keys -- [COOK-4364] - yum_repository delete action fails - -## v3.1.4 (2014-03-12) - -- [COOK-4417] Expand test harness to encompass 32-bit boxes - -## v3.1.2 (2014-02-23) - -Fixing bugs around :delete action and cache clean Fixing specs to cover :remove and :delete aliasing properly Adding Travis-ci build matrix bits - -## v3.1.0 (2014-02-13) - -- Updating testing harness for integration testing on Travis-ci -- Adding TESTING.md and Guardfile -- PR #67 - Add skip_if_unvailable repository option -- PR #64 - Fix validation of 'metadata_expire' option to match documentation -- [COOK-3591] - removing node.name from repo template rendering -- [COOK-4275] - Enhancements to yum cookbook -- Adding full spec coverage -- Adding support for custom source template to yum_repository - -## v3.0.8 (2014-01-27) - -Fixing typo in default.rb. yum_globalconfig now passes proxy attribute correctly. - -## v3.0.6 (2014-01-27) - -Updating default.rb to consume node['yum']['main']['proxy'] - -## v3.0.4 (2013-12-29) - -### Bug - -- **[COOK-4156](https://tickets.chef.io/browse/COOK-4156)** - yum cookbook creates a yum.conf with "cachefir" directive - -## v3.0.2 - -Updating globalconfig provider for Chef 10 compatability - -## v3.0.0 - -3.0.0 Major rewrite with breaking changes. Recipes broken out into individual cookbooks yum_key resource has been removed yum_repository resource now takes gpgkey as a URL directly yum_repository actions have been reduced to :create and :delete 'name' has been changed to repositoryid to avoid ambiguity chefspec test coverage gpgcheck is set to 'true' by default and must be explicitly disabled - -## v2.4.4 - -Reverting to Ruby 1.8 hash syntax. - -## v2.4.2 - -[COOK-3275] LWRP repository.rb :add method fails to create yum repo in some cases which causes :update to fail Amazon rhel - -## v2.4.0 - -### Improvement - -- [COOK-3025] - Allow per-repo proxy definitions - -## v2.3.4 - -### Improvement - -- **[COOK-3689](https://tickets.chef.io/browse/COOK-3689)** - Fix warnings about resource cloning -- **[COOK-3574](https://tickets.chef.io/browse/COOK-3574)** - Add missing "description" field in metadata - -## v2.3.2 - -### Bug - -- **[COOK-3145](https://tickets.chef.io/browse/COOK-3145)** - Use correct download URL for epel `key_url` - -## v2.3.0 - -### New Feature - -- [COOK-2924]: Yum should allow type setting in repo file - -## v2.2.4 - -### Bug - -- [COOK-2360]: last commit to `yum_repository` changes previous behaviour -- [COOK-3015]: Yum cookbook test minitest to fail - -## v2.2.2 - -### Improvement - -- [COOK-2741]: yum::elrepo -- [COOK-2946]: update tests, test kitchen support in yum cookbook - -### Bug - -- [COOK-2639]: Yum cookbook - epel - always assumes url is a mirror list -- [COOK-2663]: Yum should allow metadata_expire setting in repo file -- [COOK-2751]: Update yum.ius_release version to 1.0-11 - -## v2.2.0 - -- [COOK-2189] - yum::ius failed on install (caused from rpm dependency) -- [COOK-2196] - Make includepkgs and exclude configurable for each repos -- [COOK-2244] - Allow configuring caching using attributes -- [COOK-2399] - yum cookbook LWRPs fail FoodCritic -- [COOK-2519] - Add priority option to Yum repo files -- [COOK-2593] - allow integer or string for yum priority -- [COOK-2643] - don't use conditional attribute for `yum_key` `remote_file` - -## v2.1.0 - -- [COOK-2045] - add remi repository recipe -- [COOK-2121] - add `:create` action to `yum_repository` - -## v2.0.6 - -- [COOK-2037] - minor style fixes -- [COOK-2038] - updated README - -## v2.0.4 - -- [COOK-1908] - unable to install repoforge on CentOS 6 32 bit - -## v2.0.2 - -- [COOK-1758] - Add default action for repository resource - -## v2.0.0 - -This version changes the behavior of the EPEL recipe (most commonly used in other Chef cookbooks) on Amazon, and removes an attribute, `node['yum']['epel_release']`. See the README for details. - -- [COOK-1772] - Simplify management of EPEL with LWRP - -## v1.0.0 - -`mirrorlist` in the `yum_repository` LWRP must be set to the mirror list URI to use rather than setting it to true. See README.md. - -- [COOK-1088] - use dl.fedoraproject.org for EPEL to prevent redirects -- [COOK-1653] - fix mirrorlist -- [COOK-1710] - support http proxy -- [COOK-1722] - update IUS version - -## v0.8.2 - -- [COOK-1521] - add :update action to `yum_repository` - -## v0.8.0 - -- [COOK-1204] - Make 'add' default action for yum_repository -- [COOK-1351] - option to not make the yum cache (via attribute) -- [COOK-1353] - x86_64 centos path fixes -- [COOK-1414] - recipe for repoforge - -## v0.6.2 - -- Updated README to remove git diff artifacts. - -## v0.6.0 - -- Default action for the yum_repository LWRP is now add. -- [COOK-1227] - clear Chefs internal cache after adding new yum repo -- [COOK-1262] - yum::epel should enable existing repo on Amazon Linux -- [COOK-1272], [COOK-1302] - update RPM file for CentOS / RHEL 6 -- [COOK-1330] - update cookbook documentation on excludes for yum -- [COOK-1346] - retry remote_file for EPEL in case we get an FTP mirror - -## v0.5.2 - -- [COOK-825] - epel and ius `remote_file` should notify the `rpm_package` to install - -## v0.5.0 - -- [COOK-675] - add recipe for handling EPEL repository -- [COOK-722] - add recipe for handling IUS repository - -## v.0.1.2 - -- Remove yum update in default recipe, that doesn't update caches, it updates packages installed. diff --git a/cookbooks/yum/README.md b/cookbooks/yum/README.md deleted file mode 100644 index 1c8ebc3..0000000 --- a/cookbooks/yum/README.md +++ /dev/null @@ -1,109 +0,0 @@ -# yum Cookbook - -[![Cookbook Version](https://img.shields.io/cookbook/v/yum.svg)](https://supermarket.chef.io/cookbooks/yum) -[![CI State](https://github.com/sous-chefs/yum/workflows/ci/badge.svg)](https://github.com/sous-chefs/yum/actions?query=workflow%3Aci) -[![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers) -[![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) -[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) - -The Yum cookbook exposes the `yum_globalconfig` resource which allows a user to control global yum behavior. This resources aims to allow the user to configure all options listed in the `yum.conf` man page, found at - -## Maintainers - -This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit [sous-chefs.org](https://sous-chefs.org/) or come chat with us on the Chef Community Slack in [#sous-chefs](https://chefcommunity.slack.com/messages/C2V7B88SF). - -## Requirements - -### Platforms - -- RHEL/CentOS and derivatives -- Fedora - -### Chef - -- Chef 15.3+ - -### Cookbooks - -- none - -## Resources - -- [`yum_globalconfig`](documentation/yum_globalconfig.md) -- [`dnf_module`](documentation/dnf_module.md) - -## Recipes (deprecated) - -- `default` - Configures `yum_globalconfig[/etc/yum.conf]` with values found in node attributes at `node['yum']['main']` - -## Attributes - -The following attributes are set by default - -```ruby -default['yum']['main']['cachedir'] = '/var/cache/yum/$basearch/$releasever' -default['yum']['main']['keepcache'] = false -default['yum']['main']['debuglevel'] = nil -default['yum']['main']['exclude'] = nil -default['yum']['main']['logfile'] = '/var/log/yum.log' -default['yum']['main']['exactarch'] = nil -default['yum']['main']['obsoletes'] = nil -default['yum']['main']['installonly_limit'] = nil -default['yum']['main']['installonlypkgs'] = nil -default['yum']['main']['installroot'] = nil -``` - -For Amazon platform nodes, the default is to receive a continuous flow of updates, - -```ruby -default['yum']['main']['releasever'] = 'latest' -``` - -To lock existing instances to the current version of the Amazon AMI, - -```ruby -default['yum']['main']['releasever'] = '' -``` - -## Related Cookbooks - -Recipes from older versions of this cookbook have been moved individual cookbooks. Recipes for managing platform yum configurations and installing specific repositories can be found in one (or more!) of the following cookbook. - -- yum-centos -- yum-fedora -- yum-amazon -- yum-epel -- yum-elrepo -- yum-repoforge -- yum-ius -- yum-percona -- yum-pgdg - -## Usage - -Put `depends 'yum'` in your metadata.rb to gain access to the yum_repository resource. - -## Contributors - -This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) - -### Backers - -Thank you to all our backers! - -![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40) - -### Sponsors - -Support this project by becoming a sponsor. Your logo will show up here with a link to your website. - -![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100) diff --git a/cookbooks/yum/attributes/main.rb b/cookbooks/yum/attributes/main.rb deleted file mode 100644 index 3592fb8..0000000 --- a/cookbooks/yum/attributes/main.rb +++ /dev/null @@ -1,97 +0,0 @@ -# http://man7.org/linux/man-pages/man5/yum.conf.5.html - -default['yum']['main']['cachedir'] = '/var/cache/yum/$basearch/$releasever' -default['yum']['main']['distroverpkg'] = case node['platform'] - when 'amazon' - 'system-release' - when 'scientific' - 'sl-release' - when 'redhat' - nil - when 'oracle' - 'oraclelinux-release' - else - "#{node['platform']}-release" - end -default['yum']['main']['releasever'] = 'latest' if platform?('amazon') -default['yum']['main']['alwaysprompt'] = nil # [true, false] -default['yum']['main']['assumeyes'] = nil # [true, false] -default['yum']['main']['bandwidth'] = nil # /^\d+$/ -default['yum']['main']['bugtracker_url'] = nil -default['yum']['main']['clean_requirements_on_remove'] = nil # [true, false] -default['yum']['main']['color'] = nil # %w{ always never } -default['yum']['main']['color_list_available_downgrade'] = nil -default['yum']['main']['color_list_available_install'] = nil -default['yum']['main']['color_list_available_reinstall'] = nil -default['yum']['main']['color_list_available_upgrade'] = nil -default['yum']['main']['color_list_installed_extra'] = nil -default['yum']['main']['color_list_installed_newer'] = nil -default['yum']['main']['color_list_installed_older'] = nil -default['yum']['main']['color_list_installed_reinstall'] = nil -default['yum']['main']['color_search_match'] = nil -default['yum']['main']['color_update_installed'] = nil -default['yum']['main']['color_update_local'] = nil -default['yum']['main']['color_update_remote'] = nil -default['yum']['main']['commands'] = nil -default['yum']['main']['deltarpm'] = nil # [true, false] -default['yum']['main']['debuglevel'] = nil # /^\d+$/ -default['yum']['main']['diskspacecheck'] = nil # [true, false] -default['yum']['main']['enable_group_conditionals'] = nil # [true, false] -default['yum']['main']['errorlevel'] = nil # /^\d+$/ -default['yum']['main']['exactarch'] = nil # [true, false] -default['yum']['main']['exclude'] = nil -default['yum']['main']['gpgcheck'] = true # [true, false] -default['yum']['main']['group_package_types'] = nil -default['yum']['main']['groupremove_leaf_only'] = nil # [true, false] -default['yum']['main']['history_list_view'] = nil -default['yum']['main']['history_record'] = nil # [true, false] -default['yum']['main']['history_record_packages'] = nil -default['yum']['main']['http_caching'] = nil # %w{ packages all none } -default['yum']['main']['ip_resolve'] = nil # %w{ 4 6 } -default['yum']['main']['installonly_limit'] = nil # /\d+/, /keep/ -default['yum']['main']['installonlypkgs'] = nil -default['yum']['main']['installroot'] = nil -default['yum']['main']['keepalive'] = nil # [true, false] -default['yum']['main']['keepcache'] = false # [true, false] -default['yum']['main']['kernelpkgnames'] = nil -default['yum']['main']['localpkg_gpgcheck'] = false # [true,# false] -default['yum']['main']['logfile'] = '/var/log/yum.log' -default['yum']['main']['max_retries'] = nil # /^\d+$/ -default['yum']['main']['mdpolicy'] = nil # %w{ packages all none } -default['yum']['main']['metadata_expire'] = nil # /^\d+$/ -default['yum']['main']['mirrorlist_expire'] = nil # /^\d+$/ -default['yum']['main']['multilib_policy'] = nil # %w{ all best } -default['yum']['main']['obsoletes'] = nil # [true, false] -default['yum']['main']['overwrite_groups'] = nil # [true, false] -default['yum']['main']['password'] = nil -default['yum']['main']['path'] = '/etc/yum.conf' -default['yum']['main']['persistdir'] = nil -default['yum']['main']['pluginconfpath'] = nil -default['yum']['main']['pluginpath'] = nil -default['yum']['main']['plugins'] = nil # [true, false] -default['yum']['main']['protected_multilib'] = nil -default['yum']['main']['protected_packages'] = nil -default['yum']['main']['proxy'] = nil -default['yum']['main']['proxy_password'] = nil -default['yum']['main']['proxy_username'] = nil -default['yum']['main']['password'] = nil -default['yum']['main']['recent'] = nil # /^\d+$/ -default['yum']['main']['repo_gpgcheck'] = nil # [true, false] -default['yum']['main']['reposdir'] = nil -default['yum']['main']['reset_nice'] = nil # [true, false] -default['yum']['main']['rpmverbosity'] = nil # %w{ info critical# emergency error warn debug } -default['yum']['main']['showdupesfromrepos'] = nil # [true, false] -default['yum']['main']['skip_broken'] = nil # [true, false] -default['yum']['main']['ssl_check_cert_permissions'] = nil # [true, false] -default['yum']['main']['sslcacert'] = nil -default['yum']['main']['sslclientcert'] = nil -default['yum']['main']['sslclientkey'] = nil -default['yum']['main']['sslverify'] = nil # [true, false] -default['yum']['main']['syslog_device'] = nil -default['yum']['main']['syslog_facility'] = nil -default['yum']['main']['syslog_ident'] = nil -default['yum']['main']['throttle'] = nil # [/\d+k/, /\d+M/, /\d+G/] -default['yum']['main']['timeout'] = nil # /\d+/ -default['yum']['main']['tolerant'] = false -default['yum']['main']['tsflags'] = nil -default['yum']['main']['username'] = nil diff --git a/cookbooks/yum/kitchen.dokken.yml b/cookbooks/yum/kitchen.dokken.yml deleted file mode 100644 index 9d2678f..0000000 --- a/cookbooks/yum/kitchen.dokken.yml +++ /dev/null @@ -1,48 +0,0 @@ ---- -driver: - name: dokken - privileged: true # because Docker and SystemD/Upstart - -transport: - name: dokken - -provisioner: - name: dokken - chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> - chef_license: accept-no-persist - -platforms: - - name: amazonlinux-2 - driver: - image: dokken/amazonlinux-2 - pid_one_command: /usr/lib/systemd/systemd - - - name: centos-7 - driver: - image: dokken/centos-7 - pid_one_command: /usr/lib/systemd/systemd - - - name: centos-8 - driver: - image: dokken/centos-8 - pid_one_command: /usr/lib/systemd/systemd - - - name: centos-stream-8 - driver: - image: dokken/centos-stream-8 - pid_one_command: /usr/lib/systemd/systemd - - - name: oraclelinux-7 - driver: - image: dokken/oraclelinux-7 - pid_one_command: /usr/lib/systemd/systemd - - - name: oraclelinux-8 - driver: - image: dokken/oraclelinux-8 - pid_one_command: /usr/lib/systemd/systemd - - - name: fedora-latest - driver: - image: dokken/fedora-latest - pid_one_command: /usr/lib/systemd/systemd diff --git a/cookbooks/yum/metadata.json b/cookbooks/yum/metadata.json deleted file mode 100644 index c2b9d36..0000000 --- a/cookbooks/yum/metadata.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "yum", - "description": "Configures various yum components on Red Hat-like systems", - "long_description": "", - "maintainer": "Sous Chefs", - "maintainer_email": "help@sous-chefs.org", - "license": "Apache-2.0", - "platforms": { - "amazon": ">= 0.0.0", - "centos": ">= 0.0.0", - "fedora": ">= 0.0.0", - "oracle": ">= 0.0.0", - "redhat": ">= 0.0.0", - "scientific": ">= 0.0.0", - "zlinux": ">= 0.0.0" - }, - "dependencies": { - - }, - "providing": { - - }, - "recipes": { - - }, - "version": "7.2.0", - "source_url": "https://github.com/sous-chefs/yum", - "issues_url": "https://github.com/sous-chefs/yum/issues", - "privacy": false, - "chef_versions": [ - [ - ">= 15.3" - ] - ], - "ohai_versions": [ - - ], - "gems": [ - - ], - "eager_load_libraries": true -} diff --git a/cookbooks/yum/metadata.rb b/cookbooks/yum/metadata.rb deleted file mode 100644 index 4f6c382..0000000 --- a/cookbooks/yum/metadata.rb +++ /dev/null @@ -1,17 +0,0 @@ -name 'yum' -maintainer 'Sous Chefs' -maintainer_email 'help@sous-chefs.org' -license 'Apache-2.0' -description 'Configures various yum components on Red Hat-like systems' -version '7.2.0' -source_url 'https://github.com/sous-chefs/yum' -issues_url 'https://github.com/sous-chefs/yum/issues' -chef_version '>= 15.3' - -supports 'amazon' -supports 'centos' -supports 'fedora' -supports 'oracle' -supports 'redhat' -supports 'scientific' -supports 'zlinux' diff --git a/cookbooks/yum/recipes/default.rb b/cookbooks/yum/recipes/default.rb deleted file mode 100644 index 76cd2b0..0000000 --- a/cookbooks/yum/recipes/default.rb +++ /dev/null @@ -1,26 +0,0 @@ -# -# Author:: Sean OMeara () -# Author:: Joshua Timberman () -# Recipe:: yum::default -# -# Copyright:: 2013-2019, 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. - -yum_globalconfig '/etc/yum.conf' do - node['yum']['main'].each do |config, value| - send(config.to_sym, value) unless value.nil? - end - - action :create -end diff --git a/cookbooks/yum/resources/dnf_module.rb b/cookbooks/yum/resources/dnf_module.rb deleted file mode 100644 index e256d32..0000000 --- a/cookbooks/yum/resources/dnf_module.rb +++ /dev/null @@ -1,104 +0,0 @@ -resource_name :dnf_module -provides :dnf_module - -unified_mode true - -property :module_name, String, - name_property: true, - description: 'Name of the module to install' - -property :options, [String, Array], - coerce: proc { |x| Array(x) }, - default: [], - description: 'Any additional options to pass to DNF' - -action_class do - def supported? - (platform_family?('rhel') && node['platform_version'] >= 8) || platform?('fedora') - end - - def list_modules(type) - raw_output = shell_out!('dnf -q module list').stdout.split("\n") - raw_output.keep_if { |l| l.match? /\[#{type}\]/ } - raw_output.map { |l| "#{l.split[0]}:#{l.split[1]}" }[0..-2] # remove Hint: line from end - end - - def enabled_modules - # extract modules from the rest of the output -- the lines with [e] (for enabled) - list_modules('e') - end - - def disabled_modules - # extract modules from the rest of the output -- the lines with [x] (for disabled) - # disable disables all versions of the stream, so add entry without :version - dl = list_modules('x') - dl + dl.map { |m| m.split(':').first }.uniq - end - - def installed_modules - # extract modules from the rest of the output -- the lines with [i] (for installed) - list_modules('i') - end - - def opts - new_resource.options.join(' ') - end -end - -action :switch_to do - return unless supported? - - unless enabled_modules.include?(new_resource.module_name) - converge_by "switch to #{new_resource.module_name}" do - shell_out!("dnf -qy module switch-to #{opts} '#{new_resource.module_name}'") - end - end -end - -action :enable do - return unless supported? - - unless enabled_modules.include?(new_resource.module_name) - converge_by "enable #{new_resource.module_name}" do - shell_out!("dnf -qy module enable #{opts} '#{new_resource.module_name}'") - end - end -end - -action :disable do - return unless supported? - - unless disabled_modules.include?(new_resource.module_name) - converge_by "disable #{new_resource.module_name}" do - shell_out!("dnf -qy module disable #{opts} '#{new_resource.module_name}'") - end - end -end - -action :install do - return unless supported? - - unless installed_modules.include?(new_resource.module_name) - converge_by "install #{new_resource.module_name}" do - shell_out!("dnf -qy module install #{opts} '#{new_resource.module_name}'") - end - end -end - -action :remove do - return unless supported? - - if installed_modules.include?(new_resource.module_name) - converge_by "remove #{new_resource.module_name}" do - shell_out!("dnf -qy module remove #{opts} '#{new_resource.module_name}'") - end - end -end - -action :reset do - return unless supported? - - converge_by "reset #{new_resource.module_name}" do - shell_out!("dnf -qy module reset #{opts} '#{new_resource.module_name}'") - end -end diff --git a/cookbooks/yum/resources/globalconfig.rb b/cookbooks/yum/resources/globalconfig.rb deleted file mode 100644 index 5049e79..0000000 --- a/cookbooks/yum/resources/globalconfig.rb +++ /dev/null @@ -1,166 +0,0 @@ -# -# Cookbook:: yum -# Resource:: repository -# -# Author:: Sean OMeara -# Copyright:: 2013-2020, 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. -# - -# http://man7.org/linux/man-pages/man5/yum.conf.5.html - -unified_mode true - -property :alwaysprompt, [true, false], description: 'When true yum will not prompt for confirmation when the list of packages to be installed exactly matches those given on the command line. Unless assumeyes is enabled, it will prompt when additional packages need to be installed to fulfill dependencies regardless of this setting. Note that older versions of yum would also always prompt for package removal, and that is no longer true.' -property :assumeno, [true, false], description: "If yum would prompt for confirmation of critical actions, assume the user chose no. This is basically the same as doing 'echo | yum ...' but is a bit more usable. This option overrides assumeyes, but is still subject to alwaysprompt." -property :assumeyes, [true, false], description: 'Determines whether or not yum prompts for confirmation of critical actions.' -property :autocheck_running_kernel, [true, false], description: "Set this to false to disable the automatic checking of the running kernel against updateinfo ('yum updateinfo check-running-kernel'), in the 'check-update' and 'updateinfo summary' commands." -property :autosavets, [true, false], description: 'Should yum automatically save a transaction to a file when the transaction is solved but not run. Yum defaults to True' -property :bandwidth, String, regex: /^\d+/, description: "Use to specify the maximum available network bandwidth in bytes/second. Used with the throttle property. If throttle is a percentage and bandwidth is '0' then bandwidth throttling will be disabled. If throttle is expressed as a data rate (bytes/sec) then this option is ignored." -property :bugtracker_url, String, description: 'URL where bugs should be filed for yum. Configurable for local versions or distro-specific bugtrackers.' -property :cachedir, String, default: '/var/cache/yum/$basearch/$releasever', description: 'Directory where yum should store its cache and db files.' -property :cashe_root_dir, String, description: "Directory where yum would initialize the cashe, should almost certainly be left at the default. Yum's default is '/var/cache/CAShe'. Note that unlike all other configuration, this does not change with installroot, the reason is so that multiple install root can share the same data. See man cashe for more info." -property :check_config_file_age, [true, false], description: 'Specifies whether yum should auto metadata expire repos that are older than any of the configuration files that led to them (usually the yum.conf file and the foo.repo file).' -property :clean_requirements_on_remove, [true, false], description: "When removing packages (by removal, update or obsoletion) go through each package's dependencies. If any of them are no longer required by any other package then also mark them to be removed." -property :color, String, equal_to: %w(always never), description: 'Display colorized output automatically, depending on the output terminal' -property :color_list_available_downgrade, String -property :color_list_available_install, String -property :color_list_available_reinstall, String -property :color_list_available_upgrade, String -property :color_list_installed_extra, String -property :color_list_installed_newer, String -property :color_list_installed_older, String -property :color_list_installed_reinstall, String -property :color_search_match, String -property :color_update_installed, String -property :color_update_local, String -property :color_update_remote, String -property :commands, String, description: "List of functional commands to run if no functional commands are specified on the command line (eg. 'update foo bar baz quux'). None of the short options (eg. -y, -e, -d) are accepted for this option." -property :debuglevel, String, regex: /^\d+$/, default: '2', description: 'Debug message output level 0-10.' -property :deltarpm, [String, Integer], description: "When non-zero, delta-RPM files are used if available. The value specifies the maximum number of 'applydeltarpm' processes Yum will spawn, if the value is negative then yum works out how many cores you have and multiplies that by the value (cores=2, deltarpm=-2; 4 processes). (2 by default).\nNote that the 'applydeltarpm' process uses a significant amount of disk IO, so running too many instances can significantly slow down all disk IO including the downloads that yum is doing (thus. a too high value can make everything slower)." -property :deltarpm_metadata_percentage, String, description: "When the relative size of deltarpm metadata vs pkgs is larger than this, deltarpm metadata is not downloaded from the repo. Yum's default value is 100 (Deltarpm metadata must be smaller than the packages from the repo). Note that you can give values over 100, so 200 means that the metadata is required to be half the size of the packages. Use '0' to turn off this check, and always download metadata." -property :deltarpm_percentage, String, description: "When the relative size of delta vs pkg is larger than this, delta is not used. Yum's default value is 75 (Deltas must be at least 25% smaller than the pkg). Use '0' to turn off delta rpm processing. Local repositories (with file:// baseurl) have delta rpms turned off by default." -property :depsolve_loop_limit, Integer, description: "Set the number of times any attempt to depsolve before we just give up. This shouldn't be needed as yum should always solve or fail, however it has been observed that it can loop forever with very large system upgrades. Setting this to `0' (or " > ") makes yum try forever. Yum's default is '100'." -property :disable_excludes, [true, false], description: 'Permanently set the --disableexcludes command line option.' -property :diskspacecheck, [true, false], description: 'Set this to false to disable the checking for sufficient diskspace and inodes before a RPM transaction is run.' -property :distroverpkg, String, description: "The package used by yum to determine the 'version' of the distribution, this sets $releasever for use in config. files. This can be any installed package. Default is 'system-release(releasever)', 'redhat-release'. Yum will now look at the version provided by the provide, and if that is non-empty then will use the full V(-R), otherwise it uses the version of the package." -property :enable_group_conditionals, [true, false], description: 'Determines whether yum will allow the use of conditionals packages.' -property :errorlevel, String, regex: /^\d+$/, description: 'Error message output level 0-10.' -property :exactarch, [true, false], default: true -property :exactarchlist, String, description: "List of packages that should never change archs in an update. That means, if a package has a newer version available which is for a different compatible arch, yum will not consider that version an update if the package name is in this list. For example, on x86_64, foo-1.x86_64 won't be updated to foo-2.i686 if foo is in this list. Kernels in particular fall into this category. Shell globs using wildcards (eg. * and ?) are allowed." -property :exclude, String, description: "List of packages to exclude from all repositories, so yum works as if that package was never in the repositories. This should be a space separated list. This is commonly used so a package isn't upgraded or installed accidentally, but can be used to remove packages in any way that 'yum list' will show packages. Shell globs using wildcards (eg. * and ?) are allowed." -property :exit_on_lock, [true, false], description: 'Should the yum client exit immediately when something else has the lock. Yum defaults to false' -property :fssnap_abort_on_errors, String, equal_to: %w(), description: "When fssnap_automatic_pre or fssnap_automatic_post is enabled, it's possible to specify which fssnap errors should make the transaction fail. Yum's default is 'any'.\n'broken-setup' - Abort current transaction if snapshot support is unavailable because lvm is missing or broken.\n'snapshot-failure' - Abort current transaction if creating a snapshot fails (e.g. there is not enough free space to make a snapshot).\n'any' - Abort current transaction if any of the above occurs.\n'none' - Never abort a transaction in case of errors." -property :fssnap_automatic_keep, Integer, description: "How many old snapshots should yum keep when trying to automatically create a new snapshot. Setting to 0 disables this feature. Yum's default is '1'" -property :fssnap_automatic_post, [true, false], description: 'Should yum try to automatically create a snapshot after it runs a transaction. Yum defaults to False' -property :fssnap_automatic_pre, [true, false], description: 'Should yum try to automatically create a snapshot before it runs a transaction. Yum defaults to False' -property :fssnap_devices, String, description: 'The origin LVM devices to use for snapshots. Wildcards and negation are allowed, first match (positive or negative) wins. Default is: !*/swap !*/lv_swap glob:/etc/yum/fssnap.d/*.conf' -property :fssnap_percentage, Integer, description: "The size of new snaphosts, expressed as a percentage of the old origin device. Any number between 1 and 100. Yum defaults to '100'." -property :ftp_disable_epsv, [true, false], description: 'This options disables Extended Passive Mode (the EPSV command) which does not work correctly on some buggy ftp servers.' -property :gpgcheck, [true, false], default: true, description: 'This tells yum whether or not it should perform a GPG signature check on packages. When this is set in the [main] section it sets the default for all repositories.' -property :group_command, String, equal_to: %w(simple compat objects), description: "Tells yum what to do for group install/upgrade/remove commands.\nSimple acts like you did yum group cmd $(repoquery --group --list group), so it is very easy to reason about what will happen. Alas. this is often not what people want to happen.\nCompat. works much like simple, except that when you run 'group upgrade' it actually runs 'group install' (this means that you get any new packages added to the group, but you also get packages added that were there before and you didn't want). \nObjects makes groups act like a real object, separate from the packages they contain. Yum keeps track of the groups you have installed, so 'group upgrade' will install new packages for the group but not install old ones. It also knows about group members that are installed but weren't installed as part of the group, and won't remove those on 'group remove'. Running 'yum upgrade' will also run 'yum group upgrade' (thus. adding new packages for all groups)." -property :group_package_types, String, description: "List of the following: optional, default, mandatory. Tells yum which type of packages in groups will be installed when 'groupinstall' is called." -property :groupremove_leaf_only, [true, false], description: "Used to determine yum's behaviour when the groupremove command is run. If groupremove_leaf_only is false (default) then all packages in the group will be removed. If groupremove_leaf_only is true then only those packages in the group that aren't required by another package will be removed." -property :history_list_view, String, equal_to: %w(users commands single-user-commands), description: "Which column of information to display in the 'yum history list' command." -property :history_record, [true, false], description: 'Should yum record history entries for transactions. This takes some disk space, and some extra time in the transactions. But it allows how to know a lot of information about what has happened before, and display it to the user with the history info/list/summary commands. yum also provides the history undo/redo commands.' -property :history_record_packages, String, description: 'This is a list of package names that should be recorded as having helped the transaction. yum plugins have an API to add themselves to this, so it should not normally be necessary to add packages here. Not that this is also used for the packages to look for in --version. Defaults to rpm, yum, yum-metadata-parser.' -property :http_caching, String, equal_to: %w(packages all none), description: "Determines how upstream HTTP caches are instructed to handle any HTTP downloads that Yum does. This option can take the following values: all' means that all HTTP downloads should be cached. 'packages' means that only RPM package downloads should be cached (but not repository metadata downloads). 'none' means that no HTTP downloads should be cached." -property :installonly_limit, String, regex: [/^\d+/, /keep/], default: '3', description: "Number of packages listed in installonlypkgs to keep installed at the same time. Setting to 0 disables this feature. Default is '0'. Note that this functionality used to be in the 'installonlyn' plugin, where this option was altered via tokeep. Note that as of version 3.2.24, yum will now look in the yumdb for a installonly attribute on installed packages. If that attribute is 'keep', then they will never be removed." -property :installonlypkgs, String, description: 'List of package provides that should only ever be installed, never updated. Kernels in particular fall into this category. Defaults to kernel, kernel-bigmem, kernel-enterprise, kernel-smp, kernel-modules, kernel-debug, kernel- unsupported, kernel-source, kernel-devel, kernel-PAE, kernel- PAE-debug.' -property :installroot, String, description: 'Specifies an alternative installroot, relative to which all packages will be installed.' -property :install_weak_deps, [true, false], description: "When this option is set to true and a new package is about to be installed, all packages linked by a weak dependency relation (i.e., Recommends or Supplements flags) with this package will be pulled into the transaction. Default is DNF's default of true." -property :ip_resolve, [String, Integer], equal_to: [4, '4', 6, '6'], description: "Determines how yum resolves host names. '4': resolve to IPv4 addresses only. '6': resolve to IPv6 addresses only." -property :keepalive, [true, false], description: 'Set whether HTTP keepalive should be used for HTTP/1.1 servers that support it. This can improve transfer speeds by using one connection when downloading multiple files from a repository.' -property :keepcache, [true, false], default: false, description: 'Determines whether or not yum keeps the cache of headers and packages after successful installation.' -property :kernelpkgnames, String, description: 'List of package names that are kernels. This is really only here for the updating of kernel packages and should be removed out in the yum 2.1 series.' -property :loadts_ignoremissing, [true, false], description: "Should the load-ts command ignore packages that are missing. This includes packages in the TS to be removed, which aren't installed, and packages in the TS to be added, which aren't available. If this is set to true, and an rpm is missing then loadts_ignorenewrpm is automatically set to true. Yum defaults to False." -property :loadts_ignorenewrpm, [true, false], description: 'Should the load-ts command ignore the future rpmdb version or abort if there is a mismatch between the TS file and what will happen on the current machine. Note that if loadts_ignorerpm is True, this option does nothing. Yum defaults to False' -property :loadts_ignorerpm, [true, false], description: 'Should the load-ts command ignore the rpmdb version (yum version nogroups) or abort if there is a mismatch between the TS file and the current machine. If this is set to true, then loadts_ignorenewrpm is automatically set to true. Yum defaults to False' -property :localpkg_gpgcheck, [true, false], description: 'This tells yum whether or not it should perform a GPG signature check on local packages (packages in a file, not in a repositoy).' -property :logfile, String, default: '/var/log/yum.log', description: 'Full directory and file name for where yum should write its log file.' -property :max_connections, String, regex: /^\d+/, description: 'The maximum number of simultaneous connections. This overrides the urlgrabber default of 5 connections. Note that there are also implicit per-mirror limits and the downloader honors these too.' -property :mddownloadpolicy, String, equal_to: %w(sqlite xml), description: "You can select which kinds of repodata you would prefer yum to download:\n'sqlite' - Download the .sqlite files, if available. This is currently slightly faster, once they are downloaded. However these files tend to be bigger, and thus. take longer to download. \n'xml' - Download the .XML files, which yum will do anyway as a fallback on the other options. These files tend to be smaller, but they require parsing/converting locally after download and some aditional checks are performed on them each time they are used." -property :mdpolicy, String, equal_to: %w(instant group:primary group:small group:main group:all), description: "You can select from different metadata download policies depending on how much data you want to download with the main repository metadata index. The advantages of downloading more metadata with the index is that you can't get into situations where you need to use that metadata later and the versions available aren't compatible (or the user lacks privileges) and that if the metadata is corrupt in any way yum will revert to the previous metadata.\n'instant' - Just download the new metadata index, this is roughly what yum always did, however it now does some checking on the index and reverts if it classifies it as bad.\n'group:primary' - Download the primary metadata with the index. This contains most of the package information and so is almost always required anyway.\n'group:small' - With the primary also download the updateinfo metadata, groups, and pkgtags. This is required for yum-security operations and it also used in the graphical clients. This file also tends to be significantly smaller than most others. This is the default. \n'group:main' - With the primary and updateinfo download the filelists metadata and the group metadata. The filelists data is required for operations like 'yum install /bin/bash', and also some dependency resolutions require it. The group data is used in some graphical clients and for group operations like 'yum grouplist Base'.\n'group:all' - Download all metadata listed in the index, currently the only one not listed above is the other metadata, which contains the changelog information which is used by yum-changelog. This is what 'yum makecache' uses." -property :metadata_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/, /never/], description: "Time (in seconds) after which the metadata will expire. So that if the current metadata downloaded is less than this many seconds old then yum will not update the metadata against the repository. If you find that yum is not downloading information on updates as often as you would like lower the value of this option. You can also change from the default of using seconds to using days, hours or minutes by appending a d, h or m respectively. The default is 6 hours, to compliment yum-updatesd running once an hour. It's also possible to use the word 'never', meaning that the metadata will never expire. Note that when using a metalink file the metalink must always be newer than the metadata for the repository, due to the validation, so this timeout also applies to the metalink file." -property :metadata_expire_filter, String, equal_to: %w(never read-only:past read-only:present read-only:future), description: "Filter the metadata_expire time, allowing a trade of speed for accuracy if a command doesn't require it. Each yum command can specify that it requires a certain level of timeliness quality from the remote repos. from 'I\'m about to install/upgrade, so this better be current' to 'Anything that\'s available is good enough'. \n'never' - Nothing is filtered, always obey metadata_expire. \n'read-only:past' - Commands that only care about past\ information are filtered from metadata expiring. Eg. yum history info (if history needs to lookup anything about a previous transaction, then by definition the remote package was available in the past). \n'read-only:present' - Commands that are balanced between past and future. This is the default. Eg. yum list yum\n'read-only:future' - Commands that are likely to result in running other commands which will require the latest metadata. Eg. yum check-update\nNote that this option requires that all the enabled repositories be roughly the same freshness (meaning the cache age difference from one another is at most 5 days). Failing that, metadata_expire will always be obeyed, just like with 'never'.\nAlso note that this option does not override 'yum clean expire-cache'." -property :minrate, String, description: "This sets the low speed threshold in bytes per second. If the server is sending data slower than this for at least 'timeout' seconds, Yum aborts the connection." -property :mirrorlist_expire, String, regex: /^\d+$/, description: 'Time (in seconds) after which the mirrorlist locally cached will expire. If the current mirrorlist is less than this many seconds old then yum will not download another copy of the mirrorlist, it has the same extra format as metadata_expire. If you find that yum is not downloading the mirrorlists as often as you would like lower the value of this option.' -property :multilib_policy, String, equal_to: %w(all best), description: "The policy installation policy. Can be set to 'all' or 'best'. All means install all possible arches for any package you want to install. Therefore yum install foo will install foo.i386 and foo.x86_64 on x86_64, if it is available. Best means install the best arch for this platform, only. " -property :obsoletes, [true, false], description: "This option only has affect during an update. It enables yum's obsoletes processing logic. Useful when doing distribution level upgrades. See also the yum upgrade command documentation for more details" -property :options, Hash -property :override_install_langs, [true, false], description: "This is a way to override rpm's _install_langs macro. without having to change it within rpm's macro file" -property :overwrite_groups, [true, false], description: "Used to determine yum's behaviour if two or more repositories offer the package groups with the same name. If overwrite_groups is true then the group packages of the last matching repository will be used. If overwrite_groups is false then the groups from all matching repositories will be merged together as one large group. Note that this option does not override remove_leaf_only, so enabling that option means this has almost no affect." -property :password, String, description: 'password to use with the username for basic authentication.' -property :path, String, name_property: true -property :persistdir, String, description: 'Directory where yum should store information that should persist over multiple runs.' -property :pluginconfpath, String, description: 'A list of directories where yum should look for plugin configuration files.' -property :pluginpath, String, description: 'A list of directories where yum should look for plugin modules.' -property :plugins, [true, false], default: true, description: 'Global switch to enable or disable yum plugins.' -property :protected_multilib, [true, false], description: 'This tells yum whether or not it should perform a check to make sure that multilib packages are the same version. For example, if this option is off (rpm behavior) then in some cases it might be possible for pkgA-1.x86_64 and pkgA-2.i386 to be installed at the same time. However this is very rarely desired. Install only packages, like the kernel, are exempt from this check.' -property :protected_packages, String, description: 'This is a list of packages that yum should never completely remove. They are protected via Obsoletes as well as user/plugin removals.' -property :proxy, String, description: 'URL to the proxy server that yum should use.' -property :proxy_password, String, description: 'The password for the specified proxy.' -property :proxy_username, String, description: 'The username for the specified proxy.' -property :query_install_excludes, [true, false], description: 'This applies the command line exclude option (only, not the configuration exclude above) to installed packages being shown in some query commands' -property :recent, String, regex: /^\d+$/, description: "Number of days back to look for 'recent' packages added to a repository." -property :recheck_installed_requires, [true, false], description: "When upgrading a package do we recheck any requirements that existed in the old package. Turning this on shouldn't do anything but slow yum depsolving down, however using rpm --nodeps etc. can break the rpmdb and then this will help." -property :releasever, String -property :remove_leaf_only, [true, false], description: "Used to determine yum's behaviour when a package is removed. If remove_leaf_only is false then packages, and their deps, will be removed. If remove_leaf_only is true then only those packages that aren't required by another package will be removed." -property :repo_gpgcheck, [true, false], description: 'This tells yum whether or not it should perform a GPG signature check on the repodata. When this is set in the [main] section it sets the default for all repositories.' -property :repopkgsremove_leaf_only, [true, false], description: "Used to determine yum's behaviour when the repo-pkg remove command is run. If repopkgremove_leaf_only is false then all packages in the repo. will be removed. If repopkgremove_leaf_only is true then only those packages in the repo. that aren't required by another package will be removed. Note that this option does not override remove_leaf_only, so enabling that option means this has almost no affect." -property :reposdir, String, description: "A list of directories where yum should look for .repo files which define repositories to use. Default is '/etc/yum/repos.d'. Each file in this directory should contain one or more repository sections as documented in [repository] options below. These will be merged with the repositories defined in /etc/yum/yum.conf to form the complete set of repositories that yum will use." -property :requires_policy, String, equal_to: %w(strong weak info), description: 'Strong means install just the needed requirements. Weak means also install any weak requirements. Info means install all requirements. This only happens on install/reinstall, upgrades/downgrades do not consult this at all. Note that yum will try to just drop weak and info requirements on errors.' -property :reset_nice, [true, false], description: 'If set to true then yum will try to reset the nice value to zero, before running an rpm transaction.' -property :retries, String, regex: /^\d+$/, description: "Set the number of times any attempt to retrieve a file should retry before returning an error. Setting this to '0' makes yum try forever." -property :rpmverbosity, String, equal_to: %w(info critical emergency error warn debug), description: 'Debug scriptlet output level.' -property :shell_exit_status, String, equal_to: %w(0 ?), description: "Determines the exit status that should be returned by `yum shell' when it terminates after reading the `exit' command or EOF. If ? is set, the exit status is that of the last command executed before `exit' (bash-like behavior). Yum defaults to 0." -property :showdupesfromrepos, [true, false], description: 'Set to true if you wish to show any duplicate packages from any repository, from package listings like the info or list commands. Set to false if you want only to see the newest packages from any repository.' -property :skip_broken, [true, false], description: 'Resolve depsolve problems by removing packages that are causing problems from the transaction.' -property :skip_missing_names_on_install, [true, false], description: "If set to False, 'yum install' will fail if it can't find any of the provided names (package, group, rpm file). Yum's default is true." -property :skip_missing_names_on_update, [true, false], description: "If set to False, 'yum update' will fail if it can't find any of the provided names (package, group, rpm file). It will also fail if the provided name is a package which is available, but not installed. Yum's default is true." -property :ssl_check_cert_permissions, [true, false], description: "Whether yum should check the permissions on the paths for the certificates on the repository (both remote and local). If we can't read any of the files then yum will force skip_if_unavailable to be true. This is most useful for non-root processes which use yum on repos. that have client cert files which are readable only by root." -property :sslcacert, String, description: 'Path to the directory containing the databases of the certificate authorities yum should use to verify SSL certificates.' -property :sslclientcert, String, description: 'Path to the SSL client certificate yum should use to connect to repos/remote sites.' -property :sslclientkey, String, description: 'Path to the SSL client key yum should use to connect to repos/remote sites.' -property :sslverify, [true, false], description: 'Should yum verify SSL certificates/hosts at all.' -property :syslog_device, String, description: 'Where to log syslog messages. Can be a local device (path) or a host:port string to use a remote syslog. If empty or points to a nonexistent device, syslog logging is disabled.' -property :syslog_facility, String, description: 'Facility name for syslog messages.' -property :syslog_ident, String, description: 'Identification (program name) for syslog messages.' -property :throttle, String, regex: [/\d+k/, /\d+M/, /\d+G/], description: "Enable bandwidth throttling for downloads. This option can be expressed as a absolute data rate in bytes/sec. An SI prefix (k, M or G) may be appended to the bandwidth value (eg. '5.5k' is 5.5 kilobytes/sec, '2M' is 2 Megabytes/sec)." -property :timeout, String, regex: /^\d+$/, description: 'Number of seconds to wait for a connection before timing out.' -property :tolerant, [true, false], description: "If enabled, yum will go slower, checking for things that shouldn't be possible making it more tolerant of external errors. Default to '0' (not tolerant)." -property :tsflags, String, description: "Comma or space separated list of transaction flags to pass to the rpm transaction set. These include 'noscripts', 'notriggers', 'nodocs', 'test', 'justdb' and 'nocontexts'. 'repackage' is also available but that does nothing with newer rpm versions. You can set all/any of them. However, if you don't know what these do in the context of an rpm transaction set you're best leaving it alone." -property :ui_repoid_vars, String, description: 'When a repository id is displayed, append these yum variables to the string if they are used in the baseurl/etc. Variables are appended in the order listed (and found).' -property :upgrade_group_objects_upgrade, [true, false], description: "Set this to false to disable the automatic running of 'group upgrade' when running the 'upgrade' command, and group_command is set to 'objects'." -property :upgrade_requirements_on_install, [true, false], description: "When installing/reinstalling/upgrading packages go through each package's installed dependencies and check for an update." -property :usercache, String, description: "Determines whether or not yum should store per-user cache in $TMPDIR. When set to '0', then whenever yum runs as a non-root user, --cacheonly is implied and system cache is used directly, and no new user cache is created in $TMPDIR. This can be used to prevent $TMPDIR from filling up if many users on the system often use yum and root tends to have up-to-date metadata that the users can rely on (they can still enable this feature with --setopt if they wish)." -property :username, String, description: 'username to use for basic authentication to a repo or really any url.' -property :usr_w_check, [true, false], description: "Set this to false to disable the checking for writability on /usr in the installroot (when going into the depsolving stage). Yum's default is true." - -alias_method :max_retries, :retries - -action :create do - template new_resource.path do - source 'main.erb' - cookbook 'yum' - mode '0644' - variables(config: new_resource) - end -end - -action :delete do - file new_resource.path do - action :delete - end -end diff --git a/cookbooks/yum/templates/main.erb b/cookbooks/yum/templates/main.erb deleted file mode 100644 index 28a163f..0000000 --- a/cookbooks/yum/templates/main.erb +++ /dev/null @@ -1,286 +0,0 @@ -# This file was generated by Chef Infra Client -# Do NOT modify this file by hand. - -[main] -<% if @config.alwaysprompt %> -alwaysprompt=<%= @config.alwaysprompt %> -<% end %> -<% if @config.assumeyes %> -assumeyes=<%= @config.assumeyes %> -<% end %> -<% if @config.bandwidth %> -bandwidth=<%= @config.bandwidth %> -<% end %> -<% if @config.bugtracker_url %> -bugtracker_url=<%= @config.bugtracker_url %> -<% end %> -<% if @config.cachedir %> -cachedir=<%= @config.cachedir %> -<% end %> -<% if @config.clean_requirements_on_remove %> -clean_requirements_on_remove=<%= @config.clean_requirements_on_remove %> -<% end %> -<% if @config.color %> -color=<%= @config.color %> -<% end %> -<% if @config.color_list_available_downgrade %> -color_list_available_downgrade=<%= @config.color_list_available_downgrade %> -<% end %> -<% if @config.color_list_available_install %> -color_list_available_install=<%= @config.color_list_available_install %> -<% end %> -<% if @config.color_list_available_reinstall %> -color_list_available_reinstall=<%= @config.color_list_available_reinstall %> -<% end %> -<% if @config.color_list_available_upgrade %> -color_list_available_upgrade=<%= @config.color_list_available_upgrade %> -<% end %> -<% if @config.color_list_installed_extra %> -color_list_installed_extra=<%= @config.color_list_installed_extra %> -<% end %> -<% if @config.color_list_installed_newer %> -color_list_installed_newer=<%= @config.color_list_installed_newer %> -<% end %> -<% if @config.color_list_installed_older %> -color_list_installed_older=<%= @config.color_list_installed_older %> -<% end %> -<% if @config.color_list_installed_reinstall %> -color_list_installed_reinstall=<%= @config.color_list_installed_reinstall %> -<% end %> -<% if @config.color_search_match %> -color_search_match=<%= @config.color_search_match %> -<% end %> -<% if @config.color_update_installed %> -color_update_installed=<%= @config.color_update_installed %> -<% end %> -<% if @config.color_update_local %> -color_update_local=<%= @config.color_update_local %> -<% end %> -<% if @config.color_update_remote %> -color_update_remote=<%= @config.color_update_remote %> -<% end %> -<% if @config.commands %> -commands=<%= @config.commands %> -<% end %> -<% if @config.debuglevel %> -debuglevel=<%= @config.debuglevel %> -<% end %> -<% if @config.deltarpm == true %> -deltarpm=1 -<% elsif @config.deltarpm == false %> -deltarpm=0 -<% end %> -<% if @config.diskspacecheck %> -diskspacecheck=<%= @config.diskspacecheck %> -<% end %> -<% if @config.distroverpkg %> -distroverpkg=<%= @config.distroverpkg %> -<% end %> -<% if @config.enable_group_conditionals %> -enable_group_conditionals=1 -<% end %> -<% if @config.errorlevel %> -errorlevel=<%= @config.errorlevel %> -<% end %> -<% if @config.exactarch %> -exactarch=1 -<% else %> -exactarch=0 -<% end %> -<% if @config.exclude %> -exclude=<%= @config.exclude %> -<% end %> -<% if @config.gpgcheck %> -gpgcheck=1 -<% else %> -gpgcheck=0 -<% end %> -<% if @config.group_package_types %> -group_package_types=<%= @config.group_package_types %> -<% end %> -<% if @config.groupremove_leaf_only %> -groupremove_leaf_only=<%= @config.groupremove_leaf_only %> -<% end %> -<% if @config.history_list_view %> -history_list_view=<%= @config.history_list_view %> -<% end %> -<% if @config.history_record %> -history_record=<%= @config.history_record %> -<% end %> -<% if @config.history_record_packages %> -history_record_packages=<%= @config.history_record_packages %> -<% end %> -<% if @config.http_caching %> -http_caching=<%= @config.http_caching %> -<% end %> -<% if @config.ip_resolve %> -ip_resolve=<%= @config.ip_resolve %> -<% end %> -<% unless @config.install_weak_deps.nil? %> -<% if @config.install_weak_deps %> -install_weak_deps=1 -<% else %> -install_weak_deps=0 -<% end %> -<% end %> -<% if @config.installonly_limit %> -installonly_limit=<%= @config.installonly_limit %> -<% end %> -<% if @config.installonlypkgs %> -installonlypkgs=<%= @config.installonlypkgs %> -<% end %> -<% if @config.installroot %> -installroot=<%= @config.installroot %> -<% end %> -<% if @config.keepalive %> -keepalive=<%= @config.keepalive %> -<% end %> -<% if @config.keepcache %> -keepcache=1 -<% else %> -keepcache=0 -<% end %> -<% if @config.kernelpkgnames %> -kernelpkgnames=<%= @config.kernelpkgnames %> -<% end %> -<% if @config.localpkg_gpgcheck %> -localpkg_gpgcheck=1 -<% else %> -localpkg_gpgcheck=0 -<% end %> -<% if @config.logfile %> -logfile=<%= @config.logfile %> -<% end %> -<% if @config.max_retries %> -max_retries=<%= @config.max_retries %> -<% end %> -<% if @config.mdpolicy %> -mdpolicy=<%= @config.mdpolicy %> -<% end %> -<% if @config.metadata_expire %> -metadata_expire=<%= @config.metadata_expire %> -<% end %> -<% if @config.mirrorlist_expire %> -mirrorlist_expire=<%= @config.mirrorlist_expire %> -<% end %> -<% if @config.multilib_policy %> -multilib_policy=<%= @config.multilib_policy %> -<% end %> -<% if @config.obsoletes == false %> -obsoletes=0 -<% else %> -obsoletes=1 -<% end %> -<% if @config.overwrite_groups %> -overwrite_groups=<%= @config.overwrite_groups %> -<% end %> -<% if @config.password %> -password=<%= @config.password %> -<% end %> -<% if @config.persistdir %> -persistdir=<%= @config.persistdir %> -<% end %> -<% if @config.pluginconfpath %> -pluginconfpath=<%= @config.pluginconfpath %> -<% end %> -<% if @config.pluginpath %> -pluginpath=<%= @config.pluginpath %> -<% end %> -<% if @config.plugins %> -plugins=1 -<% else %> -plugins=0 -<% end %> -<% if @config.protected_multilib %> -protected_multilib=<%= @config.protected_multilib %> -<% end %> -<% if @config.protected_packages %> -protected_packages=<%= @config.protected_packages %> -<% end %> -<% if @config.proxy %> -proxy=<%= @config.proxy %> -<% end %> -<% if @config.proxy_password %> -proxy_password=<%= @config.proxy_password %> -<% end %> -<% if @config.proxy_username %> -proxy_username=<%= @config.proxy_username %> -<% end %> -<% if @config.recent %> -recent=<%= @config.recent %> -<% end %> -<% if @config.releasever && @config.releasever.length > 0 %> -releasever=<%= @config.releasever %> -<% end %> -<% if @config.repo_gpgcheck %> -repo_gpgcheck=<%= @config.repo_gpgcheck %> -<% end %> -<% if @config.reposdir %> -reposdir=<%= @config.reposdir %> -<% end %> -<% if @config.reset_nice %> -reset_nice=<%= @config.reset_nice %> -<% end %> -<% if @config.rpmverbosity %> -rpmverbosity=<%= @config.rpmverbosity %> -<% end %> -<% if @config.showdupesfromrepos %> -showdupesfromrepos=<%= @config.showdupesfromrepos %> -<% end %> -<% if @config.skip_broken %> -skip_broken=<%= @config.skip_broken %> -<% end %> -<% if @config.ssl_check_cert_permissions %> -ssl_check_cert_permissions=<%= @config.ssl_check_cert_permissions %> -<% end %> -<% if @config.sslcacert %> -sslcacert=<%= @config.sslcacert %> -<% end %> -<% if @config.sslclientcert %> -sslclientcert=<%= @config.sslclientcert %> -<% end %> -<% if @config.sslclientkey %> -sslclientkey=<%= @config.sslclientkey %> -<% end %> -<% unless @config.sslverify.nil? %> -sslverify=<%= ( @config.sslverify ) ? 'true' : 'false' %> -<% end %> -<% if @config.syslog_device %> -syslog_device=<%= @config.syslog_device %> -<% end %> -<% if @config.syslog_facility %> -syslog_facility=<%= @config.syslog_facility %> -<% end %> -<% if @config.syslog_ident %> -syslog_ident=<%= @config.syslog_ident %> -<% end %> -<% if @config.throttle %> -throttle=<%= @config.throttle %> -<% end %> -<% if @config.timeout %> -timeout=<%= @config.timeout %> -<% end %> -<% if @config.tolerant %> -tolerant=<%= ( @config.tolerant ) ? '1' : '0' %> -<% end %> -<% if @config.tsflags %> -tsflags=<%= @config.tsflags %> -<% end %> -<% if @config.username %> -username=<%= @config.username %> -<% end %> -<% if @config.options -%> -<% @config.options.each do |key, value| -%> -<%= key %>=<%= - case value - when Array - value.join("\n ") - when TrueClass - '1' - when FalseClass - '0' - else - value - end %> -<% end -%> -<% end -%>