diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2019-11-14 13:35:09 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2019-11-14 13:35:09 -0800 |
commit | 0abe9ee9a5ea1ba74ae78e6eac404be9d37252a9 (patch) | |
tree | ffd833a7397cd3dee52e8c68581a03cb8c0f40e1 | |
parent | 37d505f3240e4b0a0ba0c316e6ecff4e9c3e5e45 (diff) | |
download | chef-0abe9ee9a5ea1ba74ae78e6eac404be9d37252a9.tar.gz |
additional chef-utils helpers for rhel6/7/8
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r-- | chef-utils/README.md | 5 | ||||
-rw-r--r-- | chef-utils/lib/chef-utils/dsl/platform_family.rb | 34 | ||||
-rw-r--r-- | chef-utils/spec/unit/dsl/platform_family_spec.rb | 54 |
3 files changed, 79 insertions, 14 deletions
diff --git a/chef-utils/README.md b/chef-utils/README.md index 19e679839c..7b71763a9b 100644 --- a/chef-utils/README.md +++ b/chef-utils/README.md @@ -82,7 +82,10 @@ There are helpers here which are also meta-families which group together multipl * `macos?` * `netbsd?` * `openbsd?` -* `rhel?` - includes redhat, centos, scientific, oracle +* `rhel?` - includes redhat, centos, scientific, oracle, clearos +* `rhel6?` - includes redhat6, centos6, scientifc6, oracle6, clearos6 +* `rhel7?` - includes redhat7, centos7, scientifc7, oracle7, clearos7 +* `rhel8?` - includes redhat8, centos8, scientifc8, oracle8, clearos8 * `smartos?` * `solaris2?` * `suse?` diff --git a/chef-utils/lib/chef-utils/dsl/platform_family.rb b/chef-utils/lib/chef-utils/dsl/platform_family.rb index f13a2e146b..55ca6196c9 100644 --- a/chef-utils/lib/chef-utils/dsl/platform_family.rb +++ b/chef-utils/lib/chef-utils/dsl/platform_family.rb @@ -77,7 +77,9 @@ module ChefUtils alias_method :mac?, :macos? alias_method :mac_os_x?, :macos? - # Determine if the current node is a member of the redhat family. + # Determine if the current node is a member of the rhel family (RHEL, CentOS, Oracle or Scientific Linux, no Amazon or Fedora). + # + # The platform_versions for these operating systems must match (rhel7 == centos7 == oracle7 == scientfic7), modulo additional packages # # @param [Chef::Node] node # @@ -88,6 +90,36 @@ module ChefUtils end alias_method :el?, :rhel? + # Determine if the current node is a rhel6 compatible build (RHEL, CentOS, Oracle or Scientific Linux) + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def rhel6?(node = __getnode) + node["platform_family"] == "rhel" && node["platform_version"].to_f >= 6.0 && node["platform_version"].to_f < 7.0 + end + + # Determine if the current node is a rhel7 compatible build (RHEL, CentOS, Oracle or Scientific Linux) + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def rhel7?(node = __getnode) + node["platform_family"] == "rhel" && node["platform_version"].to_f >= 7.0 && node["platform_version"].to_f < 8.0 + end + + # Determine if the current node is a rhel8 compatible build (RHEL, CentOS, Oracle or Scientific Linux) + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def rhel8?(node = __getnode) + node["platform_family"] == "rhel" && node["platform_version"].to_f >= 8.0 && node["platform_version"].to_f < 9.0 + end + # Determine if the current node is a member of the amazon family. # # @param [Chef::Node] node diff --git a/chef-utils/spec/unit/dsl/platform_family_spec.rb b/chef-utils/spec/unit/dsl/platform_family_spec.rb index 6349ef295f..8ceb1bdb4a 100644 --- a/chef-utils/spec/unit/dsl/platform_family_spec.rb +++ b/chef-utils/spec/unit/dsl/platform_family_spec.rb @@ -88,16 +88,28 @@ RSpec.describe ChefUtils::DSL::PlatformFamily do pf_reports_true_for(:arch?, :arch_linux?) end - context "on centos" do - let(:options) { { platform: "centos" } } + context "on centos6" do + let(:options) { { platform: "centos", version: "6.9" } } - pf_reports_true_for(:rhel?, :rpm_based?, :fedora_derived?, :redhat_based?, :el?) + pf_reports_true_for(:rhel?, :rpm_based?, :fedora_derived?, :redhat_based?, :el?, :rhel6?) end - context "on clearos" do - let(:options) { { platform: "clearos" } } + context "on centos7" do + let(:options) { { platform: "centos", version: "7.7.1908" } } - pf_reports_true_for(:rhel?, :rpm_based?, :fedora_derived?, :redhat_based?, :el?) + pf_reports_true_for(:rhel?, :rpm_based?, :fedora_derived?, :redhat_based?, :el?, :rhel7?) + end + + context "on centos8" do + let(:options) { { platform: "centos", version: "8" } } + + pf_reports_true_for(:rhel?, :rpm_based?, :fedora_derived?, :redhat_based?, :el?, :rhel8?) + end + + context "on clearos7" do + let(:options) { { platform: "clearos", version: "7.4" } } + + pf_reports_true_for(:rhel?, :rpm_based?, :fedora_derived?, :redhat_based?, :el?, :rhel7?) end context "on dragonfly4" do @@ -142,16 +154,34 @@ RSpec.describe ChefUtils::DSL::PlatformFamily do pf_reports_true_for(:suse?, :rpm_based?) end - context "on oracle" do - let(:options) { { platform: "oracle" } } + context "on oracle6" do + let(:options) { { platform: "oracle", version: "6.10" } } + + pf_reports_true_for(:rhel?, :rpm_based?, :fedora_derived?, :redhat_based?, :el?, :rhel6?) + end + + context "on oracle7" do + let(:options) { { platform: "oracle", version: "7.6" } } + + pf_reports_true_for(:rhel?, :rpm_based?, :fedora_derived?, :redhat_based?, :el?, :rhel7?) + end + + context "on redhat6" do + let(:options) { { platform: "redhat", version: "6.9" } } + + pf_reports_true_for(:rhel?, :rpm_based?, :fedora_derived?, :redhat_based?, :el?, :rhel6?) + end + + context "on redhat7" do + let(:options) { { platform: "redhat", version: "7.6" } } - pf_reports_true_for(:rhel?, :rpm_based?, :fedora_derived?, :redhat_based?, :el?) + pf_reports_true_for(:rhel?, :rpm_based?, :fedora_derived?, :redhat_based?, :el?, :rhel7?) end - context "on redhat" do - let(:options) { { platform: "redhat" } } + context "on redhat8" do + let(:options) { { platform: "redhat", version: "8" } } - pf_reports_true_for(:rhel?, :rpm_based?, :fedora_derived?, :redhat_based?, :el?) + pf_reports_true_for(:rhel?, :rpm_based?, :fedora_derived?, :redhat_based?, :el?, :rhel8?) end context "on smartos" do |