knife-zero 0.0.2 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +50 -3
- data/lib/chef/knife/chef_client.rb +49 -0
- data/lib/chef/knife/zero_base.rb +16 -0
- data/lib/chef/knife/zero_bootstrap.rb +34 -30
- data/lib/knife-zero/bootstrap_ssh.rb +2 -2
- data/lib/knife-zero/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52c93c2a006243fcbd0e0ad73eb140a8336b73d6
|
4
|
+
data.tar.gz: 718d5d1c551c145af599aaa9a9e0f3a40a6bcdec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d62de79dcd29220aa558f044e3ef10d7f42f95c8d8e6c397df1d571c987eb11310b52da7bc6226d1d366f17b03e5c3358c205ef6999065b49e28d7b6b8849720
|
7
|
+
data.tar.gz: d942ed977b211e2ee6f33305c1b9cb85e291d465cf50ed16837cf0c8b4e96c076acaa49e3c4c548c5808e6f5890c4d4bacca5aa704d977ac50c9844a178a9017
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Changelog of knife-zero
|
2
|
+
|
3
|
+
## v0.1.1
|
4
|
+
|
5
|
+
- Bug: Issue #1 NoMethodError: undefined method 'split' for nil:NilClass at bootstrap
|
6
|
+
|
7
|
+
## v0.1.0 (yanked)
|
8
|
+
|
9
|
+
- Feature: run Chef-Client by Seach query.
|
10
|
+
|
11
|
+
|
12
|
+
## v0.0.2
|
13
|
+
|
14
|
+
- initial release
|
15
|
+
- Feature: bootstrap with chefzero via tcp-forward
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Knife-Plugin Zero
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/knife-zero.svg)](http://badge.fury.io/rb/knife-zero)
|
4
|
+
[![Stories in Ready](https://badge.waffle.io/higanworks/knife-zero.svg?label=ready&title=Ready)](http://waffle.io/higanworks/knife-zero)
|
5
|
+
[![Stories in Progress](https://badge.waffle.io/higanworks/knife-zero.svg?label=In%20Progress&title=In%20Progress)](http://waffle.io/higanworks/knife-zero)
|
4
6
|
|
5
7
|
Run chef-client at remote node with chef-zero(local-mode) via HTTP over SSH port fowarding.
|
6
8
|
|
@@ -32,9 +34,10 @@ Or install it yourself as:
|
|
32
34
|
```
|
33
35
|
** ZERO COMMANDS **
|
34
36
|
knife zero bootstrap FQDN (options)
|
37
|
+
knife zero chef_client QUERY (options)
|
35
38
|
```
|
36
39
|
|
37
|
-
###
|
40
|
+
### knife zero bootstrap
|
38
41
|
|
39
42
|
Install Chef to remote node and run chef-client under chef-zero via tcp-forward.
|
40
43
|
|
@@ -56,6 +59,7 @@ host.example.com Starting first Chef Client run...
|
|
56
59
|
host.example.com Starting Chef Client, version 11.14.6
|
57
60
|
host.example.com Creating a new client identity for host.example.com using the validator key.
|
58
61
|
|
62
|
+
|
59
63
|
## Resolv and sync cookbook via http over ssh tcp-forward by run-list.
|
60
64
|
host.example.com resolving cookbooks for run list: ["hogehoge::default"]
|
61
65
|
host.example.com Synchronizing Cookbooks:
|
@@ -102,13 +106,56 @@ xxx.xxx.xxx.xxx 08:41:36 up 1:03, 1 user, load average: 0.00, 0.01, 0.01
|
|
102
106
|
xxx.xxx.xxx.xxx 08:41:37 up 143 days, 2:32, 4 users, load average: 0.00, 0.01, 0.05
|
103
107
|
```
|
104
108
|
|
105
|
-
###
|
109
|
+
### knife zero chef_client (for update)
|
110
|
+
|
111
|
+
`knife zero chef_client QUERY (options)`
|
106
112
|
|
107
113
|
Search nodes from local chef-repo directory, and run command at remote node.
|
108
114
|
|
109
115
|
Supported options are mostly the same as `knife ssh`.
|
110
116
|
|
111
|
-
|
117
|
+
#### Example
|
118
|
+
|
119
|
+
```
|
120
|
+
## Chef-Repo has two nodes
|
121
|
+
$ knife node list --local-mode
|
122
|
+
host.example.com
|
123
|
+
host2.example.com
|
124
|
+
|
125
|
+
## add recipe to run_list of host.example.com
|
126
|
+
$ knife node run_list add host.example.com hogehoge::default --local-mode
|
127
|
+
host.example.com:
|
128
|
+
run_list: recipe[hogehoge::default]
|
129
|
+
|
130
|
+
|
131
|
+
$ knife zero chef_client 'name:*' --attribute ipaddress
|
132
|
+
|
133
|
+
## host.example.com was converged by run_list.
|
134
|
+
host.example.com Starting Chef Client, version 11.14.6
|
135
|
+
host.example.com resolving cookbooks for run list: ["hogehoge::default"]
|
136
|
+
host.example.com Synchronizing Cookbooks:
|
137
|
+
host.example.com - hogehoge
|
138
|
+
host.example.com Compiling Cookbooks...
|
139
|
+
host.example.com Converging 0 resources
|
140
|
+
host.example.com
|
141
|
+
host.example.com Running handlers:
|
142
|
+
host.example.com Running handlers complete
|
143
|
+
host.example.com Chef Client finished, 0/0 resources updated in 3.112708185 seconds
|
144
|
+
|
145
|
+
|
146
|
+
## host2.example.com has no run_list.
|
147
|
+
host2.example.com Starting Chef Client, version 11.14.2
|
148
|
+
host2.example.com resolving cookbooks for run list: []
|
149
|
+
host2.example.com Synchronizing Cookbooks:
|
150
|
+
host2.example.com Compiling Cookbooks...
|
151
|
+
host2.example.com [2014-08-24T11:52:15+00:00] WARN: Node ngrok01.xenzai.net has an empty run list.
|
152
|
+
host2.example.com Converging 0 resources
|
153
|
+
host2.example.com
|
154
|
+
host2.example.com Running handlers:
|
155
|
+
host2.example.com Running handlers complete
|
156
|
+
host2.example.com Chef Client finished, 0/0 resources updated in 3.729471856 seconds
|
157
|
+
```
|
158
|
+
|
112
159
|
|
113
160
|
## Sample Workflow
|
114
161
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
require 'chef/knife/zero_base'
|
3
|
+
|
4
|
+
class Chef
|
5
|
+
class Knife
|
6
|
+
class ZeroChefClient < Chef::Knife::Ssh
|
7
|
+
include Chef::Knife::ZeroBase
|
8
|
+
deps do
|
9
|
+
require 'chef/node'
|
10
|
+
require 'chef/environment'
|
11
|
+
require 'chef/api_client'
|
12
|
+
require 'chef/search/query'
|
13
|
+
require 'knife-zero/bootstrap_ssh'
|
14
|
+
Chef::Knife::BootstrapSsh.load_deps
|
15
|
+
end
|
16
|
+
|
17
|
+
banner "knife zero chef_client QUERY (options)"
|
18
|
+
|
19
|
+
option :attribute,
|
20
|
+
:short => "-a ATTR",
|
21
|
+
:long => "--attribute ATTR",
|
22
|
+
:description => "The attribute to use for opening the connection - default depends on the context",
|
23
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:ssh_attribute] = key.strip }
|
24
|
+
|
25
|
+
def run
|
26
|
+
configure_attribute
|
27
|
+
configure_user
|
28
|
+
configure_password
|
29
|
+
configure_identity_file
|
30
|
+
list = search_nodes
|
31
|
+
|
32
|
+
list.each do |n|
|
33
|
+
Chef::Log.debug("Start session for #{n}")
|
34
|
+
session = knife_ssh
|
35
|
+
session.configure_session(n)
|
36
|
+
session.ssh_command(start_chef_client)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def start_chef_client
|
41
|
+
client_path = @config[:chef_client_path] || 'chef-client'
|
42
|
+
s = "#{client_path}"
|
43
|
+
s << ' -l debug' if @config[:verbosity] and @config[:verbosity] >= 2
|
44
|
+
s << " -S http://127.0.0.1:8889"
|
45
|
+
s
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/chef/knife/zero_base.rb
CHANGED
@@ -58,6 +58,22 @@ class Chef
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
def knife_ssh
|
62
|
+
ssh = Chef::Knife::BootstrapSsh.new
|
63
|
+
ssh.ui = ui
|
64
|
+
ssh.name_args = [ server_name, ssh_command ] unless ssh.name_args.empty?
|
65
|
+
ssh.config[:ssh_user] = Chef::Config[:knife][:ssh_user] || config[:ssh_user]
|
66
|
+
ssh.config[:ssh_password] = config[:ssh_password]
|
67
|
+
ssh.config[:ssh_port] = Chef::Config[:knife][:ssh_port] || config[:ssh_port]
|
68
|
+
ssh.config[:ssh_gateway] = Chef::Config[:knife][:ssh_gateway] || config[:ssh_gateway]
|
69
|
+
ssh.config[:forward_agent] = Chef::Config[:knife][:forward_agent] || config[:forward_agent]
|
70
|
+
ssh.config[:identity_file] = Chef::Config[:knife][:identity_file] || config[:identity_file]
|
71
|
+
ssh.config[:manual] = true
|
72
|
+
ssh.config[:host_key_verify] = Chef::Config[:knife][:host_key_verify] || config[:host_key_verify]
|
73
|
+
ssh.config[:on_error] = :raise
|
74
|
+
ssh
|
75
|
+
end
|
76
|
+
|
61
77
|
private
|
62
78
|
|
63
79
|
def locate_config_value(key)
|
@@ -80,36 +80,36 @@ class Chef
|
|
80
80
|
name, path = h.split("=")
|
81
81
|
Chef::Config[:knife][:hints][name] = path ? Chef::JSONCompat.parse(::File.read(path)) : Hash.new }
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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
113
|
|
114
114
|
def knife_ssh
|
115
115
|
ssh = Chef::Knife::BootstrapSsh.new
|
@@ -127,6 +127,10 @@ class Chef
|
|
127
127
|
ssh
|
128
128
|
end
|
129
129
|
|
130
|
+
alias :default_run :run
|
131
|
+
def run
|
132
|
+
default_run
|
133
|
+
end
|
130
134
|
end
|
131
135
|
end
|
132
136
|
end
|
@@ -3,8 +3,8 @@ require 'chef/knife/ssh'
|
|
3
3
|
class Chef
|
4
4
|
class Knife
|
5
5
|
class BootstrapSsh < Chef::Knife::Ssh
|
6
|
-
def configure_session
|
7
|
-
host, ssh_port =
|
6
|
+
def configure_session(args = @name_args)
|
7
|
+
host, ssh_port = args[0].split(" ")
|
8
8
|
@longest = host.length
|
9
9
|
|
10
10
|
Chef::Log.debug("Configration for #{host}")
|
data/lib/knife-zero/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-zero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sawanoboly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -61,12 +61,14 @@ extensions: []
|
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
|
+
- CHANGELOG.md
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE.txt
|
66
67
|
- README.md
|
67
68
|
- Rakefile
|
68
69
|
- knife-zero.gemspec
|
69
70
|
- lib/chef/knife/bootstrap/chef-full-localmode.erb
|
71
|
+
- lib/chef/knife/chef_client.rb
|
70
72
|
- lib/chef/knife/zero_base.rb
|
71
73
|
- lib/chef/knife/zero_bootstrap.rb
|
72
74
|
- lib/knife-zero/bootstrap_ssh.rb
|