knife-manage 0.0.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/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +91 -0
- data/Rakefile +23 -0
- data/knife-manage.gemspec +25 -0
- data/lib/chef/knife/configure_file_list.rb +22 -0
- data/lib/chef/knife/configure_file_set.rb +53 -0
- data/lib/chef/knife/configure_file_show.rb +20 -0
- data/lib/chef/knife/manage_base.rb +49 -0
- data/lib/knife-manage.rb +7 -0
- data/lib/knife-manage/version.rb +5 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1fdc85f1084523172a99406b0087acc31474d616
|
4
|
+
data.tar.gz: cc5a9ff78d46fcc8820fa25f123c9bfe6924181e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e98c0315381aecc6fdbe4a63b4bf358f1474cfe022a0bcf0d6f81bb57adc79fc6baa91c578946d8013771dfc1e243de0b50f49af3ea1a1cda8e7cb3bd407b09d
|
7
|
+
data.tar.gz: 9765b90601847bb8fd283eb7dd84ba19699cb4bbb9dca959d641152bfb698445c98f62743563170ed24dcc656379be314c1fae739f88a610bf3258dfc3f16f0f
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ryan Cragun
|
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,91 @@
|
|
1
|
+
# knife-manage
|
2
|
+
|
3
|
+
Do you manage several chef servers? Do you ever get sick of
|
4
|
+
specifying a path to the chef server _every_ time you want to use knife? If
|
5
|
+
you answered yes then this is this plugin for you.
|
6
|
+
|
7
|
+
## Requirements
|
8
|
+
The Ruby in the plugin is 1.8.7 compliant and only uses a single standard lib so
|
9
|
+
this should work with Chef 10.x and Chef 11.x, though I've only tested in on
|
10
|
+
11.12.x. If you find a bug please open an issue.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
```shell
|
14
|
+
$: gem install knife-manage
|
15
|
+
```
|
16
|
+
|
17
|
+
or for the fancy kids using the chefdk:
|
18
|
+
|
19
|
+
```
|
20
|
+
$: chef gem install knife-manage
|
21
|
+
```
|
22
|
+
|
23
|
+
or if you wanna get super crazy and build from source:
|
24
|
+
|
25
|
+
```shell
|
26
|
+
$: git clone https://github.com/ryancragun/knife-manage
|
27
|
+
$: cd knife-manage
|
28
|
+
$: bundle exec rake build
|
29
|
+
$: gem install pkg/*gem
|
30
|
+
```
|
31
|
+
|
32
|
+
## Configuration
|
33
|
+
knife-manage expects that you keep your knife configuration files in a central
|
34
|
+
repository (~/.chef) with a common naming scheme. If you have multiple knife
|
35
|
+
file locations don't sweat it. We've got ya covered.
|
36
|
+
|
37
|
+
The naming scheme that is expected is `knife_ORGNAME.rb` where `ORGNAME` is the
|
38
|
+
unique identifier for that knife configuration file. If you use a dash in the
|
39
|
+
name `knife-foo.rb` or nothing `knifebar.rb` it should still work okay.
|
40
|
+
|
41
|
+
## Usage
|
42
|
+
```shell
|
43
|
+
$: knife configure file $COMMAND [OPTIONS]
|
44
|
+
```
|
45
|
+
|
46
|
+
**list**
|
47
|
+
all available configuration files in the default directory
|
48
|
+
```shell
|
49
|
+
$: knife configure file list
|
50
|
+
foo
|
51
|
+
bar
|
52
|
+
```
|
53
|
+
|
54
|
+
**show**
|
55
|
+
which file is currently being used
|
56
|
+
```shell
|
57
|
+
$: knife configure file show
|
58
|
+
foo
|
59
|
+
```
|
60
|
+
|
61
|
+
**set**
|
62
|
+
the configuration file you want to use
|
63
|
+
```shell
|
64
|
+
$: knife configure file set bar
|
65
|
+
bar
|
66
|
+
```
|
67
|
+
|
68
|
+
If you want to specify a different directory to look for files use the
|
69
|
+
`--file-dir` switch:
|
70
|
+
|
71
|
+
```shell
|
72
|
+
$: knife configure file list --file-dir ~/code/project/.chef
|
73
|
+
project
|
74
|
+
$: knife configure file set --file-dir ~/code/project/.chef project
|
75
|
+
project
|
76
|
+
```
|
77
|
+
|
78
|
+
knife-manage uses symlinks to point `~/.chef/knife.rb` to the config file of
|
79
|
+
your choice. The first time you use the utility it might complain about the
|
80
|
+
file not being a symlink. Don't worry, if you use the `--force` switch it'll
|
81
|
+
backup the file and create a symlink.
|
82
|
+
|
83
|
+
## Contributing
|
84
|
+
|
85
|
+
1. Fork it ( https://github.com/[my-github-username]/knife-manage/fork )
|
86
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
87
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
88
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
89
|
+
5. Create a new Pull Request
|
90
|
+
|
91
|
+
Happy Cheffing
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rubygems/package_task'
|
4
|
+
require 'rdoc/task'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
|
7
|
+
Bundler::GemHelper.install_tasks
|
8
|
+
|
9
|
+
task :default => :spec
|
10
|
+
|
11
|
+
desc 'Run specs'
|
12
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
13
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
14
|
+
end
|
15
|
+
|
16
|
+
gem_spec = eval(File.read('knife-manage.gemspec'))
|
17
|
+
|
18
|
+
RDoc::Task.new do |rdoc|
|
19
|
+
rdoc.rdoc_dir = 'rdoc'
|
20
|
+
rdoc.title = "chef_fs #{gem_spec.version}"
|
21
|
+
rdoc.rdoc_files.include('README*')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'knife-manage/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "knife-manage"
|
8
|
+
spec.version = Knife::Manage::VERSION
|
9
|
+
spec.authors = ["Ryan Cragun"]
|
10
|
+
spec.email = ["me@ryan.ec"]
|
11
|
+
spec.summary = %q{Manage multiple knife configuration files}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = 'https://github.com/ryancragun/knife-manage'
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'chef'
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
require 'chef/knife/manage_base'
|
3
|
+
|
4
|
+
class Chef
|
5
|
+
class Knife
|
6
|
+
class ConfigureFileList < Chef::Knife
|
7
|
+
include Knife::ManageBase
|
8
|
+
|
9
|
+
banner 'knife configure file list (options)'
|
10
|
+
|
11
|
+
def run
|
12
|
+
list_files
|
13
|
+
end
|
14
|
+
|
15
|
+
def list_files
|
16
|
+
knife_files.each do |file|
|
17
|
+
show_knife(file.basename.to_s) unless file.symlink? && file.basename.to_s == 'knife.rb'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
require 'chef/knife/manage_base'
|
3
|
+
|
4
|
+
class Chef
|
5
|
+
class Knife
|
6
|
+
class ConfigureFileSet < Chef::Knife
|
7
|
+
include Knife::ManageBase
|
8
|
+
|
9
|
+
banner 'knife configure file set [CONFIG] (options)'
|
10
|
+
|
11
|
+
option :force,
|
12
|
+
:long => '--force',
|
13
|
+
:boolean => true,
|
14
|
+
:default => false,
|
15
|
+
:description => 'Force overwrite knife.rb if it is not a symlink (default: false)'
|
16
|
+
|
17
|
+
def run
|
18
|
+
set_default
|
19
|
+
end
|
20
|
+
|
21
|
+
def verify_args
|
22
|
+
if name_args.count < 1
|
23
|
+
ui.error 'You must supply a configuration file as an argument'
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
if default_file.exist? && !default_file.symlink? && !config[:force]
|
28
|
+
ui.error 'The default file is not a symlink. Use --force to overwrite it.'
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_default
|
34
|
+
verify_args
|
35
|
+
new_config = name_args[0]
|
36
|
+
new_file = knife_files.select { |f| f.basename.to_s.include?(new_config) }.first
|
37
|
+
if !new_file
|
38
|
+
ui.error "Could not find a #{new_config} configuration file."
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
|
42
|
+
if default_file.symlink?
|
43
|
+
default_file.unlink
|
44
|
+
elsif default_file.exist?
|
45
|
+
default_file.rename("#{config_dir}/knife.rb.bak")
|
46
|
+
end
|
47
|
+
|
48
|
+
default_file.make_symlink(new_file)
|
49
|
+
show_knife(default_file.realpath.basename.to_s)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
require 'chef/knife/manage_base'
|
3
|
+
|
4
|
+
class Chef
|
5
|
+
class Knife
|
6
|
+
class ConfigureFileShow < Chef::Knife
|
7
|
+
include Knife::ManageBase
|
8
|
+
|
9
|
+
banner 'knife configure file show (options)'
|
10
|
+
|
11
|
+
def run
|
12
|
+
show_default
|
13
|
+
end
|
14
|
+
|
15
|
+
def show_default
|
16
|
+
show_knife(default_file.realpath.basename.to_s)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
module ManageBase
|
6
|
+
|
7
|
+
def self.included(klass)
|
8
|
+
klass.class_eval do
|
9
|
+
|
10
|
+
deps do
|
11
|
+
require 'pathname'
|
12
|
+
end
|
13
|
+
|
14
|
+
option :file_dir,
|
15
|
+
:long => '--file-dir DIRECTORY',
|
16
|
+
:description => 'Path to knife.rb configuration files directory (default: ~/.chef)'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def config_dir
|
21
|
+
@dir ||= config[:file_dir] || "#{ENV['HOME']}/.chef"
|
22
|
+
if !::File.directory?(@dir)
|
23
|
+
ui.error "Could not locate configuration files because #{@dir} doesn't exist. Use --file-dir to specify where your knife files live"
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
@dir
|
27
|
+
end
|
28
|
+
|
29
|
+
def knife_files
|
30
|
+
@files ||= Pathname.new(config_dir).children.select do |file|
|
31
|
+
file.basename.to_s =~ /^(knife)(?:_?|-?)(\w+)?.rb$/
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def default_file
|
36
|
+
@default ||= Pathname.new("#{config_dir}/knife.rb")
|
37
|
+
end
|
38
|
+
|
39
|
+
def show_knife(basename)
|
40
|
+
basename =~ /^(knife)(?:_?|-?)(\w+)?.rb$/
|
41
|
+
if $2
|
42
|
+
puts "#{$2}\n"
|
43
|
+
elsif $1
|
44
|
+
puts "default\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/knife-manage.rb
ADDED
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-manage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Cragun
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: chef
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Manage multiple knife configuration files
|
70
|
+
email:
|
71
|
+
- me@ryan.ec
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- knife-manage.gemspec
|
82
|
+
- lib/chef/knife/configure_file_list.rb
|
83
|
+
- lib/chef/knife/configure_file_set.rb
|
84
|
+
- lib/chef/knife/configure_file_show.rb
|
85
|
+
- lib/chef/knife/manage_base.rb
|
86
|
+
- lib/knife-manage.rb
|
87
|
+
- lib/knife-manage/version.rb
|
88
|
+
homepage: https://github.com/ryancragun/knife-manage
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.2.2
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Manage multiple knife configuration files
|
112
|
+
test_files: []
|