knife-support 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chef/knife/support.rb +165 -0
- metadata +58 -0
@@ -0,0 +1,165 @@
|
|
1
|
+
# Author:: Paul Mooring <paul@opscode.com>
|
2
|
+
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module KnifeSuppport
|
19
|
+
class Support < Chef::Knife
|
20
|
+
banner "knife support [HOST] (options)"
|
21
|
+
|
22
|
+
# Don't lazy load or you'll get an error
|
23
|
+
require 'chef/environment'
|
24
|
+
require 'chef/node'
|
25
|
+
require 'chef/role'
|
26
|
+
require 'chef/api_client'
|
27
|
+
# Do lazy load this stuff
|
28
|
+
deps do
|
29
|
+
require 'chef/knife/ssh'
|
30
|
+
require 'chef/mixin/command'
|
31
|
+
require 'net/ssh'
|
32
|
+
require 'net/ssh/multi'
|
33
|
+
end
|
34
|
+
|
35
|
+
[:knife, :nodes, :roles, :environments, :clients, :databags].each do |opt|
|
36
|
+
option opt,
|
37
|
+
:short => "-#{opt.to_s[0]}",
|
38
|
+
:long => "--#{opt.to_s}",
|
39
|
+
:boolean => true,
|
40
|
+
:description => "Include details on #{opt.to_s}"
|
41
|
+
end
|
42
|
+
|
43
|
+
option :all,
|
44
|
+
:short => '-a',
|
45
|
+
:long => '--all',
|
46
|
+
:boolean => true,
|
47
|
+
:description => "Include everything (except data bags)"
|
48
|
+
|
49
|
+
option :really_all,
|
50
|
+
:short => '-A',
|
51
|
+
:long => '--really-all',
|
52
|
+
:boolean => true,
|
53
|
+
:description => "Include everything (including data bags)"
|
54
|
+
|
55
|
+
option :ssh_user,
|
56
|
+
:short => "-x USERNAME",
|
57
|
+
:long => "--ssh-user USERNAME",
|
58
|
+
:description => "The ssh username"
|
59
|
+
|
60
|
+
option :ssh_password,
|
61
|
+
:short => "-P PASSWORD",
|
62
|
+
:long => "--ssh-password PASSWORD",
|
63
|
+
:description => "The ssh password"
|
64
|
+
|
65
|
+
option :ssh_port,
|
66
|
+
:short => "-p PORT",
|
67
|
+
:long => "--ssh-port PORT",
|
68
|
+
:description => "The ssh port",
|
69
|
+
:default => "22",
|
70
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key }
|
71
|
+
|
72
|
+
option :connect_attribute,
|
73
|
+
:short => "-C ATTR",
|
74
|
+
:long => "--connect-attribute ATTR",
|
75
|
+
:description => "The attribute to use for opening the connection - default is fqdn",
|
76
|
+
:default => "fqdn"
|
77
|
+
|
78
|
+
option :use_sudo,
|
79
|
+
:long => "--sudo",
|
80
|
+
:description => "Execute the bootstrap via sudo",
|
81
|
+
:boolean => true
|
82
|
+
|
83
|
+
option :host_key_verify,
|
84
|
+
:long => "--[no-]host-key-verify",
|
85
|
+
:description => "Verify host key, enabled by default.",
|
86
|
+
:boolean => true,
|
87
|
+
:default => true
|
88
|
+
|
89
|
+
[Chef::Environment, Chef::Role, Chef::Node, Chef::ApiClient, Chef::DataBag].each do |klass|
|
90
|
+
component = klass.to_s.downcase.gsub("chef::", "").concat('s')
|
91
|
+
define_method "get_#{component}".to_sym do
|
92
|
+
msg "==== #{component} ===="
|
93
|
+
klass.list.each do |name, uri|
|
94
|
+
msg "=== #{name} ==="
|
95
|
+
output format_for_display(klass.load(name))
|
96
|
+
msg "=== End #{name} ==="
|
97
|
+
end
|
98
|
+
msg "==== End #{component} ===="
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def knife_ssh(host)
|
103
|
+
command = if config[:use_sudo]
|
104
|
+
"sudo chef-client -l debug"
|
105
|
+
else
|
106
|
+
"chef-client -l debug"
|
107
|
+
end
|
108
|
+
|
109
|
+
ssh = Chef::Knife::Ssh.new
|
110
|
+
ssh.ui = ui
|
111
|
+
ssh.name_args = [ host, command ]
|
112
|
+
ssh.config[:ssh_user] = config[:ssh_user]
|
113
|
+
ssh.config[:ssh_user] ||= 'root'
|
114
|
+
ssh.config[:ssh_password] = config[:ssh_password]
|
115
|
+
ssh.config[:ssh_port] = Chef::Config[:knife][:ssh_port] || config[:ssh_port]
|
116
|
+
ssh.config[:identity_file] = config[:identity_file]
|
117
|
+
ssh.config[:manual] = true
|
118
|
+
ssh.config[:host_key_verify] = config[:host_key_verify]
|
119
|
+
ssh.config[:on_error] = :raise
|
120
|
+
ssh.config[:attribute] = config[:connect_attribute]
|
121
|
+
begin
|
122
|
+
ssh.run
|
123
|
+
rescue Net::SSH::AuthenticationFailed
|
124
|
+
if ssh.config[:ssh_password].nil?
|
125
|
+
msg "Failed to authenticate #{config[:ssh_user]} - trying password auth"
|
126
|
+
config[:ssh_password] ||= ui.ask("Enter your password: ") { |q| q.echo = false }
|
127
|
+
knife_ssh(host)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def get_config
|
133
|
+
msg "==== configuration ===="
|
134
|
+
msg "=== config ==="
|
135
|
+
pp config
|
136
|
+
msg "=== End config ==="
|
137
|
+
msg "=== Chef::Config ==="
|
138
|
+
pp Chef::Config.configuration
|
139
|
+
msg "=== End Chef::Config ==="
|
140
|
+
msg "==== End configuration ===="
|
141
|
+
end
|
142
|
+
|
143
|
+
def run
|
144
|
+
unless config[:knife] or config[:nodes] or config[:roles] or config[:environments] or config[:clients] or config[:databags]
|
145
|
+
config[:all] = true
|
146
|
+
end
|
147
|
+
if config[:really_all]
|
148
|
+
config[:all] = true
|
149
|
+
warn "The --really-all will include your data bags and data contained in them."
|
150
|
+
confirm "Do you want to continue"
|
151
|
+
elsif config[:databags]
|
152
|
+
warn "The --databags will include your data bags and data contained in them."
|
153
|
+
confirm "Do you want to continue"
|
154
|
+
end
|
155
|
+
|
156
|
+
get_config if config[:knife] or config[:all]
|
157
|
+
get_nodes if config[:nodes] or config[:all]
|
158
|
+
get_roles if config[:roles] or config[:all]
|
159
|
+
get_environments if config[:environments] or config[:all]
|
160
|
+
get_apiclients if config[:clients] or config[:all]
|
161
|
+
get_databags if config[:databags] or config[:really_all]
|
162
|
+
knife_ssh name_args.first if name_args.first
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-support
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Paul Mooring
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-17 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chef
|
16
|
+
requirement: &70102066264120 !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: *70102066264120
|
25
|
+
description: Knife plugin for getting detailed org information output
|
26
|
+
email:
|
27
|
+
- paul@opscode.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- lib/chef/knife/support.rb
|
33
|
+
homepage: https://github.com/paulmooring/knife-support
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.17
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: Knife plugin for getting detailed org information output
|
57
|
+
test_files: []
|
58
|
+
has_rdoc:
|