chef-sugar 1.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.kitchen.yml +14 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +7 -0
- data/CONTRIBUTING.md +20 -0
- data/Gemfile +2 -0
- data/LICENSE +201 -0
- data/README.md +256 -0
- data/Rakefile +1 -0
- data/chef-extensions.gemspec +37 -0
- data/lib/chef/sugar.rb +38 -0
- data/lib/chef/sugar/architecture.rb +53 -0
- data/lib/chef/sugar/cloud.rb +147 -0
- data/lib/chef/sugar/ip.rb +48 -0
- data/lib/chef/sugar/node.rb +41 -0
- data/lib/chef/sugar/platform.rb +166 -0
- data/lib/chef/sugar/platform_family.rb +158 -0
- data/lib/chef/sugar/ruby.rb +51 -0
- data/lib/chef/sugar/shell.rb +136 -0
- data/lib/chef/sugar/vagrant.rb +41 -0
- data/lib/chef/sugar/version.rb +21 -0
- data/metadata.rb +8 -0
- data/recipes/default.rb +25 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/shared_examples.rb +20 -0
- data/spec/unit/chef/extensions/architecture_spec.rb +29 -0
- data/spec/unit/chef/extensions/cloud_spec.rb +113 -0
- data/spec/unit/chef/extensions/ip_spec.rb +53 -0
- data/spec/unit/chef/extensions/node_spec.rb +30 -0
- data/spec/unit/chef/extensions/platform_family_spec.rb +137 -0
- data/spec/unit/chef/extensions/platform_spec.rb +201 -0
- data/spec/unit/chef/extensions/ruby_spec.rb +39 -0
- data/spec/unit/chef/extensions/shell_spec.rb +82 -0
- data/spec/unit/chef/extensions/vagrant_spec.rb +17 -0
- data/spec/unit/recipes/default_spec.rb +9 -0
- metadata +207 -0
@@ -0,0 +1,158 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2013, Seth Vargo <sethvargo@gmail.com>
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
class Chef
|
18
|
+
module Sugar
|
19
|
+
module PlatformFamily
|
20
|
+
extend self
|
21
|
+
|
22
|
+
#
|
23
|
+
# Determine if the current node is a member of the arch family.
|
24
|
+
#
|
25
|
+
# @param [Chef::Node] node
|
26
|
+
#
|
27
|
+
# @return [Boolean]
|
28
|
+
#
|
29
|
+
def arch_linux?(node)
|
30
|
+
node['platform_family'] == 'arch'
|
31
|
+
end
|
32
|
+
alias_method :arch?, :arch_linux?
|
33
|
+
|
34
|
+
#
|
35
|
+
# Determine if the current node is a member of the debian family.
|
36
|
+
#
|
37
|
+
# @param [Chef::Node] node
|
38
|
+
#
|
39
|
+
# @return [Boolean]
|
40
|
+
#
|
41
|
+
def debian?(node)
|
42
|
+
node['platform_family'] == 'debian'
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Determine if the current node is a member of the fedora family.
|
47
|
+
#
|
48
|
+
# @param [Chef::Node] node
|
49
|
+
#
|
50
|
+
# @return [Boolean]
|
51
|
+
#
|
52
|
+
def fedora?(node)
|
53
|
+
node['platform_family'] == 'fedora'
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Determine if the current node is a member of the arch family.
|
58
|
+
#
|
59
|
+
# @param [Chef::Node] node
|
60
|
+
#
|
61
|
+
# @return [Boolean]
|
62
|
+
#
|
63
|
+
def gentoo?(node)
|
64
|
+
node['platform_family'] == 'gentoo'
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Determine if the current node is a member of the OSX family.
|
69
|
+
#
|
70
|
+
# @param [Chef::Node] node
|
71
|
+
#
|
72
|
+
# @return [Boolean]
|
73
|
+
#
|
74
|
+
def mac_os_x?(node)
|
75
|
+
node['platform_family'] == 'mac_os_x'
|
76
|
+
end
|
77
|
+
alias_method :osx?, :mac_os_x?
|
78
|
+
alias_method :mac?, :mac_os_x?
|
79
|
+
|
80
|
+
#
|
81
|
+
# Determine if the current node is a member of the openbsd family.
|
82
|
+
#
|
83
|
+
# @param [Chef::Node] node
|
84
|
+
#
|
85
|
+
# @return [Boolean]
|
86
|
+
#
|
87
|
+
def openbsd?(node)
|
88
|
+
node['platform_family'] == 'openbsd'
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# Determine if the current node is a member of the redhat family.
|
93
|
+
#
|
94
|
+
# @param [Chef::Node] node
|
95
|
+
#
|
96
|
+
# @return [Boolean]
|
97
|
+
#
|
98
|
+
def rhel?(node)
|
99
|
+
node['platform_family'] == 'rhel'
|
100
|
+
end
|
101
|
+
alias_method :redhat?, :rhel?
|
102
|
+
|
103
|
+
#
|
104
|
+
# Determine if the current node is a member of the slackware family.
|
105
|
+
#
|
106
|
+
# @param [Chef::Node] node
|
107
|
+
#
|
108
|
+
# @return [Boolean]
|
109
|
+
#
|
110
|
+
def slackware?(node)
|
111
|
+
node['platform_family'] == 'slackware'
|
112
|
+
end
|
113
|
+
|
114
|
+
#
|
115
|
+
# Determine if the current node is a member of the suse family.
|
116
|
+
#
|
117
|
+
# @param [Chef::Node] node
|
118
|
+
#
|
119
|
+
# @return [Boolean]
|
120
|
+
#
|
121
|
+
def suse?(node)
|
122
|
+
node['platform_family'] == 'suse'
|
123
|
+
end
|
124
|
+
|
125
|
+
#
|
126
|
+
# Determine if the current node is a member of the windows family.
|
127
|
+
#
|
128
|
+
# @param [Chef::Node] node
|
129
|
+
#
|
130
|
+
# @return [Boolean]
|
131
|
+
#
|
132
|
+
def windows?(node)
|
133
|
+
node['platform_family'] == 'windows'
|
134
|
+
end
|
135
|
+
alias_method :not_linux?, :windows?
|
136
|
+
|
137
|
+
#
|
138
|
+
# Determine if the current system is a linux derivative
|
139
|
+
#
|
140
|
+
# @param [Chef::Node] node
|
141
|
+
#
|
142
|
+
# @return [Boolean]
|
143
|
+
#
|
144
|
+
def linux?(node)
|
145
|
+
!windows?(node)
|
146
|
+
end
|
147
|
+
alias_method :not_windows?, :linux?
|
148
|
+
end
|
149
|
+
|
150
|
+
module DSL
|
151
|
+
Chef::Sugar::PlatformFamily.instance_methods.each do |name|
|
152
|
+
define_method(name) do
|
153
|
+
Chef::Sugar::PlatformFamily.send(name, node)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2013, Seth Vargo <sethvargo@gmail.com>
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
class Chef
|
18
|
+
module Sugar
|
19
|
+
module Ruby
|
20
|
+
extend self
|
21
|
+
|
22
|
+
#
|
23
|
+
# Determine if the current Ruby version is 2.0.
|
24
|
+
#
|
25
|
+
# @return [Boolean]
|
26
|
+
#
|
27
|
+
def ruby_20?(node)
|
28
|
+
version = Gem::Version.new(node['languages']['ruby']['version'])
|
29
|
+
Gem::Requirement.new('~> 2.0.0').satisfied_by?(version)
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Determine if the current Ruby version is 1.9.
|
34
|
+
#
|
35
|
+
# @return [Boolean]
|
36
|
+
#
|
37
|
+
def ruby_19?(node)
|
38
|
+
version = Gem::Version.new(node['languages']['ruby']['version'])
|
39
|
+
Gem::Requirement.new('~> 1.9.0').satisfied_by?(version)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module DSL
|
44
|
+
# @see Chef::Sugar::Ruby#ruby_20?
|
45
|
+
def ruby_20?; Chef::Sugar::Ruby.ruby_20?(node); end
|
46
|
+
|
47
|
+
# @see Chef::Sugar::Ruby#ruby_19?
|
48
|
+
def ruby_19?; Chef::Sugar::Ruby.ruby_19?(node); end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2013, Seth Vargo <sethvargo@gmail.com>
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'mixlib/shellout'
|
18
|
+
|
19
|
+
class Chef
|
20
|
+
module Sugar
|
21
|
+
module Shell
|
22
|
+
extend self
|
23
|
+
|
24
|
+
#
|
25
|
+
# Finds a command in $PATH
|
26
|
+
#
|
27
|
+
# @param [String] cmd
|
28
|
+
# the command to find
|
29
|
+
#
|
30
|
+
# @return [String, nil]
|
31
|
+
#
|
32
|
+
def which(cmd)
|
33
|
+
paths = ENV['PATH'].split(::File::PATH_SEPARATOR) + %w(/bin /usr/bin /sbin /usr/sbin)
|
34
|
+
|
35
|
+
paths.each do |path|
|
36
|
+
possible = File.join(path, cmd)
|
37
|
+
return possible if File.executable?(possible)
|
38
|
+
end
|
39
|
+
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# The platform-specific output path to +/dev/null+.
|
45
|
+
#
|
46
|
+
# @return [String]
|
47
|
+
#
|
48
|
+
def dev_null(node)
|
49
|
+
Chef::Sugar::PlatformFamily.windows?(node) ? 'NUL' : '/dev/null'
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Boolean method to check if a command line utility is installed.
|
54
|
+
#
|
55
|
+
# @param [String] cmd
|
56
|
+
# the command to find
|
57
|
+
#
|
58
|
+
# @return [Boolean]
|
59
|
+
# true if the command is found in the path, false otherwise
|
60
|
+
#
|
61
|
+
def installed?(cmd)
|
62
|
+
!which(cmd).nil?
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# Checks if the given binary is installed and exists at the given
|
67
|
+
# version. Also see {version_for}.
|
68
|
+
#
|
69
|
+
# @param [String] cmd
|
70
|
+
# the command to check
|
71
|
+
# @param [String] version
|
72
|
+
# the version to check
|
73
|
+
# @param [String] flag
|
74
|
+
# the flag to use to check the version of the binary
|
75
|
+
#
|
76
|
+
# @return [Boolean]
|
77
|
+
# true if the command exists and is at the given version, false
|
78
|
+
# otherwise
|
79
|
+
#
|
80
|
+
def installed_at_version?(cmd, version, flag = '--version')
|
81
|
+
which(cmd) && if version.is_a?(Regexp)
|
82
|
+
version_for(cmd, flag) =~ version
|
83
|
+
else
|
84
|
+
version_for(cmd, flag).include?(version)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
# The version for a given command. This method does NOT check if the
|
90
|
+
# command exists! It is assumed the command existence has been
|
91
|
+
# checked with +which+ or similar. To simply check if an installed
|
92
|
+
# version is acceptable, please see {installed_at_version}.
|
93
|
+
#
|
94
|
+
# Assumptions:
|
95
|
+
# 1. The command exists.
|
96
|
+
# 2. The command outputs version information to +$stdout+.
|
97
|
+
#
|
98
|
+
#
|
99
|
+
# @param [String] cmd
|
100
|
+
# the command to find the version for
|
101
|
+
# @param [String] flag
|
102
|
+
# the flag to use to get the version
|
103
|
+
#
|
104
|
+
# @return [String]
|
105
|
+
# the output of the version command
|
106
|
+
#
|
107
|
+
def version_for(cmd, flag = '--version')
|
108
|
+
cmd = Mixlib::ShellOut.new("#{cmd} #{flag}")
|
109
|
+
cmd.run_command
|
110
|
+
cmd.error!
|
111
|
+
cmd.stdout.strip
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
module DSL
|
116
|
+
# @see Chef::Sugar::Shell#which
|
117
|
+
def which(cmd); Chef::Sugar::Shell.which(cmd); end
|
118
|
+
|
119
|
+
# @see Chef::Sugar::Shell#dev_null
|
120
|
+
def dev_null; Chef::Sugar::Shell.dev_null(node); end
|
121
|
+
|
122
|
+
# @see Chef::Sugar::Shell#installed?
|
123
|
+
def installed?(cmd); Chef::Sugar::Shell.installed?(cmd); end
|
124
|
+
|
125
|
+
# @see Chef::Sugar::Shell#installed_at_version?
|
126
|
+
def installed_at_version?(cmd, version, flag = '--version')
|
127
|
+
Chef::Sugar::Shell.installed_at_version?(cmd, version, flag)
|
128
|
+
end
|
129
|
+
|
130
|
+
# @see Chef::Sugar::Shell#version_for
|
131
|
+
def version_for(cmd, flag = '--version')
|
132
|
+
Chef::Sugar::Shell.version_for(cmd, flag)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2013, Seth Vargo <sethvargo@gmail.com>
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
class Chef
|
18
|
+
module Sugar
|
19
|
+
module Vagrant
|
20
|
+
extend self
|
21
|
+
|
22
|
+
#
|
23
|
+
# Determine if the current node is running in vagrant mode.
|
24
|
+
#
|
25
|
+
# @param [Chef::Node] node
|
26
|
+
#
|
27
|
+
# @return [Boolean]
|
28
|
+
# true if the machine is currently running vagrant, false
|
29
|
+
# otherwise
|
30
|
+
#
|
31
|
+
def vagrant?(node)
|
32
|
+
node.key?('vagrant')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module DSL
|
37
|
+
# @see Chef::Sugar::Vagrant#vagrant?
|
38
|
+
def vagrant?; Chef::Sugar::Vagrant.vagrant?(node); end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2013, Seth Vargo <sethvargo@gmail.com>
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
class Chef
|
18
|
+
module Sugar
|
19
|
+
VERSION = '1.0.0.beta.1'
|
20
|
+
end
|
21
|
+
end
|
data/metadata.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
name 'chef-sugar'
|
2
|
+
maintainer 'Seth Vargo'
|
3
|
+
maintainer_email 'sethvargo@gmail.com'
|
4
|
+
license 'Apache 2.0'
|
5
|
+
description 'Installs chef-sugar. Please see the chef-sugar ' \
|
6
|
+
'Ruby gem for more information.'
|
7
|
+
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
8
|
+
version '1.0.0'
|
data/recipes/default.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#
|
2
|
+
# Cookbook Name:: chef-sugar
|
3
|
+
# Recipe:: default
|
4
|
+
#
|
5
|
+
# Copyright 2013, Seth Vargo <sethvargo@gmail.com>
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
chef_gem('chef-sugar') do
|
21
|
+
version '1.0.0'
|
22
|
+
action :nothing
|
23
|
+
end.run_action(:install)
|
24
|
+
|
25
|
+
require 'chef/sugar'
|