chef-recipe 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/bin/chef-recipe +25 -0
- data/chef-recipe.gemspec +20 -0
- data/lib/chef/application/recipe.rb +126 -0
- data/lib/chef-recipe/version.rb +5 -0
- data/lib/chef-recipe.rb +7 -0
- metadata +121 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
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,35 @@
|
|
1
|
+
# chef-recipe
|
2
|
+
|
3
|
+
This gem installs chef-recipe, a command-line to help you start
|
4
|
+
learning Chef as quickly as possible. This is an education tool meant
|
5
|
+
to new Chef users started as quickly as possible.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'chef-recipe'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install chef-recipe
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
`chef-recipe RECIPE_FILE`
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
32
|
+
|
33
|
+
## Authorship
|
34
|
+
|
35
|
+
This gem is based on a [gist](https://gist.github.com/2920702) written by Daniel DeLeo
|
data/Rakefile
ADDED
data/bin/chef-recipe
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# ./chef-recipe - Run a single chef recipe, for educational purposes
|
4
|
+
#
|
5
|
+
# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
|
6
|
+
# Copyright:: Copyright (c) 2012 Bryan W. Berry
|
7
|
+
# License:: Apache License, Version 2.0
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
|
21
|
+
require 'rubygems'
|
22
|
+
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
23
|
+
require 'chef/application/recipe'
|
24
|
+
|
25
|
+
Chef::Application::Recipe.new.run
|
data/chef-recipe.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/chef-recipe/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Bryan Berry"]
|
6
|
+
gem.email = ["bryan.berry@gmail.com"]
|
7
|
+
gem.description = %q{command to execute a single chef recipe}
|
8
|
+
gem.summary = %q{This gem installs a command that can be used to execute a single chef recipe}
|
9
|
+
gem.homepage = "https://github.com/bryanwb/chef-recipe"
|
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.add_dependency "chef"
|
14
|
+
%w(rspec-core rspec-expectations rspec-mocks).each { |g| gem.add_development_dependency g, "~> 2.8.0" }
|
15
|
+
gem.bindir = "bin"
|
16
|
+
gem.executables = %w( chef-recipe )
|
17
|
+
gem.name = "chef-recipe"
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.version = Chef::Recipe::VERSION
|
20
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
|
3
|
+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
|
4
|
+
# Copyright:: Copyright (c) 2012 Bryan W. Berry
|
5
|
+
# Copyright:: Copyright (c) 2012 Daniel DeLeo
|
6
|
+
# License:: Apache License, Version 2.0
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
|
20
|
+
require 'chef'
|
21
|
+
require 'chef/application'
|
22
|
+
require 'chef/client'
|
23
|
+
require 'chef/config'
|
24
|
+
require 'chef/log'
|
25
|
+
require 'fileutils'
|
26
|
+
require 'chef/providers'
|
27
|
+
require 'chef/resources'
|
28
|
+
|
29
|
+
class Chef::Application::Recipe < Chef::Application
|
30
|
+
|
31
|
+
banner "Usage: chef-recipe RECIPE_FILE"
|
32
|
+
|
33
|
+
|
34
|
+
option :log_level,
|
35
|
+
:short => "-l LEVEL",
|
36
|
+
:long => "--log_level LEVEL",
|
37
|
+
:description => "Set the log level (debug, info, warn, error, fatal)",
|
38
|
+
:proc => lambda { |l| l.to_sym }
|
39
|
+
|
40
|
+
option :help,
|
41
|
+
:short => "-h",
|
42
|
+
:long => "--help",
|
43
|
+
:description => "Show this message",
|
44
|
+
:on => :tail,
|
45
|
+
:boolean => true,
|
46
|
+
:show_options => true,
|
47
|
+
:exit => 0
|
48
|
+
|
49
|
+
option :version,
|
50
|
+
:short => "-v",
|
51
|
+
:long => "--version",
|
52
|
+
:description => "Show chef version",
|
53
|
+
:boolean => true,
|
54
|
+
:proc => lambda {|v| puts "Chef: #{::Chef::VERSION}"},
|
55
|
+
:exit => 0
|
56
|
+
|
57
|
+
option :why_run,
|
58
|
+
:short => '-W',
|
59
|
+
:long => '--why-run',
|
60
|
+
:description => 'Enable whyrun mode',
|
61
|
+
:boolean => true
|
62
|
+
|
63
|
+
def initialize
|
64
|
+
super
|
65
|
+
end
|
66
|
+
|
67
|
+
def reconfigure
|
68
|
+
configure_logging
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
class Chef::Client
|
73
|
+
attr_reader :events
|
74
|
+
end
|
75
|
+
|
76
|
+
def find_recipe(recipe_path)
|
77
|
+
if recipe_path.nil?
|
78
|
+
STDERR.puts banner
|
79
|
+
exit 1
|
80
|
+
elsif !::File.exist?(recipe_path)
|
81
|
+
STDERR.puts "No file at #{recipe_path}"
|
82
|
+
STDERR.puts banner
|
83
|
+
exit 1
|
84
|
+
end
|
85
|
+
recipe_path = File.expand_path(recipe_path)
|
86
|
+
end
|
87
|
+
|
88
|
+
def run_chef_recipe
|
89
|
+
recipe_path = ARGV[0]
|
90
|
+
recipe_path = find_recipe recipe_path
|
91
|
+
Chef::Config[:solo] = true
|
92
|
+
client = Chef::Client.new
|
93
|
+
client.run_ohai
|
94
|
+
client.build_node
|
95
|
+
run_context = if client.events.nil?
|
96
|
+
Chef::RunContext.new(client.node, {})
|
97
|
+
else
|
98
|
+
Chef::RunContext.new(client.node, {}, client.events)
|
99
|
+
end
|
100
|
+
|
101
|
+
recipe = Chef::Recipe.new("(chef-recipe cookbook)", "(chef-recipe recipe)", run_context)
|
102
|
+
recipe.from_file(recipe_path)
|
103
|
+
|
104
|
+
runner = Chef::Runner.new(run_context)
|
105
|
+
runner.converge
|
106
|
+
end
|
107
|
+
|
108
|
+
def run_application
|
109
|
+
begin
|
110
|
+
run_chef_recipe
|
111
|
+
Chef::Application.exit! "Exiting", 0
|
112
|
+
rescue SystemExit => e
|
113
|
+
raise
|
114
|
+
rescue Exception => e
|
115
|
+
Chef::Application.debug_stacktrace(e)
|
116
|
+
Chef::Application.fatal!("#{e.class}: #{e.message}", 1)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Get this party started
|
121
|
+
def run
|
122
|
+
reconfigure
|
123
|
+
run_application
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
data/lib/chef-recipe.rb
ADDED
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chef-recipe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bryan Berry
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chef
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec-core
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.8.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.8.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec-expectations
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.8.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.8.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec-mocks
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.8.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.8.0
|
78
|
+
description: command to execute a single chef recipe
|
79
|
+
email:
|
80
|
+
- bryan.berry@gmail.com
|
81
|
+
executables:
|
82
|
+
- chef-recipe
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- bin/chef-recipe
|
92
|
+
- chef-recipe.gemspec
|
93
|
+
- lib/chef-recipe.rb
|
94
|
+
- lib/chef-recipe/version.rb
|
95
|
+
- lib/chef/application/recipe.rb
|
96
|
+
homepage: https://github.com/bryanwb/chef-recipe
|
97
|
+
licenses: []
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 1.8.23
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: This gem installs a command that can be used to execute a single chef recipe
|
120
|
+
test_files: []
|
121
|
+
has_rdoc:
|