garcun 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +17 -0
- data/.gitignore +197 -0
- data/.rspec +2 -0
- data/Gemfile +22 -0
- data/LICENSE +201 -0
- data/README.md +521 -0
- data/Rakefile +47 -0
- data/garcun.gemspec +83 -0
- data/lib/garcon.rb +290 -0
- data/lib/garcon/chef/chef_helpers.rb +343 -0
- data/lib/garcon/chef/coerce/coercer.rb +134 -0
- data/lib/garcon/chef/coerce/coercions/boolean_definitions.rb +34 -0
- data/lib/garcon/chef/coerce/coercions/date_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/date_time_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/fixnum_definitions.rb +34 -0
- data/lib/garcon/chef/coerce/coercions/float_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/hash_definitions.rb +29 -0
- data/lib/garcon/chef/coerce/coercions/integer_definitions.rb +31 -0
- data/lib/garcon/chef/coerce/coercions/string_definitions.rb +45 -0
- data/lib/garcon/chef/coerce/coercions/time_definitions.rb +32 -0
- data/lib/garcon/chef/handler/devreporter.rb +127 -0
- data/lib/garcon/chef/log.rb +64 -0
- data/lib/garcon/chef/node.rb +100 -0
- data/lib/garcon/chef/provider/civilize.rb +209 -0
- data/lib/garcon/chef/provider/development.rb +159 -0
- data/lib/garcon/chef/provider/download.rb +420 -0
- data/lib/garcon/chef/provider/house_keeping.rb +265 -0
- data/lib/garcon/chef/provider/node_cache.rb +31 -0
- data/lib/garcon/chef/provider/partial.rb +183 -0
- data/lib/garcon/chef/provider/recovery.rb +80 -0
- data/lib/garcon/chef/provider/zip_file.rb +271 -0
- data/lib/garcon/chef/resource/attribute.rb +52 -0
- data/lib/garcon/chef/resource/base_dsl.rb +174 -0
- data/lib/garcon/chef/resource/blender.rb +140 -0
- data/lib/garcon/chef/resource/lazy_eval.rb +66 -0
- data/lib/garcon/chef/resource/resource_name.rb +109 -0
- data/lib/garcon/chef/secret_bag.rb +204 -0
- data/lib/garcon/chef/validations.rb +76 -0
- data/lib/garcon/chef_inclusions.rb +151 -0
- data/lib/garcon/configuration.rb +138 -0
- data/lib/garcon/core_ext.rb +39 -0
- data/lib/garcon/core_ext/array.rb +27 -0
- data/lib/garcon/core_ext/binding.rb +64 -0
- data/lib/garcon/core_ext/boolean.rb +66 -0
- data/lib/garcon/core_ext/duration.rb +271 -0
- data/lib/garcon/core_ext/enumerable.rb +34 -0
- data/lib/garcon/core_ext/file.rb +127 -0
- data/lib/garcon/core_ext/filetest.rb +62 -0
- data/lib/garcon/core_ext/hash.rb +279 -0
- data/lib/garcon/core_ext/kernel.rb +159 -0
- data/lib/garcon/core_ext/lazy.rb +222 -0
- data/lib/garcon/core_ext/method_access.rb +243 -0
- data/lib/garcon/core_ext/module.rb +92 -0
- data/lib/garcon/core_ext/nil.rb +53 -0
- data/lib/garcon/core_ext/numeric.rb +44 -0
- data/lib/garcon/core_ext/object.rb +342 -0
- data/lib/garcon/core_ext/pathname.rb +152 -0
- data/lib/garcon/core_ext/process.rb +41 -0
- data/lib/garcon/core_ext/random.rb +497 -0
- data/lib/garcon/core_ext/string.rb +312 -0
- data/lib/garcon/core_ext/struct.rb +49 -0
- data/lib/garcon/core_ext/symbol.rb +170 -0
- data/lib/garcon/core_ext/time.rb +234 -0
- data/lib/garcon/exceptions.rb +101 -0
- data/lib/garcon/inflections.rb +237 -0
- data/lib/garcon/inflections/defaults.rb +79 -0
- data/lib/garcon/inflections/inflections.rb +182 -0
- data/lib/garcon/inflections/rules_collection.rb +37 -0
- data/lib/garcon/secret.rb +271 -0
- data/lib/garcon/stash/format.rb +114 -0
- data/lib/garcon/stash/journal.rb +226 -0
- data/lib/garcon/stash/queue.rb +83 -0
- data/lib/garcon/stash/serializer.rb +86 -0
- data/lib/garcon/stash/store.rb +435 -0
- data/lib/garcon/task.rb +31 -0
- data/lib/garcon/task/atomic.rb +151 -0
- data/lib/garcon/task/atomic_boolean.rb +127 -0
- data/lib/garcon/task/condition.rb +99 -0
- data/lib/garcon/task/copy_on_notify_observer_set.rb +154 -0
- data/lib/garcon/task/copy_on_write_observer_set.rb +153 -0
- data/lib/garcon/task/count_down_latch.rb +92 -0
- data/lib/garcon/task/delay.rb +196 -0
- data/lib/garcon/task/dereferenceable.rb +144 -0
- data/lib/garcon/task/event.rb +119 -0
- data/lib/garcon/task/executor.rb +275 -0
- data/lib/garcon/task/executor_options.rb +59 -0
- data/lib/garcon/task/future.rb +107 -0
- data/lib/garcon/task/immediate_executor.rb +84 -0
- data/lib/garcon/task/ivar.rb +171 -0
- data/lib/garcon/task/lazy_reference.rb +74 -0
- data/lib/garcon/task/monotonic_time.rb +69 -0
- data/lib/garcon/task/obligation.rb +256 -0
- data/lib/garcon/task/observable.rb +101 -0
- data/lib/garcon/task/priority_queue.rb +234 -0
- data/lib/garcon/task/processor_count.rb +128 -0
- data/lib/garcon/task/read_write_lock.rb +304 -0
- data/lib/garcon/task/safe_task_executor.rb +58 -0
- data/lib/garcon/task/single_thread_executor.rb +97 -0
- data/lib/garcon/task/thread_pool/cached.rb +71 -0
- data/lib/garcon/task/thread_pool/executor.rb +294 -0
- data/lib/garcon/task/thread_pool/fixed.rb +61 -0
- data/lib/garcon/task/thread_pool/worker.rb +90 -0
- data/lib/garcon/task/timer.rb +44 -0
- data/lib/garcon/task/timer_set.rb +194 -0
- data/lib/garcon/task/timer_task.rb +377 -0
- data/lib/garcon/task/waitable_list.rb +58 -0
- data/lib/garcon/utility/ansi.rb +199 -0
- data/lib/garcon/utility/at_random.rb +77 -0
- data/lib/garcon/utility/crypto.rb +292 -0
- data/lib/garcon/utility/equalizer.rb +146 -0
- data/lib/garcon/utility/faker/extensions/array.rb +22 -0
- data/lib/garcon/utility/faker/extensions/symbol.rb +9 -0
- data/lib/garcon/utility/faker/faker.rb +164 -0
- data/lib/garcon/utility/faker/faker/company.rb +17 -0
- data/lib/garcon/utility/faker/faker/hacker.rb +30 -0
- data/lib/garcon/utility/faker/faker/version.rb +3 -0
- data/lib/garcon/utility/faker/locales/en-US.yml +83 -0
- data/lib/garcon/utility/faker/locales/en.yml +21 -0
- data/lib/garcon/utility/file_helper.rb +170 -0
- data/lib/garcon/utility/hookers.rb +178 -0
- data/lib/garcon/utility/interpolation.rb +90 -0
- data/lib/garcon/utility/memstash.rb +364 -0
- data/lib/garcon/utility/misc.rb +54 -0
- data/lib/garcon/utility/msg_from_god.rb +62 -0
- data/lib/garcon/utility/retry.rb +238 -0
- data/lib/garcon/utility/timeout.rb +58 -0
- data/lib/garcon/utility/uber/builder.rb +91 -0
- data/lib/garcon/utility/uber/callable.rb +7 -0
- data/lib/garcon/utility/uber/delegates.rb +13 -0
- data/lib/garcon/utility/uber/inheritable_attr.rb +37 -0
- data/lib/garcon/utility/uber/options.rb +101 -0
- data/lib/garcon/utility/uber/uber_version.rb +3 -0
- data/lib/garcon/utility/uber/version.rb +33 -0
- data/lib/garcon/utility/url_helper.rb +100 -0
- data/lib/garcon/utils.rb +29 -0
- data/lib/garcon/version.rb +62 -0
- data/lib/garcun.rb +24 -0
- metadata +680 -0
data/README.md
ADDED
@@ -0,0 +1,521 @@
|
|
1
|
+
|
2
|
+
# Garcon
|
3
|
+
|
4
|
+
A collection of methods helpful in writing complex cookbooks that are
|
5
|
+
impossible to comprehend.
|
6
|
+
|
7
|
+
Hipster, hoodie ninja cool awesome.
|
8
|
+
|
9
|
+
## Requirements
|
10
|
+
|
11
|
+
Before trying to use the cookbook make sure you have a supported system. If you
|
12
|
+
are attempting to use the cookbook in a standalone manner to do testing and
|
13
|
+
development you will need a functioning Chef/Ruby environment, with the
|
14
|
+
following:
|
15
|
+
|
16
|
+
* Chef 11 or higher
|
17
|
+
* Ruby 1.9 (preferably from the Chef full-stack installer)
|
18
|
+
|
19
|
+
#### Chef
|
20
|
+
|
21
|
+
Chef Server version 11+ and Chef Client version 11.16.2+ and Ohai 7+ are
|
22
|
+
required. Clients older that 11.16.2 do not work.
|
23
|
+
|
24
|
+
#### Platforms
|
25
|
+
|
26
|
+
This cookbook uses Test Kitchen to do cross-platform convergence and post-
|
27
|
+
convergence tests. The tested platforms are considered supported. This cookbook
|
28
|
+
may work on other platforms or platform versions with or without modification.
|
29
|
+
|
30
|
+
* Red Hat Enterprise Linux (RHEL) Server 6 x86_64 (RedHat, CentOS, Oracle etc.)
|
31
|
+
|
32
|
+
#### Cookbooks
|
33
|
+
|
34
|
+
The following cookbooks are required as noted (check the metadata.rb file for
|
35
|
+
the specific version numbers):
|
36
|
+
|
37
|
+
* [chef_handler](https://supermarket.getchef.com/cookbooks/chef_handler) -
|
38
|
+
Distribute and enable Chef Exception and Report handlers.
|
39
|
+
* [yum](https://supermarket.getchef.com/cookbooks/yum) - The Yum cookbook
|
40
|
+
exposes the yum_repository resources that allows a user to both control global
|
41
|
+
behavior and make individual Yum repositories available for use.
|
42
|
+
|
43
|
+
### Development Requirements
|
44
|
+
|
45
|
+
In order to develop and test this Cookbook, you will need a handful of gems
|
46
|
+
installed.
|
47
|
+
|
48
|
+
* [Chef][]
|
49
|
+
* [Berkshelf][]
|
50
|
+
* [Test Kitchen][]
|
51
|
+
* [ChefSpec][]
|
52
|
+
* [Foodcritic][]
|
53
|
+
|
54
|
+
It is recommended for you to use the Chef Developer Kit (ChefDK). You can get
|
55
|
+
the [latest release of ChefDK from the downloads page][ChefDK].
|
56
|
+
|
57
|
+
On Mac OS X, you can also use [homebrew-cask](http://caskroom.io) to install
|
58
|
+
ChefDK.
|
59
|
+
|
60
|
+
Once you install the package, the `chef-client` suite, `berks`, `kitchen`, and
|
61
|
+
this application (`chef`) will be symlinked into your system bin directory,
|
62
|
+
ready to use.
|
63
|
+
|
64
|
+
You should then set your Ruby/Chef development environment to use ChefDK. You
|
65
|
+
can do so by initializing your shell with ChefDK's environment.
|
66
|
+
|
67
|
+
eval "$(chef shell-init SHELL_NAME)"
|
68
|
+
|
69
|
+
where `SHELL_NAME` is the name of your shell, (bash or zsh). This modifies your
|
70
|
+
`PATH` and `GEM_*` environment variables to include ChefDK's paths (run without
|
71
|
+
the `eval` to see the generated code). Now your default `ruby` and associated
|
72
|
+
tools will be the ones from ChefDK:
|
73
|
+
|
74
|
+
which ruby
|
75
|
+
# => /opt/chefdk/embedded/bin/ruby
|
76
|
+
|
77
|
+
You will also need Vagrant 1.6+ installed and a Virtualization provider such as
|
78
|
+
VirtualBox or VMware.
|
79
|
+
|
80
|
+
## Usage
|
81
|
+
|
82
|
+
Include the garcon recipe in your run list:
|
83
|
+
|
84
|
+
include_recipe 'garcon::default'
|
85
|
+
|
86
|
+
## Attributes
|
87
|
+
|
88
|
+
Attributes are under the `garcon` namespace, the following attributes affect
|
89
|
+
the behavior of how the cookbook performs an installation, or are used in the
|
90
|
+
recipes for various settings that require flexibility.
|
91
|
+
|
92
|
+
### General attributes:
|
93
|
+
|
94
|
+
General attributes can be found in the `default.rb` file.
|
95
|
+
|
96
|
+
* `node[:garcon][:repo][:gpgcheck]`: [TrueClass, FalseClass] This tells yum
|
97
|
+
whether or not it should perform a GPG signature check on packages. When this
|
98
|
+
is set in the [main] section it sets the default for all repositories. The
|
99
|
+
default is `true`.
|
100
|
+
* `node[:garcon][:repo][:gpgkey]`: [String, URI::HTTP] A URL pointing to the
|
101
|
+
ASCII-armored GPG key file for the repository. This option is used if yum
|
102
|
+
needs a public key to verify a package and the required key hasn't been
|
103
|
+
imported into the RPM database. If this option is set, yum will automatically
|
104
|
+
import the key from the specified URL.
|
105
|
+
* `node[:garcon][:repo][:mirrorlist]`: [String, URI::HTTP] Specifies a URL to a
|
106
|
+
file containing a list of baseurls. This can be used instead of or with the
|
107
|
+
baseurl option. Substitution variables, described below, can be used with this
|
108
|
+
option. As a special hack is the mirrorlist URL contains the word "metalink"
|
109
|
+
then the value of mirrorlist is copied to metalink (if metalink is not set).
|
110
|
+
|
111
|
+
## Providers
|
112
|
+
|
113
|
+
This cookbook includes HWRPs for managing:
|
114
|
+
|
115
|
+
* `Chef::Provider::Download`: The `download` resource is a lightweight multi-
|
116
|
+
protocol and multi-source download utility. It supports HTTP/HTTPS, FTP,
|
117
|
+
BitTorrent and Metalink.
|
118
|
+
* `Chef::Provider::ZipFile`: Provides a pure-ruby implementation for managing
|
119
|
+
zip files, adapted from the `windows_zipfile` resource.
|
120
|
+
* `Chef::Provider::Thread`:
|
121
|
+
|
122
|
+
### download
|
123
|
+
|
124
|
+
Use the `download` resource to transfer files from a remote location, similar
|
125
|
+
to `remote_file` but provides multithreaded torrent and http downloader
|
126
|
+
utilizing [Aria2](http://aria2.sourceforge.net). This can be up to four times
|
127
|
+
faster than the standard `remote_file` resource, useful for large file
|
128
|
+
transfers.
|
129
|
+
|
130
|
+
#### Syntax
|
131
|
+
|
132
|
+
The syntax for using the `download` resource in a recipe is as follows:
|
133
|
+
|
134
|
+
download 'name' do
|
135
|
+
attribute 'value' # see attributes section below
|
136
|
+
...
|
137
|
+
action :action # see actions section below
|
138
|
+
end
|
139
|
+
|
140
|
+
Where:
|
141
|
+
|
142
|
+
* `download` tells the chef-client to use the `Chef::Provider::Download`
|
143
|
+
provider during the chef-client run;
|
144
|
+
* `name` is the name of the resource block; when the `path` attribute is not
|
145
|
+
specified as part of a recipe, `name` is also the path to the remote file;
|
146
|
+
* `attribute` is zero (or more) of the attributes that are available for this
|
147
|
+
resource;
|
148
|
+
* `:action` identifies which steps the chef-client will take to bring the node
|
149
|
+
into the desired state.
|
150
|
+
|
151
|
+
For example:
|
152
|
+
|
153
|
+
download ::File.join(Chef::Config[:file_cache_path], 'file.tar.gz') do
|
154
|
+
source 'http://www.example.org/file.tar.gz'
|
155
|
+
end
|
156
|
+
|
157
|
+
#### Actions
|
158
|
+
|
159
|
+
* `:create`: Default. Use to create a file. If a file already exists (but does
|
160
|
+
not match), use to update that file to match.
|
161
|
+
* `:create_if_missing`: Use to create a file only if the file does not exist.
|
162
|
+
(When the file exists, nothing happens.)
|
163
|
+
* `:delete`: Use to delete a file.
|
164
|
+
* `:touch`: Use to touch a file. This updates the access (atime) and file
|
165
|
+
modification (mtime) times for a file. (This action may be used with this
|
166
|
+
resource, but is typically only used with the file resource.)
|
167
|
+
|
168
|
+
#### Attribute Parameters
|
169
|
+
|
170
|
+
* `backup`: The number of backups to be kept. Set to false to prevent backups
|
171
|
+
from being kept. Default value: 5.
|
172
|
+
* `checksum`: Optional, allows for conditional gets. The SHA-256 checksum of
|
173
|
+
the file. Use to prevent the `download` resource from re-downloading a file.
|
174
|
+
When the local file matches the checksum, it will not be downloaded.
|
175
|
+
* `connections`: Download a file using N connections. If more than N URIs are
|
176
|
+
given, first N URIs are used and remaining URIs are used for backup. If less
|
177
|
+
than N URIs are given, those URIs are used more than once so that N
|
178
|
+
connections total are made simultaneously. Default: 5.
|
179
|
+
* `group`: A string or ID that identifies the group owner by group name. If
|
180
|
+
this value is not specified, existing groups will remain unchanged and new
|
181
|
+
group assignments will use the default POSIX group (if available).
|
182
|
+
* `max_connections`: The maximum number of connections to one server for each
|
183
|
+
download. Default: 5.
|
184
|
+
* `mode`: A quoted string that defines the octal mode for a file. If mode is
|
185
|
+
not specified and if the file already exists, the existing mode on the file
|
186
|
+
is used. If mode is not specified, the file does not exist, and the :create
|
187
|
+
action is specified, the chef-client will assume a mask value of "0777" and
|
188
|
+
then apply the umask for the system on which the file will be created to the
|
189
|
+
mask value. For example, if the umask on a system is "022", the chef-client
|
190
|
+
would use the default value of "0755".
|
191
|
+
* `owner`: A string or ID that identifies the group owner by user name. If
|
192
|
+
this value is not specified, existing owners will remain unchanged and new
|
193
|
+
owner assignments will use the current user (when necessary).
|
194
|
+
* `path`: The full path to the file, including the file name and its
|
195
|
+
extension. Default value: the name of the resource block.
|
196
|
+
* `source`: name attribute. The location (URI) of the source file. This value
|
197
|
+
may also specify HTTP (http://), FTP (ftp://), or local (file://) source
|
198
|
+
file locations.
|
199
|
+
|
200
|
+
#### Examples
|
201
|
+
|
202
|
+
The following examples demonstrate various approaches for using resources in
|
203
|
+
recipes. If you want to see examples of how Chef uses resources in recipes, take
|
204
|
+
a closer look at the cookbooks that Chef authors and maintains: https://
|
205
|
+
github.com/opscode-cookbooks.
|
206
|
+
|
207
|
+
##### Transfer a file from a URL
|
208
|
+
|
209
|
+
download '/tmp/testfile' do
|
210
|
+
source 'http://www.example.com/tempfiles/testfile'
|
211
|
+
mode 00644
|
212
|
+
checksum '3a7dac00b1' # A SHA256 (or portion thereof) of the file.
|
213
|
+
end
|
214
|
+
|
215
|
+
##### Transfer a file only when the source has changed
|
216
|
+
|
217
|
+
download '/tmp/file.png' do
|
218
|
+
source 'http://example.com/file.png'
|
219
|
+
action :nothing
|
220
|
+
end
|
221
|
+
|
222
|
+
http_request 'HEAD //example.com/file.png' do
|
223
|
+
message ''
|
224
|
+
url '//example.com/file.png'
|
225
|
+
action :head
|
226
|
+
if ::File.exists?('/tmp/file.png')
|
227
|
+
header "If-Modified-Since" => ::File.mtime("/tmp/file.png").httpdate
|
228
|
+
end
|
229
|
+
notifies :create, 'download[http://example.com/file.png]', :immediately
|
230
|
+
end
|
231
|
+
|
232
|
+
##### Install a file from a remote location using bash
|
233
|
+
|
234
|
+
The following is an example of how to install the foo123 module for Nginx. This
|
235
|
+
module adds shell-style functionality to an Nginx configuration file and does
|
236
|
+
the following:
|
237
|
+
|
238
|
+
* Declares three variables;
|
239
|
+
* Gets the Nginx file from a remote location;
|
240
|
+
* Installs the file to the path specified by the `src_path` variable.
|
241
|
+
|
242
|
+
The following code sample is similar to the `upload_progress_module` recipe in
|
243
|
+
the [nginx](https://github.com/opscode-cookbooks/nginx) cookbook.
|
244
|
+
|
245
|
+
src_file = "foo123-nginx-module-v#{node[:nginx][:foo123][:version]}.tar.gz"
|
246
|
+
src_path = ::File.join(Chef::Config[:file_cache_path], src_file)
|
247
|
+
extract_path = ::File.join(Chef::Config[:file_cache_path],
|
248
|
+
'nginx_foo123_module', node[:nginx][:foo123][:checksum]
|
249
|
+
)
|
250
|
+
|
251
|
+
download src_path do
|
252
|
+
source node[:nginx][:foo123][:url]
|
253
|
+
checksum node[:nginx][:foo123][:checksum]
|
254
|
+
owner 'root'
|
255
|
+
group 'root'
|
256
|
+
mode 00644
|
257
|
+
end
|
258
|
+
|
259
|
+
bash 'extract module' do
|
260
|
+
cwm ::File.dirname(src_path)
|
261
|
+
code <<-CODE
|
262
|
+
mkdir -p #{extract_path}
|
263
|
+
tar xzf #{src_file} -C #{extract_path}
|
264
|
+
mv #{extract_path}/*/* #{extract_path}/
|
265
|
+
CODE
|
266
|
+
not_if { ::File.exist?(extract_path) }
|
267
|
+
end
|
268
|
+
|
269
|
+
### zip_file
|
270
|
+
|
271
|
+
This resource provides a pure-ruby implementation for managing zip files. Be
|
272
|
+
sure to use the not_if or only_if meta parameters to guard the resource for
|
273
|
+
idempotence or action will be taken every Chef run.
|
274
|
+
|
275
|
+
#### Syntax
|
276
|
+
|
277
|
+
The syntax for using the `zip_file` resource in a recipe is as follows:
|
278
|
+
|
279
|
+
zip_file 'name' do
|
280
|
+
attribute 'value' # see attributes section below
|
281
|
+
...
|
282
|
+
action :action # see actions section below
|
283
|
+
end
|
284
|
+
|
285
|
+
Where:
|
286
|
+
|
287
|
+
* `zip_file` tells the chef-client to use the `Chef::Provider::ZipFile`
|
288
|
+
provider during the chef-client run;
|
289
|
+
* `name` is the name of the resource block; when the `path` attribute is not
|
290
|
+
specified as part of a recipe, `name` is also the path where files will be
|
291
|
+
(un)zipped to;
|
292
|
+
* `attribute` is zero (or more) of the attributes that are available for this
|
293
|
+
resource;
|
294
|
+
* `:action` identifies which steps the chef-client will take to bring the node
|
295
|
+
into the desired state.
|
296
|
+
|
297
|
+
For example:
|
298
|
+
|
299
|
+
zip_file '/tmp/path' do
|
300
|
+
source 'http://www.example.org/file.tar.gz'
|
301
|
+
end
|
302
|
+
|
303
|
+
#### Actions
|
304
|
+
|
305
|
+
* `:unzip`: unzip a compressed file.
|
306
|
+
* `:zip`: zip a directory (recursively).
|
307
|
+
|
308
|
+
#### Attribute Parameters
|
309
|
+
|
310
|
+
* `checksum`: for :unzip, useful if source is remote, if the local file
|
311
|
+
matches the SHA-256 checksum, Chef will not download it.
|
312
|
+
* `group`: A string or ID that identifies the group owner by group name. If
|
313
|
+
this value is not specified, existing groups will remain unchanged and new
|
314
|
+
group assignments will use the default POSIX group (if available).
|
315
|
+
* `mode`: A quoted string that defines the octal mode for a file. If mode is
|
316
|
+
not specified and if the file already exists, the existing mode on the file
|
317
|
+
is used. If mode is not specified, the file does not exist, and the :create
|
318
|
+
action is specified, the chef-client will assume a mask value of "0777" and
|
319
|
+
then apply the umask for the system on which the file will be created to the
|
320
|
+
mask value. For example, if the umask on a system is "022", the chef-client
|
321
|
+
would use the default value of "0755".
|
322
|
+
* `overwrite`: force an overwrite of the files if they already exist.
|
323
|
+
* `owner`: A string or ID that identifies the group owner by user name. If
|
324
|
+
this value is not specified, existing owners will remain unchanged and new
|
325
|
+
owner assignments will use the current user (when necessary).
|
326
|
+
* `path`: name attribute. The path where files will be (un)zipped to.
|
327
|
+
* `remove_after`: If the zip file should be removed once it has been unzipped.
|
328
|
+
Default is false.
|
329
|
+
* `source`: The source of the zip file (either a URI or local
|
330
|
+
path) for :unzip, or directory to be zipped for :zip.
|
331
|
+
|
332
|
+
#### Examples
|
333
|
+
|
334
|
+
The following examples demonstrate various approaches for using resources in
|
335
|
+
recipes. If you want to see examples of how Chef uses resources in recipes, take
|
336
|
+
a closer look at the cookbooks that Chef authors and maintains: https://
|
337
|
+
github.com/opscode-cookbooks.
|
338
|
+
|
339
|
+
##### Unzip a remote zip file locally
|
340
|
+
|
341
|
+
zip_file '/opt/app' do
|
342
|
+
source 'http://example.com/app.zip'
|
343
|
+
owner 'app_user'
|
344
|
+
group 'app_group'
|
345
|
+
action :unzip
|
346
|
+
not_if { ::File.exist?('/opt/app/bin/startup.sh') }
|
347
|
+
end
|
348
|
+
|
349
|
+
##### Unzip a local zipfile
|
350
|
+
|
351
|
+
zip_file '/home/foo' do
|
352
|
+
source '/tmp/something.zip'
|
353
|
+
action :unzip
|
354
|
+
end
|
355
|
+
|
356
|
+
##### Create a local zipfile
|
357
|
+
|
358
|
+
zip_file '/tmp/foo.zip' do
|
359
|
+
source '/home/foo'
|
360
|
+
action :zip
|
361
|
+
end
|
362
|
+
|
363
|
+
## Testing
|
364
|
+
|
365
|
+
Ensure you have all the required prerequisite listed in the Development
|
366
|
+
Requirements section. You should have a working Vagrant installation with either VirtualBox or VMware installed. From the parent directory of this cookbook begin by running bundler to ensure you have all the required Gems:
|
367
|
+
|
368
|
+
bundle install
|
369
|
+
|
370
|
+
A ruby environment with Bundler installed is a prerequisite for using the testing harness shipped with this cookbook. At the time of this writing, it works with Ruby 2.1.2 and Bundler 1.6.2. All programs involved, with the exception of Vagrant and VirtualBox, can be installed by cd'ing into the parent directory of this cookbook and running 'bundle install'.
|
371
|
+
|
372
|
+
#### Vagrant and VirtualBox
|
373
|
+
|
374
|
+
The installation of Vagrant and VirtualBox is extremely complex and involved. Please be prepared to spend some time at your computer:
|
375
|
+
|
376
|
+
If you have not yet installed Homebrew do so now:
|
377
|
+
|
378
|
+
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
|
379
|
+
|
380
|
+
Next install Homebrew Cask:
|
381
|
+
|
382
|
+
brew tap phinze/homebrew-cask && brew install brew-cask
|
383
|
+
|
384
|
+
Then, to get Vagrant installed run this command:
|
385
|
+
|
386
|
+
brew cask install vagrant
|
387
|
+
|
388
|
+
Finally install VirtualBox:
|
389
|
+
|
390
|
+
brew cask install virtualbox
|
391
|
+
|
392
|
+
You will also need to get the Berkshelf and Omnibus plugins for Vagrant:
|
393
|
+
|
394
|
+
vagrant plugin install vagrant-berkshelf
|
395
|
+
vagrant plugin install vagrant-omnibus
|
396
|
+
|
397
|
+
Try doing that on Windows.
|
398
|
+
|
399
|
+
#### Rakefile
|
400
|
+
|
401
|
+
The Rakefile ships with a number of tasks, each of which can be ran individually, or in groups. Typing `rake` by itself will perform style checks with [Rubocop](https://github.com/bbatsov/rubocop) and [Foodcritic](http://www.foodcritic.io), [Chefspec](http://sethvargo.github.io/chefspec/) with rspec, and integration with [Test Kitchen](http://kitchen.ci) using the Vagrant driver by default. Alternatively, integration tests can be ran with Test Kitchen cloud drivers for EC2 are provided.
|
402
|
+
|
403
|
+
$ rake -T
|
404
|
+
rake all # Run all tasks
|
405
|
+
rake chefspec # Run RSpec code examples
|
406
|
+
rake doc # Build documentation
|
407
|
+
rake foodcritic # Lint Chef cookbooks
|
408
|
+
rake kitchen:all # Run all test instances
|
409
|
+
rake kitchen:apps-dir-centos-65 # Run apps-dir-centos-65 test instance
|
410
|
+
rake kitchen:default-centos-65 # Run default-centos-65 test instance
|
411
|
+
rake kitchen:ihs-centos-65 # Run ihs-centos-65 test instance
|
412
|
+
rake kitchen:was-centos-65 # Run was-centos-65 test instance
|
413
|
+
rake kitchen:wps-centos-65 # Run wps-centos-65 test instance
|
414
|
+
rake readme # Generate README.md from _README.md.erb
|
415
|
+
rake rubocop # Run RuboCop
|
416
|
+
rake rubocop:auto_correct # Auto-correct RuboCop offenses
|
417
|
+
rake test # Run all tests except `kitchen` / Run
|
418
|
+
# kitchen integration tests
|
419
|
+
rake yard # Generate YARD Documentation
|
420
|
+
|
421
|
+
#### Style Testing
|
422
|
+
|
423
|
+
Ruby style tests can be performed by Rubocop by issuing either the bundled binary or with the Rake task:
|
424
|
+
|
425
|
+
$ bundle exec rubocop
|
426
|
+
or
|
427
|
+
$ rake style:ruby
|
428
|
+
|
429
|
+
Chef style tests can be performed with Foodcritic by issuing either:
|
430
|
+
|
431
|
+
$ bundle exec foodcritic
|
432
|
+
or
|
433
|
+
$ rake style:chef
|
434
|
+
|
435
|
+
### Testing
|
436
|
+
|
437
|
+
This cookbook uses Test Kitchen to verify functionality.
|
438
|
+
|
439
|
+
1. Install [ChefDK](http://downloads.getchef.com/chef-dk/)
|
440
|
+
2. Activate ChefDK's copy of ruby: `eval "$(chef shell-init bash)"`
|
441
|
+
3. `bundle install`
|
442
|
+
4. `bundle exec kitchen test kitchen:default-centos-65`
|
443
|
+
|
444
|
+
#### Spec Testing
|
445
|
+
|
446
|
+
Unit testing is done by running Rspec examples. Rspec will test any libraries, then test recipes using ChefSpec. This works by compiling a recipe (but not converging it), and allowing the user to make assertions about the resource_collection.
|
447
|
+
|
448
|
+
#### Integration Testing
|
449
|
+
|
450
|
+
Integration testing is performed by Test Kitchen. Test Kitchen will use either the Vagrant driver or EC2 cloud driver to instantiate machines and apply cookbooks. After a successful converge, tests are uploaded and ran out of band of Chef. Tests are be designed to
|
451
|
+
ensure that a recipe has accomplished its goal.
|
452
|
+
|
453
|
+
#### Integration Testing using Vagrant
|
454
|
+
|
455
|
+
Integration tests can be performed on a local workstation using Virtualbox or VMWare. Detailed instructions for setting this up can be found at the [Bento](https://github.com/opscode/bento) project web site. Integration tests using Vagrant can be performed with either:
|
456
|
+
|
457
|
+
$ bundle exec kitchen test
|
458
|
+
or
|
459
|
+
$ rake integration:vagrant
|
460
|
+
|
461
|
+
#### Integration Testing using EC2 Cloud provider
|
462
|
+
|
463
|
+
Integration tests can be performed on an EC2 providers using Test Kitchen plugins. This cookbook references environmental variables present in the shell that `kitchen test` is ran from. These must contain authentication tokens for driving APIs, as well as the paths to ssh private keys needed for Test Kitchen log into them after they've been created.
|
464
|
+
|
465
|
+
Examples of environment variables being set in `~/.bash_profile`:
|
466
|
+
|
467
|
+
# aws
|
468
|
+
export AWS_ACCESS_KEY_ID='your_bits_here'
|
469
|
+
export AWS_SECRET_ACCESS_KEY='your_bits_here'
|
470
|
+
export AWS_KEYPAIR_NAME='your_bits_here'
|
471
|
+
|
472
|
+
Integration tests using cloud drivers can be performed with either
|
473
|
+
|
474
|
+
$ bundle exec kitchen test
|
475
|
+
or
|
476
|
+
$ rake integration:cloud
|
477
|
+
|
478
|
+
### Guard
|
479
|
+
|
480
|
+
Guard tasks have been separated into the following groups:
|
481
|
+
|
482
|
+
* `doc`
|
483
|
+
* `lint`
|
484
|
+
* `unit`
|
485
|
+
* `integration`
|
486
|
+
|
487
|
+
By default, Guard will generate documentation, lint, and run unit tests.
|
488
|
+
The integration group must be selected manually with `guard -g integration`.
|
489
|
+
|
490
|
+
## Contributing
|
491
|
+
|
492
|
+
Please see the [CONTRIBUTING.md](CONTRIBUTING.md).
|
493
|
+
|
494
|
+
## License and Authors
|
495
|
+
|
496
|
+
Author:: Stefano Harding <riddopic@gmail.com>
|
497
|
+
|
498
|
+
Copyright:: 2014-2015, Stefano Harding
|
499
|
+
|
500
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
501
|
+
you may not use this file except in compliance with the License.
|
502
|
+
You may obtain a copy of the License at
|
503
|
+
|
504
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
505
|
+
|
506
|
+
Unless required by applicable law or agreed to in writing, software
|
507
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
508
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
509
|
+
See the License for the specific language governing permissions and
|
510
|
+
limitations under the License.
|
511
|
+
|
512
|
+
- - -
|
513
|
+
|
514
|
+
[Berkshelf]: http://berkshelf.com "Berkshelf"
|
515
|
+
[Chef]: https://www.getchef.com "Chef"
|
516
|
+
[ChefDK]: https://www.getchef.com/downloads/chef-dk "Chef Development Kit"
|
517
|
+
[Chef Documentation]: http://docs.opscode.com "Chef Documentation"
|
518
|
+
[ChefSpec]: http://chefspec.org "ChefSpec"
|
519
|
+
[Foodcritic]: http://foodcritic.io "Foodcritic"
|
520
|
+
[Learn Chef]: http://learn.getchef.com "Learn Chef"
|
521
|
+
[Test Kitchen]: http://kitchen.ci "Test Kitchen"
|