From 2fb94f3ade408267f2b9ec8eac907be94c0d3c96 Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Mon, 6 Feb 2017 15:25:29 -0500 Subject: [PATCH] Reformed the attributes to use the newer better methods, added compat_resources --- Berksfile | 6 ++++- attributes/default.rb | 6 ++++- attributes/zabbix-non-supported.rb | 15 ++++++++---- attributes/zabbix.rb | 22 +++++++++++------ metadata.rb | 5 ++-- recipes/default.rb | 38 ++++++------------------------ 6 files changed, 45 insertions(+), 47 deletions(-) diff --git a/Berksfile b/Berksfile index e9cf30e..5c43a05 100644 --- a/Berksfile +++ b/Berksfile @@ -2,5 +2,9 @@ source "https://supermarket.chef.io" metadata -cookbook "yum-epel", ">= 2.1.1" + +group :integration do + cookbook "compat_resource", '>= 12.16.3' + cookbook "yum-epel", ">= 2.1.1" +end diff --git a/attributes/default.rb b/attributes/default.rb index 461149f..104cf76 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1 +1,5 @@ -default['yum-zabbix']['repositories'] = %w(zabbix zabbix-non-supported) +default['yum-zabbix']['repos'] = %w( + zabbix + zabbix-non-supported +) + diff --git a/attributes/zabbix-non-supported.rb b/attributes/zabbix-non-supported.rb index 1a230e2..8d9757f 100644 --- a/attributes/zabbix-non-supported.rb +++ b/attributes/zabbix-non-supported.rb @@ -1,9 +1,14 @@ default['yum']['zabbix-non-supported']['repositoryid'] = 'zabbix-non-supported' +default['yum']['zabbix-non-supported']['description'] = 'Zabbix Official Repository - $basearch' +case node['platform'] +when 'amazon' + default['yum']['zabbix-non-supported']['baseurl'] = "http://repo.zabbix.com/non-supported/rhel/6/$basearch/" + default['yum']['zabbix-non-supported']['gpgkey'] = 'http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX' +else + default['yum']['zabbix-non-supported']['baseurl'] = "http://repo.zabbix.com/non-supported/rhel/#{node['platform_version'].to_i}/$basearch/" + default['yum']['zabbix-non-supported']['gpgkey'] = 'http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX' +end +default['yum']['zabbix-non-supported']['gpgcheck'] = true default['yum']['zabbix-non-supported']['enabled'] = false default['yum']['zabbix-non-supported']['managed'] = false -default['yum']['zabbix-non-supported']['gpgkey'] = 'http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX' -default['yum']['zabbix-non-supported']['gpgcheck'] = true - -default['yum']['zabbix-non-supported']['description'] = 'Zabbix Official Repository - $basearch' -default['yum']['zabbix-non-supported']['baseurl'] = "http://repo.zabbix.com/non-supported/rhel/#{node['platform_version'].to_i}/$basearch/" diff --git a/attributes/zabbix.rb b/attributes/zabbix.rb index 77e4043..05662b1 100644 --- a/attributes/zabbix.rb +++ b/attributes/zabbix.rb @@ -1,11 +1,19 @@ default['yum']['zabbix']['repositoryid'] = 'zabbix' +default['yum']['zabbix']['description'] = 'Zabbix Official Repository - $basearch' +default['yum']['zabbix']['release_repo'] = '3.0' +case node['platform'] +when 'amazon' + default['yum']['zabbix']['baseurl'] = "http://repo.zabbix.com/zabbix/#{node['yum']['zabbix']['release_repo']}/rhel/6/$basearch/" + default['yum']['zabbix']['gpgkey'] = 'http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX' +else + default['yum']['zabbix']['baseurl'] = "http://repo.zabbix.com/zabbix/#{node['yum']['zabbix']['release_repo']}/rhel/#{node['platform_version'].to_i}/$basearch/" + if node['yum']['zabbix']['release_repo'].to_f > 3.0 + default['yum']['zabbix']['gpgkey'] = 'http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-A14FE591' + else + default['yum']['zabbix']['gpgkey'] = 'http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX' + end +end default['yum']['zabbix']['enabled'] = true default['yum']['zabbix']['managed'] = true -default['yum']['zabbix']['gpgkey'] = 'http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX' default['yum']['zabbix']['gpgcheck'] = true -default['yum']['zabbix']['release_repo'] = '3.0' - -default['yum']['zabbix']['description'] = 'Zabbix Official Repository - $basearch' - -default['yum']['zabbix']['baseurl'] = "http://repo.zabbix.com/zabbix/#{node['yum']['zabbix']['release_repo']}/rhel/#{node['platform_version'].to_i}/$basearch/" - +default['yum']['zabbix']['make_cache'] = true diff --git a/metadata.rb b/metadata.rb index 271e135..3d0a91f 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,14 +4,15 @@ maintainer_email 'psi-jack@linux-help.org' license 'Apache 2.0' description 'Installs and configures the Zabbix Yum Repository' long_description '' -version '1.0.0' +version '1.0.1' issues_url 'https://git.linux-help.org/Linux-Help/cookbook-yum-zabbix/issues' source_url 'https://git.linux-help.org/Linux-Help/cookbook-yum-zabbix' -%w{ centos redhat oracle scientific }.each do |os| +%w{amazon centos redhat oracle scientific}.each do |os| supports os, '>= 6.0.0' end +depends 'compat_resource', '>= 12.16.3' depends 'yum-epel', '>= 2.1.1' chef_version '>= 12.1' diff --git a/recipes/default.rb b/recipes/default.rb index 1f5614f..292b969 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -14,38 +14,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -node['yum-zabbix']['repositories'].each do |repo| - next unless node['yum'][repo]['managed'] - include_recipe 'yum-epel' unless run_context.loaded_recipe?('yum-epel') +include_recipe 'yum-epel' unless run_context.loaded_recipe?('yum-epel') +node['yum-zabbix']['repos'].each do |repo| + next unless node['yum'][repo]['managed'] yum_repository repo do - description node['yum'][repo]['description'] unless node['yum'][repo]['description'].nil? - baseurl node['yum'][repo]['baseurl'] unless node['yum'][repo]['baseurl'].nil? - mirrorlist node['yum'][repo]['mirrorlist'] unless node['yum'][repo]['mirrorlist'].nil? - gpgcheck node['yum'][repo]['gpgcheck'] unless node['yum'][repo]['gpgcheck'].nil? - gpgkey node['yum'][repo]['gpgkey'] unless node['yum'][repo]['gpgkey'].nil? - enabled node['yum'][repo]['enabled'] unless node['yum'][repo]['enabled'].nil? - cost node['yum'][repo]['cost'] unless node['yum'][repo]['cost'].nil? - exclude node['yum'][repo]['exclude'] unless node['yum'][repo]['exclude'].nil? - enablegroups node['yum'][repo]['enablegroups'] unless node['yum'][repo]['enablegroups'].nil? - failovermethod node['yum'][repo]['failovermethod'] unless node['yum'][repo]['failovermethod'].nil? - http_caching node['yum'][repo]['http_caching'] unless node['yum'][repo]['http_caching'].nil? - include_config node['yum'][repo]['include_config'] unless node['yum'][repo]['include_config'].nil? - includepkgs node['yum'][repo]['includepkgs'] unless node['yum'][repo]['includepkgs'].nil? - keepalive node['yum'][repo]['keepalive'] unless node['yum'][repo]['keepalive'].nil? - max_retries node['yum'][repo]['max_retries'] unless node['yum'][repo]['max_retries'].nil? - metadata_expire node['yum'][repo]['metadata_expire'] unless node['yum'][repo]['metadata_expire'].nil? - mirror_expire node['yum'][repo]['mirror_expire'] unless node['yum'][repo]['mirror_expire'].nil? - priority node['yum'][repo]['priority'] unless node['yum'][repo]['priority'].nil? - proxy node['yum'][repo]['proxy'] unless node['yum'][repo]['proxy'].nil? - proxy_username node['yum'][repo]['proxy_username'] unless node['yum'][repo]['proxy_username'].nil? - proxy_password node['yum'][repo]['proxy_password'] unless node['yum'][repo]['proxy_password'].nil? - repositoryid node['yum'][repo]['repositoryid'] unless node['yum'][repo]['repositoryid'].nil? - sslcacert node['yum'][repo]['sslcacert'] unless node['yum'][repo]['sslcacert'].nil? - sslclientcert node['yum'][repo]['sslclientcert'] unless node['yum'][repo]['sslclientcert'].nil? - sslclientkey node['yum'][repo]['sslclientkey'] unless node['yum'][repo]['sslclientkey'].nil? - sslverify node['yum'][repo]['sslverify'] unless node['yum'][repo]['sslverify'].nil? - timeout node['yum'][repo]['timeout'] unless node['yum'][repo]['timeout'].nil? - action :create + node['yum'][repo].each do |config, value| + send(config.to_sym, value) unless value.nil? || config == 'managed' || config == 'release_repo' + end end end +