chef-fork 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fde528113e145397075b09d8fb0acf5c4761fcb9
4
+ data.tar.gz: 4276edcd1989f0f75cf1be4beee09dc101b47ed7
5
+ SHA512:
6
+ metadata.gz: b6bda285ea2d5ec7b4df7af95ce3f422994f0450b110d5d8ff6ed7ac9f32381260f19a626fdd2e60b8470393430a50e76d5e6103a6d81f0af25ec32144e9c57f
7
+ data.tar.gz: 990b36264081d96946ecba6bfd981a68d63080deae6d149320b9d115e639367d47637f46d4b617b2c5cb0d945ad1e1cff10df91cdc851fbdbb90a1fb1a23b403
@@ -0,0 +1,11 @@
1
+ *.swo
2
+ *.swp
3
+ /.bundle/
4
+ /.yardoc
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chef-fork.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,37 @@
1
+ # chef-fork
2
+
3
+ A tool for your left hand, to have a meal cooked by chef.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'chef-fork'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install chef-fork
20
+
21
+ ## Usage
22
+
23
+ TODO
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/yyuu/chef-fork/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
3
+
4
+ # bundler/setup doesn't work expectedly when installed via gem
5
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
6
+ require "bundler/setup"
7
+
8
+ require "chef/fork"
9
+ Chef::Fork.new.main(ARGV.dup)
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chef/fork/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chef-fork"
8
+ spec.version = Chef::Fork::VERSION
9
+ spec.authors = ["Yamashita Yuu"]
10
+ spec.email = ["peek824545201@gmail.com"]
11
+
12
+ spec.summary = %q{A tool for your left hand, to have a meal cooked by chef.}
13
+ spec.description = %q{A tool for your left hand, to have a meal cooked by chef.}
14
+ spec.homepage = "https://github.com/yyuu/chef-fork"
15
+ spec.license = "Apache-2.0"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+
25
+ spec.add_dependency "chef", ">= 11.18.0"
26
+ spec.add_dependency "erubis", ">= 2.7"
27
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require "chef/fork/application"
5
+
6
+ class Chef
7
+ class Fork
8
+ def initialize()
9
+ @application = Chef::Fork::Application.new()
10
+ end
11
+
12
+ def main(args=[])
13
+ @application.main(args)
14
+ end
15
+ end
16
+ end
17
+
18
+ # vim:set ft=ruby :
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require "chef"
5
+ require "logger"
6
+ require "optparse"
7
+ require "chef/fork/commands"
8
+ require "chef/fork/version"
9
+
10
+ class Chef
11
+ class Fork
12
+ class Application
13
+ def initialize()
14
+ @logger = Logger.new(STDERR)
15
+ @optparse = OptionParser.new
16
+ @optparse.version = "#{Chef::Fork::VERSION} (chef #{Chef::VERSION})"
17
+ @options = {}
18
+ define_options
19
+ end
20
+ attr_reader :options
21
+ attr_reader :optparse
22
+
23
+ def main(args=[])
24
+ configure_chef(locate_config_file("fork") || locate_config_file("knife"))
25
+ rest = @optparse.order(args)
26
+ begin
27
+ command = get_command(rest.shift || "help").new(self)
28
+ command.run(rest)
29
+ rescue Errno::EPIPE
30
+ # noop
31
+ end
32
+ end
33
+
34
+ private
35
+ def define_options()
36
+ options.merge!({
37
+ editor: ENV["EDITOR"],
38
+ verbose: false,
39
+ })
40
+ optparse.on("-c CONFIG", "--config CONFIG", "The configuration file to use") do |value|
41
+ options[:config_file] = value
42
+ end
43
+
44
+ optparse.on("-V", "--[no-]verbose", "Run verbosely") do |value|
45
+ options[:verbose] = value
46
+ end
47
+
48
+ optparse.on("-E ENVIRONMENT", "--environment ENVIRONMENT", "Set the Chef environment") do |value|
49
+ options[:environment] = value
50
+ end
51
+
52
+ optparse.on("-e EDITOR", "--editor EDITOR", "Set the editor to use for interactive commands") do |value|
53
+ options[:editor] = value
54
+ end
55
+
56
+ optparse.on("-u USER", "--user USER", "API Client Username") do |value|
57
+ options[:node_name] = value
58
+ end
59
+
60
+ optparse.on("-k KEY", "--key KEY", "API Client Key") do |value|
61
+ options[:client_key] = value
62
+ end
63
+
64
+ optparse.on("-s URL", "--server-url URL", "Chef Server URL") do |value|
65
+ options[:chef_server_url] = value
66
+ end
67
+ end
68
+
69
+ def locate_config_file(name)
70
+ if options.key?(:config_file)
71
+ options[:config_file]
72
+ else
73
+ candidate_configs = []
74
+ if ENV.key?("#{name.upcase}_HOME")
75
+ candidate_config << File.join(File.expand_path(ENV["#{name.upcase}_CONFIG"]), "#{name.downcase}.rb")
76
+ end
77
+ candidate_configs << File.expand_path("#{name.downcase}.rb")
78
+ if config_dir = chef_config_dir(Dir.pwd)
79
+ candidate_configs << File.join(config_dir, "#{name.downcase}.rb")
80
+ end
81
+ if ENV.key?("HOME")
82
+ candidate_configs << File.join(File.expand_path(ENV["HOME"]), "#{name.downcase}.rb")
83
+ end
84
+ candidate_configs.find { |candidate_config| File.exist?(candidate_config) }
85
+ end
86
+ end
87
+
88
+ def chef_config_dir(path)
89
+ config_dir = File.join(path, ".chef")
90
+ if File.exist?(config_dir)
91
+ return config_dir
92
+ else
93
+ if path == "/"
94
+ return nil
95
+ else
96
+ return chef_config_dir(File.dirname(path))
97
+ end
98
+ end
99
+ end
100
+
101
+ def configure_chef(config_file)
102
+ if config_file
103
+ @logger.info("Using configuration from #{config_file}")
104
+ Chef::Config.from_file(config_file)
105
+ else
106
+ @logger.warn("No fork/knife configuration file found")
107
+ end
108
+ # override with command-line options
109
+ Chef::Config.merge!(options)
110
+ end
111
+
112
+ def get_command(name)
113
+ begin
114
+ require "chef/fork/commands/#{name}"
115
+ rescue LoadError
116
+ # ignore LoadError for built-in commands
117
+ end
118
+ class_name = name.to_s.split(/[^\w]+/).map { |s| s.capitalize }.join
119
+ begin
120
+ Chef::Fork::Commands.const_get(class_name)
121
+ rescue NameError
122
+ require "chef/fork/commands/help"
123
+ Chef::Fork::Commands::Help
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ class Chef
5
+ class Fork
6
+ module Commands
7
+ class Noop
8
+ def initialize(application)
9
+ @application = application
10
+ define_options
11
+ end
12
+
13
+ def run(args=[])
14
+ rest = @application.optparse.order(args)
15
+ end
16
+
17
+ private
18
+ def define_options()
19
+ command_name = self.class.to_s.split("::").last.scan(/[A-Z][0-9_a-z]*/).join("-").downcase
20
+ optparse.banner = "Usage: #{File.basename($0)} #{command_name} [OPTIONS]"
21
+ end
22
+
23
+ def options()
24
+ @application.options
25
+ end
26
+
27
+ def optparse()
28
+ @application.optparse
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require "chef"
5
+ require "chef/knife/core/bootstrap_context"
6
+ require "erubis"
7
+ require "json"
8
+ require "shellwords"
9
+ require "chef/fork/commands/ssh"
10
+
11
+ class Chef
12
+ class Fork
13
+ module Commands
14
+ class Bootstrap < Ssh
15
+ def run(args=[])
16
+ rest = optparse.order(args)
17
+ hostname = rest.shift
18
+ command = bootstrap_command()
19
+ ssh(hostname, [command])
20
+ end
21
+
22
+ private
23
+ def define_options
24
+ super
25
+ options.merge!({
26
+ distro: "chef-full",
27
+ first_boot_attributes: {},
28
+ run_list: [],
29
+ use_sudo: true,
30
+ })
31
+
32
+ optparse.on("-N NAME", "--node-name NAME", "The Chef node name for new node") do |value|
33
+ options[:chef_node_name] = value
34
+ end
35
+
36
+ optparse.on("--bootstrap-version VERSION", "The version of Chef to install") do |value|
37
+ options[:bootstrap_version] = value
38
+ end
39
+
40
+ optparse.on("--bootstrap-proxy PROXY_URL", "The proxy server for the node being bootstrapped") do |value|
41
+ options[:bootstrap_proxy] = value
42
+ end
43
+
44
+ optparse.on("-d DISTRO", "--distro DISTRO", "Bootstrap a distro using a template") do |value|
45
+ options[:distro] = value
46
+ end
47
+
48
+ optparse.on("--sudo", "Execute the bootstrap via sudo") do |value|
49
+ options[:use_sudo] = value
50
+ end
51
+
52
+ optparse.on("--template-file TEMPLATE", "Full path to location of template to use") do |value|
53
+ options[:template_file] = value
54
+ end
55
+
56
+ optparse.on("-r RUN_LIST", "--run-list RUN_LIST", "Comma separated list of roles/recipes to apply") do |value|
57
+ options[:run_list] += value.split(",").map { |s| s.strip }
58
+ end
59
+
60
+ optparse.on("-j JSON_ATTRIBS", "--json-attributes JSON_ATTRIBS", "A JSON string to be added to the first run of chef-client") do |value|
61
+ options[:first_boot_attributes] = options[:first_boot_attributes].merge(JSON.parse(value))
62
+ end
63
+
64
+ optparse.on("-s SECRET", "--secret SECRET", "The secret key to use to encrypt data bag item values") do |value|
65
+ options[:secret] = value
66
+ end
67
+
68
+ optparse.on("--secret-file SECRET_FILE", "A file containing the secret key to use to encrypt data bag item values") do |value|
69
+ options[:secret_file] = value
70
+ end
71
+ end
72
+
73
+ def bootstrap_command()
74
+ template_file = options[:template_file] || find_template(options[:distro])
75
+ if template_file
76
+ template = File.read(template_file)
77
+ render_template(template)
78
+ else
79
+ raise(NameError.new("Unknown distro: #{distro.inspect}"))
80
+ end
81
+ end
82
+
83
+ def find_template(name)
84
+ templates = $LOAD_PATH.map { |path| File.join(path, "chef", "knife", "bootstrap", "templates", "#{name}.erb") }
85
+ templates.find { |path| File.exist?(path) }
86
+ end
87
+
88
+ def render_template(template)
89
+ context = Chef::Knife::Core::BootstrapContext.new(options, options[:run_list], Chef::Config)
90
+ Erubis::Eruby.new(template).evaluate(context)
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require "chef/fork/commands"
5
+
6
+ class Chef
7
+ class Fork
8
+ module Commands
9
+ class Cookbook < Noop
10
+ def run(args=[])
11
+ case args.first
12
+ when "show"
13
+ cookbook_show(args.slice(1..-1))
14
+ when "upload"
15
+ cookbook_upload(args.slice(1..-1))
16
+ else
17
+ raise(NameError.new(args.inspect))
18
+ end
19
+ end
20
+
21
+ private
22
+ def cookbook_show(args=[])
23
+ raise(NotImplementedError.new(args.inspect))
24
+ end
25
+
26
+ def cookbook_upload(args=[])
27
+ raise(NotImplementedError.new(args.inspect))
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require "chef/fork/commands"
5
+
6
+ class Chef
7
+ class Fork
8
+ module Commands
9
+ class Data < Noop
10
+ def run(args=[])
11
+ case args.first
12
+ when "bag"
13
+ data_bag(args.slice(1..-1))
14
+ else
15
+ raise(NameError.new(args.inspect))
16
+ end
17
+ end
18
+
19
+ private
20
+ def data_bag(args=[])
21
+ case args.first
22
+ when "from"
23
+ data_bag_from(args.slice(1..-1))
24
+ when "show"
25
+ data_bag_show(args.slice(1..-1))
26
+ else
27
+ raise(NameError.new(args.inspect))
28
+ end
29
+ end
30
+
31
+ def data_bag_from(args=[])
32
+ case args.first
33
+ when "file"
34
+ data_bag_from_file(args.slice(1..-1))
35
+ else
36
+ raise(NameError.new(args.inspect))
37
+ end
38
+ end
39
+
40
+ def data_bag_from_file(args=[])
41
+ raise(NotImplementedError.new(args.inspect))
42
+ end
43
+
44
+ def data_bag_show(args=[])
45
+ raise(NotImplementedError.new(args.inspect))
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require "chef/fork/commands/data"
5
+
6
+ class Chef
7
+ class Fork
8
+ module Commands
9
+ class Databag < Data
10
+ def run(args=[])
11
+ data_bag(args)
12
+ end
13
+
14
+ private
15
+ def data_bag(args=[])
16
+ case args.first
17
+ when "from"
18
+ data_bag_from(args.slice(1..-1))
19
+ when "show"
20
+ data_bag_show(args.slice(1..-1))
21
+ else
22
+ raise(NameError.new(args.inspect))
23
+ end
24
+ end
25
+
26
+ def data_bag_from(args=[])
27
+ case args.first
28
+ when "file"
29
+ data_bag_from_file(args.slice(1..-1))
30
+ else
31
+ raise(NameError.new(args.inspect))
32
+ end
33
+ end
34
+
35
+ def data_bag_from_file(args=[])
36
+ raise(NotImplementedError.new(args.inspect))
37
+ end
38
+
39
+ def data_bag_show(args=[])
40
+ raise(NotImplementedError.new(args.inspect))
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require "chef/fork/commands"
5
+
6
+ class Chef
7
+ class Fork
8
+ module Commands
9
+ class Environment < Noop
10
+ def run(args=[])
11
+ case args.first
12
+ when "from"
13
+ environment_from(args.slice(1..-1))
14
+ when "show"
15
+ environment_show(args.slice(1..-1))
16
+ else
17
+ raise(NameError.new(args.inspect))
18
+ end
19
+ end
20
+
21
+ private
22
+ def environment_from(args=[])
23
+ case args.first
24
+ when "file"
25
+ environment_from_file(args.slice(1..-1))
26
+ else
27
+ raise(NameError.new(args.inspect))
28
+ end
29
+ end
30
+
31
+ def environment_from_file(args=[])
32
+ raise(NotImplementedError.new(args.inspect))
33
+ end
34
+
35
+ def environment_show(args=[])
36
+ raise(NotImplementedError.new(args.inspect))
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require "rbconfig"
5
+ require "chef/fork/commands"
6
+
7
+ class Chef
8
+ class Fork
9
+ module Commands
10
+ class Help < Noop
11
+ def run(args=[])
12
+ ruby = File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"])
13
+ exit(system(ruby, $0, "--help") ? 0 : 1)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require "chef/fork/commands"
5
+
6
+ class Chef
7
+ class Fork
8
+ module Commands
9
+ class Role < Noop
10
+ def run(args=[])
11
+ case args.first
12
+ when "from"
13
+ role_from(args.slice(1..-1))
14
+ when "show"
15
+ role_show(args.slice(1..-1))
16
+ else
17
+ raise(NameError.new(args.inspect))
18
+ end
19
+ end
20
+
21
+ def role_from(args=[])
22
+ case args.shift
23
+ when "file"
24
+ rome_from_file(args.slice(1..-1))
25
+ else
26
+ raise(NameError.new(args.inspect))
27
+ end
28
+ end
29
+
30
+ def role_from_file(args=[])
31
+ raise(NotImplementedError.new(args.inspect))
32
+ end
33
+
34
+ def role_show(args=[])
35
+ raise(NotImplementedError.new(args.inspect))
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require "shellwords"
5
+ require "chef/fork/commands"
6
+
7
+ class Chef
8
+ class Fork
9
+ module Commands
10
+ class Ssh < Noop
11
+ def run(args=[])
12
+ rest = optparse.order(args)
13
+ hostname = rest.shift
14
+ ssh(hostname, rest)
15
+ end
16
+
17
+ private
18
+ def define_options
19
+ super
20
+ options.merge!({
21
+ forward_agent: false,
22
+ host_key_verify: false,
23
+ ssh_config: "/dev/null",
24
+ ssh_user: "root",
25
+ })
26
+
27
+ optparse.on("--ssh-config CONFIGFILE", "The ssh configuration file") do |value|
28
+ options[:ssh_config] = value
29
+ end
30
+
31
+ optparse.on("-x USERNAME", "--ssh-user USERNAME", "The ssh username") do |value|
32
+ options[:ssh_user] = value
33
+ end
34
+
35
+ optparse.on("-p PORT", "--ssh-port PORT", "The ssh port") do |value|
36
+ options[:ssh_port] = value
37
+ end
38
+
39
+ optparse.on("-G GATEWAY", "--ssh-gateway GATEWAY", "The ssh gateway") do |value|
40
+ options[:ssh_gateway] = value
41
+ end
42
+
43
+ optparse.on("-A", "--[no-]forward-agent", "Enable SSH agent forwarding") do |value|
44
+ options[:forward_agent] = value
45
+ end
46
+
47
+ optparse.on("-i IDENTITY_FILE", "--identity-file IDENTITY_FILE") do |value|
48
+ options[:identity_file] = value
49
+ end
50
+
51
+ optparse.on("--[no-]host-key-verify", "Verify host key, disabled by default") do |value|
52
+ options[:host_key_verify] = value
53
+ end
54
+
55
+ optparse.on("--[no-]dry-run", "Don't take action, only print what would happen") do |value|
56
+ options[:dry_run] = value
57
+ end
58
+ end
59
+
60
+ def ssh(hostname, args=[])
61
+ command = ssh_command(hostname, args)
62
+ if options[:dry_run]
63
+ STDOUT.puts(command)
64
+ else
65
+ exec(command)
66
+ exit(127)
67
+ end
68
+ end
69
+
70
+ def ssh_command(hostname, args=[])
71
+ ssh_options = [
72
+ options[:forward_agent] ? "-A" : "-a",
73
+ "-F",
74
+ options[:ssh_config],
75
+ ]
76
+
77
+ if options[:ssh_user]
78
+ ssh_options << "-l"
79
+ ssh_options << options[:ssh_user]
80
+ end
81
+
82
+ if options[:ssh_port]
83
+ ssh_options << "-p"
84
+ ssh_options << options[:ssh_port]
85
+ end
86
+
87
+ if options[:ssh_gateway]
88
+ proxy_host_port, proxy_user = options[:ssh_gateway].split("@", 2).reverse
89
+ proxy_host, proxy_port = proxy_host_port.split(":", 2)
90
+ if not proxy_user and options[:ssh_user]
91
+ proxy_user = options[:ssh_user]
92
+ end
93
+ proxy_options = [
94
+ "-F",
95
+ options[:ssh_config],
96
+ ]
97
+ proxy_options << "-W" << "%h:%p"
98
+ if options[:identity_file]
99
+ proxy_options << "-i" << options[:identity_file]
100
+ end
101
+ if proxy_user
102
+ proxy_options << "-l" << proxy_user
103
+ end
104
+ if proxy_port
105
+ proxy_options << "-p" << proxy_port
106
+ end
107
+ if not options[:host_key_verify]
108
+ proxy_options << "-o" << "UserKnownHostsFile=/dev/null"
109
+ proxy_options << "-o" << "StrictHostKeyChecking=no"
110
+ end
111
+ ssh_options << "-o" << "ProxyCommand=ssh #{Shellwords.shelljoin(proxy_options)} #{Shellwords.shellescape(proxy_host)}"
112
+ end
113
+
114
+ if options[:identity_file]
115
+ ssh_options << "-i"
116
+ ssh_options << options[:identity_file]
117
+ end
118
+
119
+ if not options[:host_key_verify]
120
+ ssh_options << "-o" << "UserKnownHostsFile=/dev/null"
121
+ ssh_options << "-o" << "StrictHostKeyChecking=no"
122
+ end
123
+
124
+ if options[:verbose]
125
+ ssh_options << "-v"
126
+ end
127
+
128
+ if args.empty?
129
+ "ssh #{Shellwords.shelljoin(ssh_options)} -- #{Shellwords.shellescape(hostname)}"
130
+ else
131
+ "ssh #{Shellwords.shelljoin(ssh_options)} -- #{Shellwords.shellescape(hostname)} #{Shellwords.shelljoin(args)}"
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,5 @@
1
+ class Chef
2
+ class Fork
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chef-fork
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yamashita Yuu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: chef
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 11.18.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 11.18.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: erubis
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '2.7'
69
+ description: A tool for your left hand, to have a meal cooked by chef.
70
+ email:
71
+ - peek824545201@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - bin/fork
83
+ - chef-fork.gemspec
84
+ - lib/chef/fork.rb
85
+ - lib/chef/fork/application.rb
86
+ - lib/chef/fork/commands.rb
87
+ - lib/chef/fork/commands/bootstrap.rb
88
+ - lib/chef/fork/commands/cookbook.rb
89
+ - lib/chef/fork/commands/data.rb
90
+ - lib/chef/fork/commands/databag.rb
91
+ - lib/chef/fork/commands/environment.rb
92
+ - lib/chef/fork/commands/help.rb
93
+ - lib/chef/fork/commands/role.rb
94
+ - lib/chef/fork/commands/ssh.rb
95
+ - lib/chef/fork/version.rb
96
+ homepage: https://github.com/yyuu/chef-fork
97
+ licenses:
98
+ - Apache-2.0
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.2.3
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: A tool for your left hand, to have a meal cooked by chef.
120
+ test_files: []
121
+ has_rdoc: