knife-zero 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +43 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +109 -0
- data/Rakefile +2 -0
- data/knife-zero.gemspec +25 -0
- data/lib/chef/knife/bootstrap/chef-full-localmode.erb +75 -0
- data/lib/chef/knife/zero_base.rb +69 -0
- data/lib/chef/knife/zero_bootstrap.rb +132 -0
- data/lib/knife-zero/bootstrap_ssh.rb +76 -0
- data/lib/knife-zero/common.rb +7 -0
- data/lib/knife-zero/core/bootstrap_context.rb +20 -0
- data/lib/knife-zero/version.rb +6 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f5e2d9755e4e6f715cd77516dc2fb0d6f79d4c07
|
4
|
+
data.tar.gz: fce3c2e244371f998167e360afb7c97bf80e776f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f31dac88e7c0f4ada81fbba4310f0c1ed2c5adf2b48684beb19b5644b4a4aff9a4d35333e02ec05daf718a2054d3957afcd96f7678ff363cedd7de5d008886c4
|
7
|
+
data.tar.gz: bc0b9977368987df43e7f2d6bad671436bcad7a5e4a42aba4223b1257c89700e3dbf70c4639cf4feb018f29b5252c3818d48a8c4c047767d2ed576adcb6ff260
|
data/.gitignore
ADDED
@@ -0,0 +1,43 @@
|
|
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
|
23
|
+
# Created by http://www.gitignore.io
|
24
|
+
|
25
|
+
### vim ###
|
26
|
+
[._]*.s[a-w][a-z]
|
27
|
+
[._]s[a-w][a-z]
|
28
|
+
*.un~
|
29
|
+
Session.vim
|
30
|
+
.netrwhist
|
31
|
+
*~
|
32
|
+
|
33
|
+
## Development
|
34
|
+
|
35
|
+
.rvmrc
|
36
|
+
|
37
|
+
## Integration
|
38
|
+
nodes/
|
39
|
+
roles/
|
40
|
+
environments/
|
41
|
+
data_bags/
|
42
|
+
clients/
|
43
|
+
cookbooks/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2014 sawanoboly@higanworks.com
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Knife-Plugin Zero
|
2
|
+
|
3
|
+
Run chef-client at remote node with chef-zero(local-mode) via HTTP over SSH port fowarding.
|
4
|
+
|
5
|
+
- It doesn't have to transport cookbooks via scp,rsync or something.
|
6
|
+
- It can collect node object into local chef-repo.
|
7
|
+
- It supports all functioanly of chef(C/S).
|
8
|
+
- You have only to manage one chef-repo.
|
9
|
+
|
10
|
+
## Requirements
|
11
|
+
|
12
|
+
- Must support AllowTcpForward
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
> This gem has not been released yet.
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
gem 'knife-zero'
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install knife-zero
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
```
|
33
|
+
** ZERO COMMANDS **
|
34
|
+
knife zero bootstrap FQDN (options)
|
35
|
+
```
|
36
|
+
|
37
|
+
### Bootstrap
|
38
|
+
|
39
|
+
Install Chef to remote node and run chef-client under chef-zero via tcp-forward.
|
40
|
+
|
41
|
+
Supported options are mostly the same as `knife bootstrap`.
|
42
|
+
|
43
|
+
|
44
|
+
#### Example
|
45
|
+
|
46
|
+
```
|
47
|
+
$ bundle exec knife zero bootstrap host.example.com -r hogehoge::default --no-host-key-verify
|
48
|
+
Connecting to host.example.com
|
49
|
+
host.example.com Installing Chef Client...
|
50
|
+
-- snip --
|
51
|
+
host.example.com Thank you for installing Chef!
|
52
|
+
|
53
|
+
host.example.com Starting first Chef Client run...
|
54
|
+
host.example.com Starting Chef Client, version 11.14.6
|
55
|
+
host.example.com Creating a new client identity for host.example.com using the validator key.
|
56
|
+
|
57
|
+
## Resolv and sync cookbook via http over ssh tcp-forward by run-list.
|
58
|
+
host.example.com resolving cookbooks for run list: ["hogehoge::default"]
|
59
|
+
host.example.com Synchronizing Cookbooks:
|
60
|
+
host.example.com - hogehoge
|
61
|
+
host.example.com Compiling Cookbooks...
|
62
|
+
host.example.com Converging 0 resources
|
63
|
+
host.example.com
|
64
|
+
host.example.com Running handlers:
|
65
|
+
host.example.com Running handlers complete
|
66
|
+
host.example.com Chef Client finished, 0/0 resources updated in 4.895561879 seconds
|
67
|
+
|
68
|
+
|
69
|
+
## Creates node object into local.
|
70
|
+
$ ls nodes/host.example.com.json
|
71
|
+
nodes/host.example.com.json
|
72
|
+
host.example.com
|
73
|
+
|
74
|
+
## Search by knife with --local--mode option.
|
75
|
+
$ bundle exec knife search node --local-mode
|
76
|
+
1 items found
|
77
|
+
|
78
|
+
Node Name: host.example.com
|
79
|
+
Environment: _default
|
80
|
+
FQDN:
|
81
|
+
IP: xxx.xxx.xxx.xxx
|
82
|
+
Run List: recipe[hogehoge::default]
|
83
|
+
Roles:
|
84
|
+
Recipes: hogehoge::default
|
85
|
+
Platform: ubuntu 12.04
|
86
|
+
Tags:
|
87
|
+
```
|
88
|
+
|
89
|
+
### SSH
|
90
|
+
|
91
|
+
Search nodes from local chef-repo directory, and run command at remote node.
|
92
|
+
|
93
|
+
Supported options are mostly the same as `knife ssh`.
|
94
|
+
|
95
|
+
> Pending
|
96
|
+
|
97
|
+
|
98
|
+
## Contributing
|
99
|
+
|
100
|
+
1. Fork it ( https://github.com/[my-github-username]/knife-zero/fork )
|
101
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
102
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
103
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
104
|
+
5. Create a new Pull Request
|
105
|
+
|
106
|
+
## License
|
107
|
+
|
108
|
+
Licensed under the Apache License, Version 2.0.
|
109
|
+
|
data/Rakefile
ADDED
data/knife-zero.gemspec
ADDED
@@ -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-zero/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "knife-zero"
|
8
|
+
spec.version = Knife::Zero::VERSION
|
9
|
+
spec.authors = ["sawanoboly"]
|
10
|
+
spec.email = ["sawanoboriyu@higanworks.com"]
|
11
|
+
spec.summary = %q{Run chef-client at remote node with chef-zero(local-mode) via HTTP over SSH port fowarding.}
|
12
|
+
spec.description = File.read('README.md')
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "Apache2"
|
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_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "chef", "~> 11.8"
|
25
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
bash -c '
|
2
|
+
<%= "export https_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
|
3
|
+
|
4
|
+
distro=`uname -s`
|
5
|
+
|
6
|
+
if test "x$distro" = "xSunOS"; then
|
7
|
+
if test -d "/usr/sfw/bin"; then
|
8
|
+
PATH=/usr/sfw/bin:$PATH
|
9
|
+
export PATH
|
10
|
+
fi
|
11
|
+
fi
|
12
|
+
|
13
|
+
exists() {
|
14
|
+
if command -v $1 &>/dev/null
|
15
|
+
then
|
16
|
+
return 0
|
17
|
+
else
|
18
|
+
return 1
|
19
|
+
fi
|
20
|
+
}
|
21
|
+
|
22
|
+
<% if knife_config[:bootstrap_install_command] %>
|
23
|
+
<%= knife_config[:bootstrap_install_command] %>
|
24
|
+
<% else %>
|
25
|
+
install_sh="<%= knife_config[:bootstrap_url] ? knife_config[:bootstrap_url] : "https://www.opscode.com/chef/install.sh" %>"
|
26
|
+
version_string="-v <%= chef_version %>"
|
27
|
+
if ! exists /usr/bin/chef-client; then
|
28
|
+
echo "Installing Chef Client..."
|
29
|
+
if exists wget; then
|
30
|
+
bash <(wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %> <%= knife_config[:bootstrap_wget_options] %> ${install_sh} -O -) <%= latest_current_chef_version_string %>
|
31
|
+
elif exists curl; then
|
32
|
+
bash <(curl -L <%= "--proxy \"#{knife_config[:bootstrap_proxy]}\" " if knife_config[:bootstrap_proxy] %> <%= knife_config[:bootstrap_curl_options] %> ${install_sh}) <%= latest_current_chef_version_string %>
|
33
|
+
else
|
34
|
+
echo "Neither wget nor curl found. Please install one and try again." >&2
|
35
|
+
exit 1
|
36
|
+
fi
|
37
|
+
fi
|
38
|
+
<% end %>
|
39
|
+
|
40
|
+
mkdir -p /etc/chef
|
41
|
+
|
42
|
+
cat > /etc/chef/validation.pem <<'EOP'
|
43
|
+
<%= OpenSSL::PKey::RSA.new 2048 %>
|
44
|
+
EOP
|
45
|
+
chmod 0600 /etc/chef/validation.pem
|
46
|
+
|
47
|
+
<% if encrypted_data_bag_secret -%>
|
48
|
+
cat > /etc/chef/encrypted_data_bag_secret <<'EOP'
|
49
|
+
<%= encrypted_data_bag_secret %>
|
50
|
+
EOP
|
51
|
+
chmod 0600 /etc/chef/encrypted_data_bag_secret
|
52
|
+
<% end -%>
|
53
|
+
|
54
|
+
<%# Generate Ohai Hints -%>
|
55
|
+
<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
|
56
|
+
mkdir -p /etc/chef/ohai/hints
|
57
|
+
|
58
|
+
<% @chef_config[:knife][:hints].each do |name, hash| -%>
|
59
|
+
cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
|
60
|
+
<%= hash.to_json %>
|
61
|
+
EOP
|
62
|
+
<% end -%>
|
63
|
+
<% end -%>
|
64
|
+
|
65
|
+
cat > /etc/chef/client.rb <<'EOP'
|
66
|
+
<%= config_content %>
|
67
|
+
EOP
|
68
|
+
|
69
|
+
cat > /etc/chef/first-boot.json <<'EOP'
|
70
|
+
<%= first_boot.to_json %>
|
71
|
+
EOP
|
72
|
+
|
73
|
+
echo "Starting first Chef Client run..."
|
74
|
+
|
75
|
+
<%= start_chef_local %>'
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'chef'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
module ZeroBase
|
6
|
+
def self.included(includer)
|
7
|
+
includer.class_eval do
|
8
|
+
deps do
|
9
|
+
Chef::Config[:local_mode] = true
|
10
|
+
require 'knife-zero/core/bootstrap_context'
|
11
|
+
require 'chef/json_compat'
|
12
|
+
require 'tempfile'
|
13
|
+
require 'highline'
|
14
|
+
require 'net/ssh'
|
15
|
+
Chef::Knife::Ssh.load_deps
|
16
|
+
end
|
17
|
+
|
18
|
+
option :ssh_user,
|
19
|
+
:short => "-x USERNAME",
|
20
|
+
:long => "--ssh-user USERNAME",
|
21
|
+
:description => "The ssh username",
|
22
|
+
:default => "root"
|
23
|
+
|
24
|
+
option :ssh_password,
|
25
|
+
:short => "-P PASSWORD",
|
26
|
+
:long => "--ssh-password PASSWORD",
|
27
|
+
:description => "The ssh password"
|
28
|
+
|
29
|
+
option :identity_file,
|
30
|
+
:short => "-i IDENTITY_FILE",
|
31
|
+
:long => "--identity-file IDENTITY_FILE",
|
32
|
+
:description => "The SSH identity file used for authentication"
|
33
|
+
|
34
|
+
option :ssh_port,
|
35
|
+
:short => "-p PORT",
|
36
|
+
:long => "--ssh-port PORT",
|
37
|
+
:description => "The ssh port",
|
38
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key }
|
39
|
+
|
40
|
+
option :ssh_gateway,
|
41
|
+
:short => "-G GATEWAY",
|
42
|
+
:long => "--ssh-gateway GATEWAY",
|
43
|
+
:description => "The ssh gateway",
|
44
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:ssh_gateway] = key }
|
45
|
+
|
46
|
+
option :forward_agent,
|
47
|
+
:short => "-A",
|
48
|
+
:long => "--forward-agent",
|
49
|
+
:description => "Enable SSH agent forwarding",
|
50
|
+
:boolean => true
|
51
|
+
|
52
|
+
option :host_key_verify,
|
53
|
+
:long => "--[no-]host-key-verify",
|
54
|
+
:description => "Verify host key, enabled by default.",
|
55
|
+
:boolean => true,
|
56
|
+
:default => true
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def locate_config_value(key)
|
64
|
+
key = key.to_sym
|
65
|
+
Chef::Config[:knife][key] || config[key]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
require 'chef/knife/bootstrap'
|
3
|
+
|
4
|
+
class Chef
|
5
|
+
class Knife
|
6
|
+
class ZeroBootstrap < Chef::Knife::Bootstrap
|
7
|
+
include ZeroBase
|
8
|
+
deps do
|
9
|
+
require 'knife-zero/bootstrap_ssh'
|
10
|
+
Chef::Knife::BootstrapSsh.load_deps
|
11
|
+
end
|
12
|
+
|
13
|
+
banner "knife zero bootstrap FQDN (options)"
|
14
|
+
|
15
|
+
option :chef_node_name,
|
16
|
+
:short => "-N NAME",
|
17
|
+
:long => "--node-name NAME",
|
18
|
+
:description => "The Chef node name for your new node"
|
19
|
+
|
20
|
+
option :prerelease,
|
21
|
+
:long => "--prerelease",
|
22
|
+
:description => "Install the pre-release chef gems"
|
23
|
+
|
24
|
+
option :bootstrap_version,
|
25
|
+
:long => "--bootstrap-version VERSION",
|
26
|
+
:description => "The version of Chef to install",
|
27
|
+
:proc => lambda { |v| Chef::Config[:knife][:bootstrap_version] = v }
|
28
|
+
|
29
|
+
option :bootstrap_proxy,
|
30
|
+
:long => "--bootstrap-proxy PROXY_URL",
|
31
|
+
:description => "The proxy server for the node being bootstrapped",
|
32
|
+
:proc => Proc.new { |p| Chef::Config[:knife][:bootstrap_proxy] = p }
|
33
|
+
|
34
|
+
option :bootstrap_no_proxy,
|
35
|
+
:long => "--bootstrap-no-proxy [NO_PROXY_URL|NO_PROXY_IP]",
|
36
|
+
:description => "Do not proxy locations for the node being bootstrapped; this option is used internally by Opscode",
|
37
|
+
:proc => Proc.new { |np| Chef::Config[:knife][:bootstrap_no_proxy] = np }
|
38
|
+
|
39
|
+
## Patched
|
40
|
+
option :distro,
|
41
|
+
:short => "-d DISTRO",
|
42
|
+
:long => "--distro DISTRO",
|
43
|
+
:description => "Bootstrap a distro using a template",
|
44
|
+
:default => "chef-full-localmode"
|
45
|
+
|
46
|
+
option :use_sudo,
|
47
|
+
:long => "--sudo",
|
48
|
+
:description => "Execute the bootstrap via sudo",
|
49
|
+
:boolean => true
|
50
|
+
|
51
|
+
option :use_sudo_password,
|
52
|
+
:long => "--use-sudo-password",
|
53
|
+
:description => "Execute the bootstrap via sudo with password",
|
54
|
+
:boolean => false
|
55
|
+
|
56
|
+
option :template_file,
|
57
|
+
:long => "--template-file TEMPLATE",
|
58
|
+
:description => "Full path to location of template to use",
|
59
|
+
:default => false
|
60
|
+
|
61
|
+
option :run_list,
|
62
|
+
:short => "-r RUN_LIST",
|
63
|
+
:long => "--run-list RUN_LIST",
|
64
|
+
:description => "Comma separated list of roles/recipes to apply",
|
65
|
+
:proc => lambda { |o| o.split(/[\s,]+/) },
|
66
|
+
:default => []
|
67
|
+
|
68
|
+
option :first_boot_attributes,
|
69
|
+
:short => "-j JSON_ATTRIBS",
|
70
|
+
:long => "--json-attributes",
|
71
|
+
:description => "A JSON string to be added to the first run of chef-client",
|
72
|
+
:proc => lambda { |o| Chef::JSONCompat.parse(o) },
|
73
|
+
:default => {}
|
74
|
+
|
75
|
+
option :hint,
|
76
|
+
:long => "--hint HINT_NAME[=HINT_FILE]",
|
77
|
+
:description => "Specify Ohai Hint to be set on the bootstrap target. Use multiple --hint options to specify multiple hints.",
|
78
|
+
:proc => Proc.new { |h|
|
79
|
+
Chef::Config[:knife][:hints] ||= Hash.new
|
80
|
+
name, path = h.split("=")
|
81
|
+
Chef::Config[:knife][:hints][name] = path ? Chef::JSONCompat.parse(::File.read(path)) : Hash.new }
|
82
|
+
|
83
|
+
option :secret,
|
84
|
+
:short => "-s SECRET",
|
85
|
+
:long => "--secret ",
|
86
|
+
:description => "The secret key to use to encrypt data bag item values",
|
87
|
+
:proc => Proc.new { |s| Chef::Config[:knife][:secret] = s }
|
88
|
+
|
89
|
+
option :secret_file,
|
90
|
+
:long => "--secret-file SECRET_FILE",
|
91
|
+
:description => "A file containing the secret key to use to encrypt data bag item values",
|
92
|
+
:proc => Proc.new { |sf| Chef::Config[:knife][:secret_file] = sf }
|
93
|
+
|
94
|
+
option :bootstrap_url,
|
95
|
+
:long => "--bootstrap-url URL",
|
96
|
+
:description => "URL to a custom installation script",
|
97
|
+
:proc => Proc.new { |u| Chef::Config[:knife][:bootstrap_url] = u }
|
98
|
+
|
99
|
+
option :bootstrap_install_command,
|
100
|
+
:long => "--bootstrap-install-command COMMANDS",
|
101
|
+
:description => "Custom command to install chef-client",
|
102
|
+
:proc => Proc.new { |ic| Chef::Config[:knife][:bootstrap_install_command] = ic }
|
103
|
+
|
104
|
+
option :bootstrap_wget_options,
|
105
|
+
:long => "--bootstrap-wget-options OPTIONS",
|
106
|
+
:description => "Add options to wget when installing chef-client",
|
107
|
+
:proc => Proc.new { |wo| Chef::Config[:knife][:bootstrap_wget_options] = wo }
|
108
|
+
|
109
|
+
option :bootstrap_curl_options,
|
110
|
+
:long => "--bootstrap-curl-options OPTIONS",
|
111
|
+
:description => "Add options to curl when install chef-client",
|
112
|
+
:proc => Proc.new { |co| Chef::Config[:knife][:bootstrap_curl_options] = co }
|
113
|
+
|
114
|
+
def knife_ssh
|
115
|
+
ssh = Chef::Knife::BootstrapSsh.new
|
116
|
+
ssh.ui = ui
|
117
|
+
ssh.name_args = [ server_name, ssh_command ]
|
118
|
+
ssh.config[:ssh_user] = Chef::Config[:knife][:ssh_user] || config[:ssh_user]
|
119
|
+
ssh.config[:ssh_password] = config[:ssh_password]
|
120
|
+
ssh.config[:ssh_port] = Chef::Config[:knife][:ssh_port] || config[:ssh_port]
|
121
|
+
ssh.config[:ssh_gateway] = Chef::Config[:knife][:ssh_gateway] || config[:ssh_gateway]
|
122
|
+
ssh.config[:forward_agent] = Chef::Config[:knife][:forward_agent] || config[:forward_agent]
|
123
|
+
ssh.config[:identity_file] = Chef::Config[:knife][:identity_file] || config[:identity_file]
|
124
|
+
ssh.config[:manual] = true
|
125
|
+
ssh.config[:host_key_verify] = Chef::Config[:knife][:host_key_verify] || config[:host_key_verify]
|
126
|
+
ssh.config[:on_error] = :raise
|
127
|
+
ssh
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'chef/knife/ssh'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class BootstrapSsh < Chef::Knife::Ssh
|
6
|
+
def configure_session
|
7
|
+
host, ssh_port = @name_args[0].split(" ")
|
8
|
+
@longest = host.length
|
9
|
+
|
10
|
+
Chef::Log.debug("Configration for #{host}")
|
11
|
+
session_opts = {}
|
12
|
+
|
13
|
+
ssh_config = Net::SSH.configuration_for(host)
|
14
|
+
|
15
|
+
# Chef::Config[:knife][:ssh_user] is parsed in #configure_user and written to config[:ssh_user]
|
16
|
+
user = config[:ssh_user] || ssh_config[:user]
|
17
|
+
hostspec = user ? "#{user}@#{host}" : host
|
18
|
+
session_opts[:keys] = File.expand_path(config[:identity_file]) if config[:identity_file]
|
19
|
+
session_opts[:keys_only] = true if config[:identity_file]
|
20
|
+
session_opts[:password] = config[:ssh_password] if config[:ssh_password]
|
21
|
+
session_opts[:forward_agent] = config[:forward_agent]
|
22
|
+
session_opts[:port] = config[:ssh_port] ||
|
23
|
+
ssh_port || # Use cloud port if available
|
24
|
+
Chef::Config[:knife][:ssh_port] ||
|
25
|
+
ssh_config[:port]
|
26
|
+
session_opts[:logger] = Chef::Log.logger if Chef::Log.level == :debug
|
27
|
+
|
28
|
+
if !config[:host_key_verify]
|
29
|
+
session_opts[:paranoid] = false
|
30
|
+
session_opts[:user_known_hosts_file] = "/dev/null"
|
31
|
+
end
|
32
|
+
|
33
|
+
## use nomal Net::SSH instead of Net::SSH::Multi for simply tcpforward.
|
34
|
+
@session ||= Net::SSH.start(host, user, session_opts)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def ssh_command(command, subsession=nil)
|
39
|
+
chef_zero_port = config[:chef_zero_port] ||
|
40
|
+
Chef::Config[:knife][:chef_zero_port] ||
|
41
|
+
8889
|
42
|
+
chef_zero_host = config[:chef_zero_host] ||
|
43
|
+
Chef::Config[:knife][:chef_zero_host] ||
|
44
|
+
'127.0.0.1'
|
45
|
+
|
46
|
+
exit_status = 0
|
47
|
+
subsession ||= session
|
48
|
+
command = fixup_sudo(command)
|
49
|
+
command.force_encoding('binary') if command.respond_to?(:force_encoding)
|
50
|
+
|
51
|
+
Chef::Log.debug("Creating tcp-foward channel to #{chef_zero_host}:#{chef_zero_port}")
|
52
|
+
session.forward.remote(8889, chef_zero_host, chef_zero_port)
|
53
|
+
subsession.open_channel do |ch|
|
54
|
+
ch.request_pty
|
55
|
+
ch.exec command do |ch, success|
|
56
|
+
raise ArgumentError, "Cannot execute #{command}" unless success
|
57
|
+
ch.on_data do |ichannel, data|
|
58
|
+
## Patched
|
59
|
+
print_data(ichannel.connection.host, data)
|
60
|
+
if data =~ /^knife sudo password: /
|
61
|
+
print_data(ichannel.connection.host, "\n")
|
62
|
+
ichannel.send_data("#{get_password}\n")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
ch.on_request "exit-status" do |ichannel, data|
|
66
|
+
exit_status = [exit_status, data.read_long].max
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
session.loop
|
71
|
+
exit_status
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'chef/knife/core/bootstrap_context'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
module Core
|
6
|
+
class BootstrapContext
|
7
|
+
class_eval do
|
8
|
+
def start_chef_local
|
9
|
+
client_path = @chef_config[:chef_client_path] || 'chef-client'
|
10
|
+
s = "#{client_path} -j /etc/chef/first-boot.json"
|
11
|
+
s << ' -l debug' if @config[:verbosity] and @config[:verbosity] >= 2
|
12
|
+
s << " -E #{bootstrap_environment}" if chef_version.to_f != 0.9 # only use the -E option on Chef 0.10+
|
13
|
+
s << " -S http://127.0.0.1:8889"
|
14
|
+
s
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-zero
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sawanoboly
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-21 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '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.8'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '11.8'
|
55
|
+
description: "# Knife-Plugin Zero\n\nRun chef-client at remote node with chef-zero(local-mode)
|
56
|
+
via HTTP over SSH port fowarding.\n\n- It doesn't have to transport cookbooks via
|
57
|
+
scp,rsync or something.\n- It can collect node object into local chef-repo.\n- It
|
58
|
+
supports all functioanly of chef(C/S).\n- You have only to manage one chef-repo.\n\n##
|
59
|
+
Requirements\n\n- Must support AllowTcpForward \n\n## Installation\n\n> This gem
|
60
|
+
has not been released yet.\n\nAdd this line to your application's Gemfile:\n\n gem
|
61
|
+
'knife-zero'\n\nAnd then execute:\n\n $ bundle\n\nOr install it yourself as:\n\n
|
62
|
+
\ $ gem install knife-zero\n\n## Usage\n\n```\n** ZERO COMMANDS **\nknife zero
|
63
|
+
bootstrap FQDN (options)\n```\n\n### Bootstrap\n\nInstall Chef to remote node and
|
64
|
+
run chef-client under chef-zero via tcp-forward.\n\nSupported options are mostly
|
65
|
+
the same as `knife bootstrap`.\n\n\n#### Example\n\n```\n$ bundle exec knife zero
|
66
|
+
bootstrap host.example.com -r hogehoge::default --no-host-key-verify\nConnecting
|
67
|
+
to host.example.com\nhost.example.com Installing Chef Client...\n-- snip --\nhost.example.com
|
68
|
+
Thank you for installing Chef!\n\nhost.example.com Starting first Chef Client run...\nhost.example.com
|
69
|
+
Starting Chef Client, version 11.14.6\nhost.example.com Creating a new client identity
|
70
|
+
for host.example.com using the validator key.\n\n## Resolv and sync cookbook via
|
71
|
+
http over ssh tcp-forward by run-list.\nhost.example.com resolving cookbooks for
|
72
|
+
run list: [\"hogehoge::default\"]\nhost.example.com Synchronizing Cookbooks:\nhost.example.com
|
73
|
+
\ - hogehoge\nhost.example.com Compiling Cookbooks...\nhost.example.com Converging
|
74
|
+
0 resources\nhost.example.com \nhost.example.com Running handlers:\nhost.example.com
|
75
|
+
Running handlers complete\nhost.example.com Chef Client finished, 0/0 resources
|
76
|
+
updated in 4.895561879 seconds\n\n\n## Creates node object into local.\n $ ls nodes/host.example.com.json
|
77
|
+
\nnodes/host.example.com.json\nhost.example.com\n\n## Search by knife with --local--mode
|
78
|
+
option.\n$ bundle exec knife search node --local-mode\n1 items found\n\nNode Name:
|
79
|
+
\ host.example.com\nEnvironment: _default\nFQDN: \nIP: xxx.xxx.xxx.xxx\nRun
|
80
|
+
List: recipe[hogehoge::default]\nRoles: \nRecipes: hogehoge::default\nPlatform:
|
81
|
+
\ ubuntu 12.04\nTags: \n```\n\n### SSH\n\nSearch nodes from local chef-repo
|
82
|
+
directory, and run command at remote node.\n\nSupported options are mostly the same
|
83
|
+
as `knife ssh`.\n\n> Pending\n\n\n## Contributing\n\n1. Fork it ( https://github.com/[my-github-username]/knife-zero/fork
|
84
|
+
)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your
|
85
|
+
changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push
|
86
|
+
origin my-new-feature`)\n5. Create a new Pull Request\n\n## License\n\nLicensed
|
87
|
+
under the Apache License, Version 2.0.\n\n"
|
88
|
+
email:
|
89
|
+
- sawanoboriyu@higanworks.com
|
90
|
+
executables: []
|
91
|
+
extensions: []
|
92
|
+
extra_rdoc_files: []
|
93
|
+
files:
|
94
|
+
- ".gitignore"
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- knife-zero.gemspec
|
100
|
+
- lib/chef/knife/bootstrap/chef-full-localmode.erb
|
101
|
+
- lib/chef/knife/zero_base.rb
|
102
|
+
- lib/chef/knife/zero_bootstrap.rb
|
103
|
+
- lib/knife-zero/bootstrap_ssh.rb
|
104
|
+
- lib/knife-zero/common.rb
|
105
|
+
- lib/knife-zero/core/bootstrap_context.rb
|
106
|
+
- lib/knife-zero/version.rb
|
107
|
+
homepage: ''
|
108
|
+
licenses:
|
109
|
+
- Apache2
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.2.2
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Run chef-client at remote node with chef-zero(local-mode) via HTTP over SSH
|
131
|
+
port fowarding.
|
132
|
+
test_files: []
|