chef-rewind 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chef-edit.gemspec
4
+ gemspec :name => "chef-rewind"
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Bryan Berry
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # Chef::Rewind
2
+
3
+ This adds a simple function to the Chef library scope to
4
+ rewind an existing resource. If the given resource does not exist,
5
+ a Chef::Exceptions::ResourceNotFound exception will be raised.
6
+
7
+ This function is designed to assist the library cookbook pattern.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'chef-rewind'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install chef-rewind
22
+
23
+ ## Usage
24
+
25
+ ```Ruby
26
+ # file postgresql/recipes/server.rb
27
+ user "postgres" do
28
+ uid 26
29
+ home '/home/postgres'
30
+ supports :manage_home => true
31
+ end
32
+
33
+ # file my-postgresql/recipes/server.rb
34
+ chef_gem "chef-rewind"
35
+ require 'chef/rewind'
36
+
37
+ include_recipe "postgresql::server"
38
+
39
+ rewind "user[postgres]" do
40
+ home '/var/lib/pgsql/9.2'
41
+ end
42
+
43
+ ```
44
+
45
+ The user "postgres" will act once with the home directory
46
+ '/var/lib/pgsql/9.2 and the cookbook_name attribute is now
47
+ "my-postgresql" instead of "postgresql". This last part is
48
+ particularly important for templates and cookbook files.
49
+
50
+ ## Gotchas *Important*
51
+
52
+ The rewind method does not automatically change the cookbook_name
53
+ attribute for a resource to the current cookbook. Doing so could cause
54
+ some unexpected behavior, particularly for less expert chef users.
55
+
56
+ Example
57
+
58
+ ```Ruby
59
+ # file postgresql/recipes/server.rb
60
+ template "/var/pgsql/data/postgresql.conf" do
61
+ source "postgresql.conf.erb"
62
+ owner "postgres"
63
+ end
64
+
65
+ # file my-postgresql/recipes/server.rb
66
+ chef_gem "chef-rewind"
67
+ require 'chef/rewind'
68
+
69
+ include_recipe "postgresql::server"
70
+ # my-postgresql.conf.erb located inside my-postgresql/templates/default/my-postgresql.conf.erb
71
+ rewind :template => "/var/pgsql/data/postgresql.conf" do
72
+ source "my-postgresql.conf.erb"
73
+ cookbook_name "my-postgresql"
74
+ end
75
+
76
+ ```
77
+
78
+ If you do not specify cookbook_name the rewind function will likely
79
+ return an error since Chef will look in the postgresql cookbook for
80
+ the source file and not in the my-postgresql cookbook.
81
+
82
+
83
+ ## Contributing
84
+
85
+ 1. Fork it
86
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
87
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
88
+ 4. Push to the branch (`git push origin my-new-feature`)
89
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.unshift(File.dirname(__FILE__) + '/lib')
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Bryan Berry"]
5
+ gem.email = ["bryan.berry@gmail.com"]
6
+ gem.description = %q{Monkey patches Chef to allow rewinding of existing resources}
7
+ gem.summary = %q{Monkey patches Chef to allow rewinding of existing resources}
8
+ gem.homepage = ""
9
+
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "chef-rewind"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = "0.0.5"
16
+ end
@@ -0,0 +1,44 @@
1
+ # modeled closely after
2
+ # https://github.com/opscode/chef/blob/master/lib/chef/dsl/recipe.rb
3
+ # and https://github.com/opscode/chef/blob/master/lib/chef/recipe.rb
4
+
5
+ class Chef
6
+ class Recipe
7
+
8
+ # rewinds an existing resource if it exists,
9
+ # otherwise raises the Chef::Exceptions::ResourceNotFound exception
10
+ # For example:
11
+ # # recipe postgresql::server defines user "postgres" and
12
+ # # sets the home directory to /var/pgsql/9.2
13
+ # include_recipe "postgresql::user"
14
+ #
15
+ # rewind "user[postgres]" do
16
+ # home "/home/postgres"
17
+ # end
18
+ # === Parameters
19
+ # resource<String>:: String identifier for resource
20
+ # block<Proc>:: Block with attributes to rewind or create
21
+ def rewind(resource_id, &block)
22
+ begin
23
+ r = resources(resource_id)
24
+ Chef::Log.info "Resource #{resource_id} found, now rewinding it"
25
+ r.instance_exec(&block) if block
26
+ rescue Chef::Exceptions::ResourceNotFound => e
27
+ Chef::Log.info "Resource #{resource_id} not found, so rewind fails"
28
+ raise e
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+
35
+ class Chef
36
+ class Resource
37
+ def cookbook_name(arg=nil)
38
+ set_or_return(
39
+ :cookbook_name,
40
+ arg,
41
+ :kind_of => String)
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chef-rewind
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bryan Berry
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-11 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Monkey patches Chef to allow rewinding of existing resources
15
+ email:
16
+ - bryan.berry@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - chef-rewind.gemspec
27
+ - lib/chef/rewind.rb
28
+ homepage: ''
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 1.8.23
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Monkey patches Chef to allow rewinding of existing resources
52
+ test_files: []
53
+ has_rdoc: