Skip to content

Commit 2343498

Browse files
authored
Actually enforce apt and yum versions in the metadata.rb file (#874)
* Actually enforce apt and yum versions in the metadata.rb file * Remove comments about apt and yum in the README.md file * Fix typo * Make it work for Chef < 13.1.33 * Fix style * Fix style
1 parent aa183de commit 2343498

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

README.md

-13
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,6 @@ The following Opscode cookbooks are dependencies:
4242

4343
#### Chef
4444

45-
**Chef 12 users**: Depending on your version of Chef 12, additional dependency constraints may apply:
46-
47-
```ruby
48-
# Chef < 12.14
49-
depends 'yum', '< 5.0'
50-
```
51-
52-
```ruby
53-
# Chef < 12.9
54-
depends 'apt', '< 6.0.0'
55-
depends 'yum', '< 5.0'
56-
```
57-
5845
**Chef 13 users**: With Chef 13 and `chef_handler` 1.x, you may have trouble using the `dd-handler` recipe. The known workaround is to update your dependency to `chef_handler` >= 2.1.
5946

6047
### Installation

metadata.rb

+23-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,30 @@
2222
supports os
2323
end
2424

25-
if Chef::VERSION < Gem::Version.new(14)
25+
current_chef_version = if Chef::VERSION.instance_of? String
26+
# For Chef < 13.1.33 Chef::VERSION was a String
27+
Gem::Version.new(Chef::VERSION.to_f)
28+
else
29+
# Else Chef::VERSION is already a VersionString
30+
Chef::VERSION
31+
end
32+
33+
if current_chef_version < Gem::Version.new(14)
2634
# The chef_handler cookbook is shipped as part of Chef >= 14,
2735
# so from Chef >= 14 chef_handler cookbook is deprecated.
2836
depends 'chef_handler', '>= 1.2'
2937
end
30-
depends 'apt' # Use '< 6.0.0' with Chef < 12.9
31-
depends 'yum', '>= 3.0' # Use '< 5.0' with Chef < 12.14
38+
39+
# Use '< 6.0.0' with Chef < 12.9
40+
if current_chef_version < Gem::Version.new(12.9)
41+
depends 'apt', '< 6.0'
42+
else
43+
depends 'apt'
44+
end
45+
46+
# Use '< 5.0' with Chef < 12.14
47+
if current_chef_version < Gem::Version.new(12.14)
48+
depends 'yum', '>= 3.0', '< 5.0'
49+
else
50+
depends 'yum', '>= 3.0'
51+
end

0 commit comments

Comments
 (0)