chake 0.10.2 → 0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a066ad18b894e6b4a17a6e67ddeea63e4120f56
4
- data.tar.gz: 00cfd9eadc606cd339292a23ad92a35b1d519a96
3
+ metadata.gz: 1984eadb9d5b222a4e1aed1b8180b04819c8158b
4
+ data.tar.gz: ec4ed19becc23cbe25377524ddc800fbc8da1e4c
5
5
  SHA512:
6
- metadata.gz: 3c4df34f504c93cbc041bd7a0eb8364b8f82163ac9a0fafe7dbf8f2980d2792a7d3d9eba727cd8709889564edc0ba4ea653e986b93628d56d8d26b07caf2d6d8
7
- data.tar.gz: 1e7531dd97822ec1afce9e1fc2b56175c6f0547639ccd9c5924846cefd369ca40be35c6c549ce5cd1306231681166608409b44b01c2c258cc93c5be54c3eb77e
6
+ metadata.gz: 32a7a9675766f6ea039d8e1c07587c210e831e97d497f2f229be1f4253b2c0c1374a74be6e27f679fd5eedaa4905ca380a02d98d5e41fceb69989240be3e4576
7
+ data.tar.gz: 775af5a4f9d52c8d70a10cab818a235a6af76b8b167c7616d6fcb97dcd343195f44da6df986200bc19f19dfb04a6e5bfa696d2d8831dc324e2d2ef9da4bf5819
@@ -1,3 +1,14 @@
1
+ # 0.11
2
+
3
+ * bootstrap: make sure FQDN matches hostname
4
+ * Add `rake check` task to check SSH connectivity and sudo setup
5
+ * Add tasks to apply a single recipe to nodes: `rake apply[recipe]` and `rake
6
+ apply:$NODE[recipe]`. If `[recipe]` is not passed in the command line, the
7
+ user is prompted for the recipe name.
8
+ * run task changed to have the same interface and behavior as the new apply
9
+ task: `rake run[command]`, or `rake run:$NODE[command]`. If `[command]` is
10
+ not passed in the command line, the user is prompted for the command.
11
+
1
12
  # 0.10.2
2
13
 
3
14
  * Fix check for modified files at the upload phase. Now chake will properly
data/README.md CHANGED
@@ -38,7 +38,7 @@ A brief explanation of the created files:
38
38
  After the repository is created, you can call either `chake` or `rake`, as they
39
39
  are completely equivalent.
40
40
 
41
- ## Managing nodes and recipes
41
+ ## Managing nodes
42
42
 
43
43
  Just after you created your repository, the contents of `nodes.yaml` is the
44
44
  following:
@@ -95,6 +95,24 @@ password prompts, you can:
95
95
  - Configure passwordless `sudo` access for the user you use to connect to your
96
96
  nodes.
97
97
 
98
+ ## Checking connectivity and initial host setup
99
+
100
+ To check whether hosts are correcly configured, you can use the `check` task:
101
+
102
+ ```bash
103
+ $ rake check
104
+ ```
105
+
106
+ That will run the the `sudo true` command on each host. If that pass without
107
+ you having to passwords, you are sure that
108
+
109
+ * you have SSH access to each host; and
110
+ * the user you are connecting as has password-less sudo correctly setup.
111
+
112
+ ```bash
113
+ $ rake check
114
+ ```
115
+
98
116
  ## Applying cookbooks
99
117
 
100
118
  To apply the configuration to all nodes, run
@@ -109,6 +127,44 @@ To apply the configuration to a single node, run
109
127
  $ rake converge:$NODE
110
128
  ```
111
129
 
130
+ To apply a single recipe on all nodes, run
131
+
132
+ ```bash
133
+ $ rake apply[myrecipe]
134
+ ```
135
+
136
+ To apply a single recipe on a specific node, run
137
+
138
+ ```bash
139
+ $ rake apply:$NODE[myrecipe]
140
+ ```
141
+
142
+ If you don't inform a recipe in the command line, you will be prompted for one.
143
+
144
+ To run a shell command on all nodes, run
145
+
146
+ ```
147
+ $ rake run[command]
148
+ ```
149
+
150
+ If the `command` you want to run contains spaces, or other characters that are
151
+ special do the shell, you have to quote them.
152
+
153
+ To run a shell command on a specific node, run
154
+
155
+ ```
156
+ $ rake run:$NODE[command]
157
+ ```
158
+
159
+ If you don't inform a command in the command line, you will be prompted for
160
+ one.
161
+
162
+ To check the existing tasks, run
163
+
164
+ ```bash
165
+ $ rake -T
166
+ ```
167
+
112
168
  ## Writing cookbooks
113
169
 
114
170
  Since chake is actually a wrapper for Chef Solo, you should read the [chef
@@ -7,6 +7,7 @@ require 'tmpdir'
7
7
  require 'chake/version'
8
8
  require 'chake/node'
9
9
  require 'chake/readline'
10
+ require 'chake/tmpdir'
10
11
 
11
12
  nodes_file = ENV['CHAKE_NODES'] || 'nodes.yaml'
12
13
  nodes_directory = ENV['CHAKE_NODES_D'] || 'nodes.d'
@@ -15,7 +16,7 @@ Dir.glob(File.join(nodes_directory, '*.yaml')).sort.each do |f|
15
16
  node_data.merge!(YAML.load_file(f))
16
17
  end
17
18
  $nodes = node_data.map { |node,data| Chake::Node.new(node, data) }.reject(&:skip?).uniq(&:hostname)
18
- $chake_tmpdir = ENV.fetch('CHAKE_TMPDIR', 'tmp/chake')
19
+ $chake_tmpdir = Chake.tmpdir
19
20
 
20
21
  desc "Initializes current directory with sample structure"
21
22
  task :init do
@@ -206,33 +207,80 @@ $nodes.each do |node|
206
207
  end
207
208
  end
208
209
 
210
+ converge_dependencies = [:converge_common, "bootstrap:#{hostname}", "upload:#{hostname}"]
211
+
209
212
  desc "converge #{hostname}"
210
- task "converge:#{hostname}" => [:converge_common, "bootstrap:#{hostname}", "upload:#{hostname}"] do
213
+ task "converge:#{hostname}" => converge_dependencies do
211
214
  chef_logging = Rake.application.options.silent && '-l fatal' || ''
212
215
  node.run_as_root "chef-solo -c #{node.path}/config.rb #{chef_logging} -j #{node.path}/#{$chake_tmpdir}/#{hostname}.json"
213
216
  end
214
217
 
218
+ desc 'apply <recipe> on #{hostname}'
219
+ task "apply:#{hostname}", [:recipe] => [:recipe_input] do |task, args|
220
+ chef_logging = Rake.application.options.silent && '-l fatal' || ''
221
+ node.run_as_root "chef-solo -c #{node.path}/config.rb #{chef_logging} -j #{node.path}/#{$chake_tmpdir}/#{hostname}.json --override-runlist recipe[#{$recipe_to_apply}]"
222
+ end
223
+ task "apply:#{hostname}" => converge_dependencies
224
+
215
225
  desc "run a command on #{hostname}"
216
- task "run:#{hostname}" => 'run_input' do
217
- node.run($cmd)
226
+ task "run:#{hostname}", [:command] => [:run_input] do
227
+ node.run($cmd_to_run)
218
228
  end
219
229
 
220
230
  desc "Logs in to a shell on #{hostname}"
221
231
  task "login:#{hostname}" do
222
232
  node.run_shell
223
233
  end
234
+
235
+ desc 'checks connectivity and setup on all nodes'
236
+ task "check:#{hostname}" do
237
+ node.run('sudo true')
238
+ end
239
+
224
240
  end
225
241
 
226
- task :run_input do
227
- puts "# Enter command to run (use arrow keys for history):"
228
- $cmd = ENV['CMD'] || Chake::Readline.readline
229
- if !$cmd || $cmd.strip == ''
242
+ task :run_input, :command do |task,args|
243
+ $cmd_to_run = args[:command]
244
+ if !$cmd_to_run
245
+ puts "# Enter command to run (use arrow keys for history):"
246
+ $cmd_to_run = Chake::Readline::Commands.readline
247
+ end
248
+ if !$cmd_to_run || $cmd_to_run.strip == ''
230
249
  puts
231
250
  puts "I: no command provided, operation aborted."
232
251
  exit(1)
233
252
  end
234
253
  end
235
254
 
255
+ task :recipe_input, :recipe do |task,args|
256
+ $recipe_to_apply = args[:recipe]
257
+
258
+ if !$recipe_to_apply
259
+ recipes = Dir['**/*/recipes/*.rb'].map do |f|
260
+ f =~ %r{(.*/)?(.*)/recipes/(.*).rb$}
261
+ cookbook = $2
262
+ recipe = $3
263
+ recipe = nil if recipe == 'default'
264
+ [cookbook,recipe].compact.join('::')
265
+ end.sort
266
+ puts 'Available recipes:'
267
+
268
+ IO.popen('column', 'w') do |column|
269
+ column.puts(recipes)
270
+ end
271
+
272
+ $recipe_to_apply = Chake::Readline::Recipes.readline
273
+ if !$recipe_to_apply || $recipe_to_apply.empty?
274
+ puts
275
+ puts "I: no recipe provided, operation aborted."
276
+ exit(1)
277
+ end
278
+ if !recipes.include?($recipe_to_apply)
279
+ abort "E: no such recipe: #{$recipe_to_apply}"
280
+ end
281
+ end
282
+ end
283
+
236
284
  desc "upload to all nodes"
237
285
  task :upload => $nodes.map { |node| "upload:#{node.hostname}" }
238
286
 
@@ -242,7 +290,15 @@ task :bootstrap => $nodes.map { |node| "bootstrap:#{node.hostname}" }
242
290
  desc "converge all nodes (default)"
243
291
  task "converge" => $nodes.map { |node| "converge:#{node.hostname}" }
244
292
 
245
- desc "run a command on all nodes"
246
- task :run => $nodes.map { |node| "run:#{node.hostname}" }
293
+ desc "Apply <recipe> on all nodes"
294
+ task "apply", [:recipe] => $nodes.map { |node| "apply:#{node.hostname}" }
295
+
296
+ desc "run <command> on all nodes"
297
+ task :run, [:command] => $nodes.map { |node| "run:#{node.hostname}" }
247
298
 
248
299
  task :default => :converge
300
+
301
+ desc 'checks connectivity and setup on all nodes'
302
+ task :check => ($nodes.map { |node| "check:#{node.hostname}" }) do
303
+ puts "✓ all hosts OK"
304
+ end
@@ -3,6 +3,11 @@ hostname="$1"
3
3
  echo "$hostname" > /etc/hostname
4
4
  hostname --file /etc/hostname
5
5
 
6
+ fqdn=$(hostname --fqdn || true)
7
+ if [ "$fqdn" != "$hostname" ]; then
8
+ printf "127.0.1.1\t%s\n" "$hostname" >> /etc/hosts
9
+ fi
10
+
6
11
  # Stop cloud-init from resetting the hostname
7
12
  if [ -f /etc/cloud/cloud.cfg ]; then
8
13
  sed -i -e '/^\s*-\s*\(set_hostname\|update_hostname\)/d' /etc/cloud/cloud.cfg
@@ -1,26 +1,33 @@
1
1
  require 'etc'
2
2
  require 'readline'
3
3
 
4
+ require 'chake/tmpdir'
5
+
4
6
  module Chake
5
7
 
6
- module Readline
8
+ class Readline
7
9
 
8
10
  class << self
9
11
 
10
12
  def history_file
11
- File.join(Dir.home, '.chake_history')
13
+ raise NotImplementedError
14
+ end
15
+
16
+ def history
17
+ @history ||= []
18
+ end
19
+
20
+ def prompt
21
+ raise NotImplementedError
12
22
  end
13
23
 
14
24
  def init
15
25
  return if !File.exists?(history_file)
16
- File.readlines(history_file).each do |line|
17
- @last = line.strip
18
- ::Readline::HISTORY.push(@last)
19
- end
26
+ @history = File.readlines(history_file).map(&:strip)
20
27
  end
21
28
 
22
29
  def finish
23
- history = ::Readline::HISTORY.map { |line| line }
30
+ return if !File.writable?(File.dirname(history_file)) || history.empty?
24
31
  File.open(history_file, 'w') do |f|
25
32
  history.last(500).each do |line|
26
33
  f.puts(line)
@@ -29,20 +36,45 @@ module Chake
29
36
  end
30
37
 
31
38
  def readline
32
- input = ::Readline.readline('$ ')
39
+ ::Readline::HISTORY.clear
40
+ history.each do |cmd|
41
+ ::Readline::HISTORY.push(cmd)
42
+ end
43
+ input = ::Readline.readline(prompt)
33
44
  if input && input.strip != '' && input != @last
34
- ::Readline::HISTORY.push(input)
45
+ history.push(input)
35
46
  end
36
47
  input
37
48
  end
38
49
 
39
50
  end
40
51
 
52
+ class Commands < Readline
53
+ def self.history_file
54
+ File.join(Chake.tmpdir, '.commands_history')
55
+ end
56
+ def self.prompt
57
+ '$ '
58
+ end
59
+ end
60
+
61
+ class Recipes < Readline
62
+ def self.history_file
63
+ File.join(Chake.tmpdir, '.recipes_history')
64
+ end
65
+ def self.prompt
66
+ '> '
67
+ end
68
+ end
69
+
41
70
  end
42
71
 
43
72
  end
44
73
 
45
- Chake::Readline.init
46
- at_exit do
47
- Chake::Readline.finish
74
+ Chake::Readline.constants.each do |subclass|
75
+ subclass = Chake::Readline.const_get(subclass)
76
+ subclass.init
77
+ at_exit do
78
+ subclass.finish
79
+ end
48
80
  end
@@ -0,0 +1,5 @@
1
+ module Chake
2
+ def self.tmpdir
3
+ ENV.fetch('CHAKE_TMPDIR', 'tmp/chake')
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Chake
2
- VERSION = "0.10.2"
2
+ VERSION = "0.11"
3
3
  end
@@ -1,5 +1,9 @@
1
- require 'simplecov'
2
- SimpleCov.start
1
+ begin
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ rescue LoadError
5
+ puts "W: simplecov not installed, we won't have a coverage report"
6
+ end
3
7
 
4
8
  require 'chake/node'
5
9
  require 'chake/backend'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: '0.11'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonio Terceiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-27 00:00:00.000000000 Z
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -101,6 +101,7 @@ files:
101
101
  - lib/chake/bootstrap/99_unsupported.sh
102
102
  - lib/chake/node.rb
103
103
  - lib/chake/readline.rb
104
+ - lib/chake/tmpdir.rb
104
105
  - lib/chake/version.rb
105
106
  - man/.gitignore
106
107
  - man/Rakefile
@@ -140,4 +141,3 @@ test_files:
140
141
  - spec/chake/backend_spec.rb
141
142
  - spec/chake/node_spec.rb
142
143
  - spec/spec_helper.rb
143
- has_rdoc: