knife-node-context-exec 1.0.7 → 1.0.8
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 +4 -4
- data/lib/chef/knife/context_exec.rb +72 -64
- data/lib/knife-node-context-exec/runner.rb +2 -1
- data/lib/knife-node-context-exec/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 924b310b24ebca668eaa253f28aacf9c5b30f487
|
4
|
+
data.tar.gz: 5332adaa69f487fb901e1b56485803f9d9370839
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edb59950c594b10d4cc97194363cd9b0b9fb408fb07dea793c200c2c628fae43c493d24ab932160389e71d479f8c41f0320a9dc43ba1c7454b1e23ced2b6bdbf
|
7
|
+
data.tar.gz: 3b6854e76099d3214e2aced02dc6bc63b1769aea8742ca74517d3cf6e32a503b590f9bd46a33738befda25cba2e83f1c1b4b78a2284d1d194abe1ee8bb1aabfb
|
@@ -1,73 +1,81 @@
|
|
1
1
|
require 'knife-node-context-exec/version'
|
2
2
|
require 'chef/knife'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module KnifeNodeContextExec
|
5
|
+
# The knife
|
6
|
+
class ContextExec < Chef::Knife
|
7
|
+
banner 'knife context exec'
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
deps do
|
10
|
+
require 'chef/search/query'
|
11
|
+
require 'knife-node-context-exec/runner'
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
14
|
+
option :environment,
|
15
|
+
short: '-E ENVIRONMENT',
|
16
|
+
long: '--environment ENVIRONMENT',
|
17
|
+
description: 'The environment to search.'
|
18
|
+
option :node_query,
|
19
|
+
short: '-Q QUERY',
|
20
|
+
long: '--query QUERY',
|
21
|
+
description: 'The node query.'
|
22
|
+
option :directory,
|
23
|
+
short: '-D DIRECTORY',
|
24
|
+
long: '--directory DIRECTORY',
|
25
|
+
description: 'A directory for working files.'
|
26
|
+
option :template_filename,
|
27
|
+
short: '-T TEMPLATE',
|
28
|
+
long: '--template TEMPLATE',
|
29
|
+
description: 'The filename of a template.'
|
30
|
+
option :script_filename,
|
31
|
+
short: '-S SCRIPT',
|
32
|
+
long: '--script SCRIPT',
|
33
|
+
description: 'The environment to search.'
|
34
|
+
option :command,
|
35
|
+
short: '-C COMMAND',
|
36
|
+
long: '--command COMMAND',
|
37
|
+
description: 'The command to run.'
|
38
|
+
option :filter_regex,
|
39
|
+
short: '-R REGEX',
|
40
|
+
long: '--regex REGEX',
|
41
|
+
description: 'A regex used to filter output.'
|
42
|
+
option :parallel,
|
43
|
+
short: '-P',
|
44
|
+
long: '--parallel',
|
45
|
+
description: 'Run in parallel?',
|
46
|
+
boolean: true | false,
|
47
|
+
default: false
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
49
|
+
def run
|
50
|
+
puts "knife context exec #{KnifeNodeContextExec::VERSION}"
|
51
|
+
environment = config[:environment].to_s
|
52
|
+
node_query = config[:node_query].to_s
|
53
|
+
directory = config[:directory].to_s
|
54
|
+
template_filename = config[:template_filename].to_s
|
55
|
+
script_filename = config[:script_filename].to_s
|
56
|
+
command = config[:command].to_s
|
57
|
+
filter_regex = config[:filter_regex].to_s
|
58
|
+
parallel = config[:parallel]
|
59
|
+
raise 'Some parameters are missing' if
|
60
|
+
environment.empty? || node_query.empty? || directory.empty? || template_filename.empty? ||
|
61
|
+
script_filename.empty? || command.empty? || filter_regex.empty?
|
62
|
+
directory = File.expand_path(directory)
|
63
|
+
template_filename = File.expand_path(template_filename)
|
64
|
+
script_filename = File.expand_path(script_filename)
|
65
|
+
puts "Environment: #{environment}"
|
66
|
+
puts "Query: #{node_query}"
|
67
|
+
puts "Directory: #{directory}"
|
68
|
+
puts "Template: #{template_filename}"
|
69
|
+
puts "Script: #{script_filename}"
|
70
|
+
puts "Command: #{command}"
|
71
|
+
puts "Regex: #{filter_regex}"
|
72
|
+
puts "Parallel? #{parallel}"
|
73
|
+
nodes = Chef::Search::Query.new.search(:node, node_query).first.select do |node|
|
74
|
+
node.environment == environment
|
75
|
+
end
|
76
|
+
nodes.each { |node| puts "Found #{node.name}" }
|
77
|
+
KnifeNodeContextExec.run(nodes, directory, template_filename, script_filename, command, filter_regex,
|
78
|
+
parallel, false)
|
68
79
|
end
|
69
|
-
nodes.each { |node| puts "Found #{node.name}" }
|
70
|
-
KnifeNodeContextExec.run(nodes, directory, template_filename, script_filename, command, filter_regex,
|
71
|
-
parallel, false)
|
72
80
|
end
|
73
81
|
end
|
@@ -16,8 +16,8 @@ module KnifeNodeContextExec
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def run
|
19
|
-
yield(">>>> Executing script for #{node.name}")
|
20
19
|
@thread = Thread.new do
|
20
|
+
yield(">>>> Executing script for #{node.name} <<<<")
|
21
21
|
script_directory = "#{working_directory}/#{node.name}"
|
22
22
|
FileUtils.makedirs(script_directory)
|
23
23
|
template = File.read(template_filename)
|
@@ -35,6 +35,7 @@ module KnifeNodeContextExec
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
|
+
yield(">>>> Executing script for #{node.name} <<<<")
|
38
39
|
self
|
39
40
|
end
|
40
41
|
|