bolt 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of bolt might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/bolt/cli.rb +127 -31
- data/lib/bolt/config.rb +39 -6
- data/lib/bolt/execution_result.rb +109 -0
- data/lib/bolt/executor.rb +4 -1
- data/lib/bolt/node.rb +6 -1
- data/lib/bolt/node/orch.rb +20 -2
- data/lib/bolt/node/winrm.rb +22 -10
- data/lib/bolt/node_uri.rb +5 -7
- data/lib/bolt/outputter/human.rb +60 -1
- data/lib/bolt/outputter/json.rb +11 -0
- data/lib/bolt/target.rb +32 -0
- data/lib/bolt/version.rb +1 -1
- data/modules/boltlib/lib/puppet/datatypes/executionresult.rb +30 -0
- data/modules/boltlib/lib/puppet/datatypes/target.rb +12 -0
- data/modules/boltlib/lib/puppet/functions/file_upload.rb +3 -3
- data/modules/boltlib/lib/puppet/functions/run_command.rb +3 -3
- data/modules/boltlib/lib/puppet/functions/run_script.rb +3 -3
- data/modules/boltlib/lib/puppet/functions/run_task.rb +10 -2
- data/vendored/puppet/lib/puppet/application/describe.rb +0 -1
- data/vendored/puppet/lib/puppet/configurer.rb +1 -1
- data/vendored/puppet/lib/puppet/configurer/plugin_handler.rb +15 -9
- data/vendored/puppet/lib/puppet/datatypes.rb +213 -0
- data/vendored/puppet/lib/puppet/datatypes/error.rb +19 -0
- data/vendored/puppet/lib/puppet/datatypes/impl/error.rb +42 -0
- data/vendored/puppet/lib/puppet/error.rb +1 -1
- data/vendored/puppet/lib/puppet/face/catalog.rb +1 -1
- data/vendored/puppet/lib/puppet/face/epp.rb +3 -3
- data/vendored/puppet/lib/puppet/face/help.rb +12 -14
- data/vendored/puppet/lib/puppet/face/man.rb +1 -0
- data/vendored/puppet/lib/puppet/face/module/search.rb +1 -1
- data/vendored/puppet/lib/puppet/face/node.rb +1 -0
- data/vendored/puppet/lib/puppet/face/parser.rb +0 -1
- data/vendored/puppet/lib/puppet/face/status.rb +1 -0
- data/vendored/puppet/lib/puppet/feature/base.rb +1 -1
- data/vendored/puppet/lib/puppet/file_bucket/dipper.rb +0 -1
- data/vendored/puppet/lib/puppet/file_system/uniquefile.rb +2 -2
- data/vendored/puppet/lib/puppet/forge/errors.rb +21 -29
- data/vendored/puppet/lib/puppet/functions.rb +64 -84
- data/vendored/puppet/lib/puppet/functions/defined.rb +0 -3
- data/vendored/puppet/lib/puppet/functions/find_file.rb +0 -1
- data/vendored/puppet/lib/puppet/functions/map.rb +0 -1
- data/vendored/puppet/lib/puppet/functions/regsubst.rb +1 -1
- data/vendored/puppet/lib/puppet/graph/simple_graph.rb +6 -10
- data/vendored/puppet/lib/puppet/indirector/catalog/compiler.rb +37 -25
- data/vendored/puppet/lib/puppet/indirector/file_server.rb +1 -1
- data/vendored/puppet/lib/puppet/indirector/indirection.rb +0 -2
- data/vendored/puppet/lib/puppet/indirector/rest.rb +9 -8
- data/vendored/puppet/lib/puppet/info_service/class_information_service.rb +1 -1
- data/vendored/puppet/lib/puppet/interface/option_manager.rb +1 -1
- data/vendored/puppet/lib/puppet/loaders.rb +1 -0
- data/vendored/puppet/lib/puppet/module.rb +6 -2
- data/vendored/puppet/lib/puppet/module_tool/applications/unpacker.rb +1 -1
- data/vendored/puppet/lib/puppet/module_tool/errors/installer.rb +29 -41
- data/vendored/puppet/lib/puppet/module_tool/errors/shared.rb +63 -138
- data/vendored/puppet/lib/puppet/module_tool/errors/uninstaller.rb +15 -37
- data/vendored/puppet/lib/puppet/module_tool/errors/upgrader.rb +18 -30
- data/vendored/puppet/lib/puppet/module_tool/installed_modules.rb +1 -1
- data/vendored/puppet/lib/puppet/module_tool/metadata.rb +0 -1
- data/vendored/puppet/lib/puppet/network/http/api/indirected_routes.rb +1 -1
- data/vendored/puppet/lib/puppet/network/rights.rb +1 -1
- data/vendored/puppet/lib/puppet/node.rb +1 -1
- data/vendored/puppet/lib/puppet/node/environment.rb +1 -1
- data/vendored/puppet/lib/puppet/parameter/value_collection.rb +4 -17
- data/vendored/puppet/lib/puppet/parser/compiler.rb +1 -0
- data/vendored/puppet/lib/puppet/parser/functions.rb +0 -1
- data/vendored/puppet/lib/puppet/parser/functions/scanf.rb +1 -1
- data/vendored/puppet/lib/puppet/parser/scope.rb +4 -3
- data/vendored/puppet/lib/puppet/parser/script_compiler.rb +1 -0
- data/vendored/puppet/lib/puppet/parser/templatewrapper.rb +3 -2
- data/vendored/puppet/lib/puppet/parser/type_loader.rb +1 -1
- data/vendored/puppet/lib/puppet/pops.rb +1 -0
- data/vendored/puppet/lib/puppet/pops/evaluator/access_operator.rb +3 -2
- data/vendored/puppet/lib/puppet/pops/evaluator/closure.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/evaluator/evaluator_impl.rb +2 -2
- data/vendored/puppet/lib/puppet/pops/functions/dispatch.rb +6 -5
- data/vendored/puppet/lib/puppet/pops/functions/function.rb +2 -2
- data/vendored/puppet/lib/puppet/pops/loader/loader.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/loader/loader_paths.rb +40 -4
- data/vendored/puppet/lib/puppet/pops/loader/module_loaders.rb +6 -2
- data/vendored/puppet/lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb +8 -8
- data/vendored/puppet/lib/puppet/pops/loader/ruby_data_type_instantiator.rb +40 -0
- data/vendored/puppet/lib/puppet/pops/loader/static_loader.rb +6 -26
- data/vendored/puppet/lib/puppet/pops/loaders.rb +11 -2
- data/vendored/puppet/lib/puppet/pops/lookup/data_dig_function_provider.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/lookup/lookup_adapter.rb +4 -14
- data/vendored/puppet/lib/puppet/pops/model/model_tree_dumper.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/parser/code_merger.rb +2 -2
- data/vendored/puppet/lib/puppet/pops/parser/eparser.rb +1471 -1501
- data/vendored/puppet/lib/puppet/pops/parser/epp_support.rb +0 -2
- data/vendored/puppet/lib/puppet/pops/parser/evaluating_parser.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/parser/interpolation_support.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/parser/lexer2.rb +2 -26
- data/vendored/puppet/lib/puppet/pops/parser/locator.rb +5 -7
- data/vendored/puppet/lib/puppet/pops/parser/parser_support.rb +2 -2
- data/vendored/puppet/lib/puppet/pops/parser/slurp_support.rb +0 -3
- data/vendored/puppet/lib/puppet/pops/pcore.rb +0 -11
- data/vendored/puppet/lib/puppet/pops/serialization/object.rb +3 -4
- data/vendored/puppet/lib/puppet/pops/serialization/to_data_converter.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/time/timespan.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/types/iterable.rb +14 -7
- data/vendored/puppet/lib/puppet/pops/types/p_object_type.rb +38 -7
- data/vendored/puppet/lib/puppet/pops/types/p_object_type_extension.rb +21 -22
- data/vendored/puppet/lib/puppet/pops/types/p_sem_ver_range_type.rb +0 -1
- data/vendored/puppet/lib/puppet/pops/types/p_type_set_type.rb +0 -1
- data/vendored/puppet/lib/puppet/pops/types/p_uri_type.rb +0 -1
- data/vendored/puppet/lib/puppet/pops/types/puppet_object.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/types/string_converter.rb +5 -1
- data/vendored/puppet/lib/puppet/pops/types/type_calculator.rb +5 -1
- data/vendored/puppet/lib/puppet/pops/types/type_factory.rb +1 -5
- data/vendored/puppet/lib/puppet/pops/types/type_formatter.rb +21 -0
- data/vendored/puppet/lib/puppet/pops/types/types.rb +2 -7
- data/vendored/puppet/lib/puppet/pops/validation/checker4_0.rb +1 -3
- data/vendored/puppet/lib/puppet/property.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/augeas/augeas.rb +3 -4
- data/vendored/puppet/lib/puppet/provider/exec.rb +0 -2
- data/vendored/puppet/lib/puppet/provider/nameservice.rb +6 -1
- data/vendored/puppet/lib/puppet/provider/nameservice/directoryservice.rb +3 -3
- data/vendored/puppet/lib/puppet/provider/package/appdmg.rb +0 -1
- data/vendored/puppet/lib/puppet/provider/package/apple.rb +0 -1
- data/vendored/puppet/lib/puppet/provider/package/macports.rb +2 -2
- data/vendored/puppet/lib/puppet/provider/package/pkgdmg.rb +0 -1
- data/vendored/puppet/lib/puppet/provider/package/portage.rb +0 -1
- data/vendored/puppet/lib/puppet/provider/package/zypper.rb +2 -2
- data/vendored/puppet/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +2 -2
- data/vendored/puppet/lib/puppet/provider/service/init.rb +1 -0
- data/vendored/puppet/lib/puppet/provider/service/launchd.rb +3 -3
- data/vendored/puppet/lib/puppet/provider/user/aix.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/user/openbsd.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/user/pw.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/yumrepo/inifile.rb +2 -4
- data/vendored/puppet/lib/puppet/provider/zfs/zfs.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/zpool/zpool.rb +1 -1
- data/vendored/puppet/lib/puppet/reference/type.rb +0 -1
- data/vendored/puppet/lib/puppet/resource.rb +1 -2
- data/vendored/puppet/lib/puppet/resource/status.rb +0 -1
- data/vendored/puppet/lib/puppet/resource/type.rb +3 -3
- data/vendored/puppet/lib/puppet/resource/type_collection.rb +1 -1
- data/vendored/puppet/lib/puppet/settings/environment_conf.rb +0 -1
- data/vendored/puppet/lib/puppet/ssl/host.rb +1 -1
- data/vendored/puppet/lib/puppet/syntax_checkers/base64.rb +1 -1
- data/vendored/puppet/lib/puppet/transaction/persistence.rb +1 -1
- data/vendored/puppet/lib/puppet/type.rb +17 -4
- data/vendored/puppet/lib/puppet/type/file.rb +3 -3
- data/vendored/puppet/lib/puppet/type/mount.rb +9 -0
- data/vendored/puppet/lib/puppet/type/schedule.rb +25 -13
- data/vendored/puppet/lib/puppet/type/tidy.rb +2 -2
- data/vendored/puppet/lib/puppet/type/user.rb +1 -1
- data/vendored/puppet/lib/puppet/util.rb +19 -14
- data/vendored/puppet/lib/puppet/util/filetype.rb +2 -2
- data/vendored/puppet/lib/puppet/util/json_lockfile.rb +1 -1
- data/vendored/puppet/lib/puppet/util/log.rb +5 -3
- data/vendored/puppet/lib/puppet/util/log/destinations.rb +0 -1
- data/vendored/puppet/lib/puppet/util/monkey_patches.rb +1 -1
- data/vendored/puppet/lib/puppet/util/network_device/config.rb +2 -2
- data/vendored/puppet/lib/puppet/util/plist.rb +6 -4
- data/vendored/puppet/lib/puppet/util/rdoc/generators/puppet_generator.rb +1 -1
- data/vendored/puppet/lib/puppet/util/rdoc/parser/puppet_parser_rdoc2.rb +1 -1
- data/vendored/puppet/lib/puppet/util/storage.rb +2 -2
- data/vendored/puppet/lib/puppet/util/windows/registry.rb +2 -2
- data/vendored/puppet/lib/puppet/util/windows/sid.rb +0 -2
- data/vendored/puppet/lib/puppet/version.rb +1 -1
- data/vendored/puppet/lib/puppet_pal.rb +30 -17
- metadata +28 -7
- data/vendored/puppet/lib/puppet/pops/types/execution_result.rb +0 -137
data/lib/bolt/executor.rb
CHANGED
@@ -7,12 +7,15 @@ require 'bolt/notifier'
|
|
7
7
|
|
8
8
|
module Bolt
|
9
9
|
class Executor
|
10
|
-
|
10
|
+
attr_reader :noop
|
11
|
+
|
12
|
+
def initialize(config = Bolt::Config.new, noop = nil)
|
11
13
|
@config = config
|
12
14
|
@logger = Logger.new(config[:log_destination])
|
13
15
|
@logger.progname = 'executor'
|
14
16
|
@logger.level = config[:log_level]
|
15
17
|
@logger.formatter = Bolt::Formatter.new
|
18
|
+
@noop = noop
|
16
19
|
@notifier = Bolt::Notifier.new
|
17
20
|
end
|
18
21
|
|
data/lib/bolt/node.rb
CHANGED
@@ -3,6 +3,7 @@ require 'bolt/node_uri'
|
|
3
3
|
require 'bolt/formatter'
|
4
4
|
require 'bolt/result'
|
5
5
|
require 'bolt/config'
|
6
|
+
require 'bolt/target'
|
6
7
|
|
7
8
|
module Bolt
|
8
9
|
class Node
|
@@ -29,7 +30,7 @@ module Bolt
|
|
29
30
|
|
30
31
|
def self.initialize_transport(_logger); end
|
31
32
|
|
32
|
-
attr_reader :logger, :host, :uri, :user, :password, :connect_timeout
|
33
|
+
attr_reader :logger, :host, :port, :uri, :user, :password, :connect_timeout
|
33
34
|
|
34
35
|
def initialize(host, port = nil, user = nil, password = nil, uri: nil,
|
35
36
|
config: Bolt::Config.new)
|
@@ -41,6 +42,7 @@ module Bolt
|
|
41
42
|
@user = user || transport_conf[:user]
|
42
43
|
@password = password || transport_conf[:password]
|
43
44
|
@key = transport_conf[:key]
|
45
|
+
@cacert = transport_conf[:cacert]
|
44
46
|
@tty = transport_conf[:tty]
|
45
47
|
@insecure = transport_conf[:insecure]
|
46
48
|
@connect_timeout = transport_conf[:connect_timeout]
|
@@ -48,6 +50,9 @@ module Bolt
|
|
48
50
|
@sudo_password = transport_conf[:sudo_password]
|
49
51
|
@run_as = transport_conf[:run_as]
|
50
52
|
@tmpdir = transport_conf[:tmpdir]
|
53
|
+
@service_url = transport_conf[:service_url]
|
54
|
+
@token_file = transport_conf[:token_file]
|
55
|
+
@orch_task_environment = transport_conf[:orch_task_environment]
|
51
56
|
|
52
57
|
@logger = init_logger(config[:log_destination], config[:log_level])
|
53
58
|
@transport_logger = init_logger(config[:log_destination], Logger::WARN)
|
data/lib/bolt/node/orch.rb
CHANGED
@@ -16,7 +16,11 @@ module Bolt
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def make_client
|
19
|
-
|
19
|
+
opts = {}
|
20
|
+
opts["service-url"] = @service_url if @service_url
|
21
|
+
opts["token-file"] = @token_file if @token_file
|
22
|
+
opts["cacert"] = @cacert if @cacert
|
23
|
+
OrchestratorClient.new(opts, true)
|
20
24
|
end
|
21
25
|
|
22
26
|
def client
|
@@ -41,7 +45,9 @@ module Bolt
|
|
41
45
|
|
42
46
|
def _run_task(task, _input_method, arguments)
|
43
47
|
body = { task: task_name_from_path(task),
|
44
|
-
|
48
|
+
environment: @orch_task_environment,
|
49
|
+
noop: arguments['_noop'],
|
50
|
+
params: arguments.reject { |k, _| k == '_noop' },
|
45
51
|
scope: {
|
46
52
|
nodes: [@host]
|
47
53
|
} }
|
@@ -53,6 +59,18 @@ module Bolt
|
|
53
59
|
|
54
60
|
if state == 'finished'
|
55
61
|
exit_code = 0
|
62
|
+
elsif state == 'skipped'
|
63
|
+
return Bolt::TaskResult.new(
|
64
|
+
JSON.dump(
|
65
|
+
'_error' => {
|
66
|
+
'kind' => 'puppetlabs.tasks/skipped-node',
|
67
|
+
'msg' => "Node #{@host} was skipped",
|
68
|
+
'details' => {}
|
69
|
+
}
|
70
|
+
),
|
71
|
+
nil,
|
72
|
+
nil
|
73
|
+
)
|
56
74
|
else
|
57
75
|
# Try to extract the exit_code from _error
|
58
76
|
begin
|
data/lib/bolt/node/winrm.rb
CHANGED
@@ -9,40 +9,52 @@ module Bolt
|
|
9
9
|
'winrm'
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
12
|
+
def port
|
13
|
+
default_port = @insecure ? 5985 : 5986
|
14
|
+
@port || default_port
|
15
|
+
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
def initialize(host, port, user, password, **kwargs)
|
18
|
+
super(host, port, user, password, **kwargs)
|
17
19
|
end
|
18
20
|
|
19
21
|
def connect
|
20
|
-
|
22
|
+
if @insecure
|
23
|
+
scheme = 'http'
|
24
|
+
transport = :negotiate
|
25
|
+
else
|
26
|
+
scheme = 'https'
|
27
|
+
transport = :ssl
|
28
|
+
end
|
29
|
+
endpoint = "#{scheme}://#{host}:#{port}/wsman"
|
30
|
+
options = { endpoint: endpoint,
|
21
31
|
user: @user,
|
22
32
|
password: @password,
|
23
|
-
retry_limit: 1
|
33
|
+
retry_limit: 1,
|
34
|
+
transport: transport,
|
35
|
+
ca_trust_path: @cacert }
|
24
36
|
|
25
37
|
Timeout.timeout(@connect_timeout) do
|
26
38
|
@connection = ::WinRM::Connection.new(options)
|
27
39
|
@connection.logger = @transport_logger
|
28
40
|
|
29
|
-
@session = @connection.shell(
|
41
|
+
@session = @connection.shell(:powershell)
|
30
42
|
@session.run('$PSVersionTable.PSVersion')
|
31
43
|
@logger.debug { "Opened session" }
|
32
44
|
end
|
33
45
|
rescue Timeout::Error
|
34
46
|
raise Bolt::Node::ConnectError.new(
|
35
|
-
"Timeout after #{@connect_timeout} seconds connecting to #{
|
47
|
+
"Timeout after #{@connect_timeout} seconds connecting to #{endpoint}",
|
36
48
|
'CONNECT_ERROR'
|
37
49
|
)
|
38
50
|
rescue ::WinRM::WinRMAuthorizationError
|
39
51
|
raise Bolt::Node::ConnectError.new(
|
40
|
-
"Authentication failed for #{
|
52
|
+
"Authentication failed for #{endpoint}",
|
41
53
|
'AUTH_ERROR'
|
42
54
|
)
|
43
55
|
rescue StandardError => e
|
44
56
|
raise Bolt::Node::ConnectError.new(
|
45
|
-
"Failed to connect to #{
|
57
|
+
"Failed to connect to #{endpoint}: #{e.message}",
|
46
58
|
'CONNECT_ERROR'
|
47
59
|
)
|
48
60
|
end
|
data/lib/bolt/node_uri.rb
CHANGED
@@ -7,13 +7,11 @@ module Bolt
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def parse(string, transport)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
uri.port ||= 5985 if uri.scheme == 'winrm'
|
16
|
-
uri
|
10
|
+
if string =~ %r{^[^:]+://}
|
11
|
+
Addressable::URI.parse(string)
|
12
|
+
else
|
13
|
+
Addressable::URI.parse("#{transport}://#{string}")
|
14
|
+
end
|
17
15
|
end
|
18
16
|
private :parse
|
19
17
|
|
data/lib/bolt/outputter/human.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'terminal-table'
|
1
2
|
module Bolt
|
2
3
|
class Outputter
|
3
4
|
class Human < Bolt::Outputter
|
@@ -77,11 +78,69 @@ module Bolt
|
|
77
78
|
elapsed_time)
|
78
79
|
end
|
79
80
|
|
81
|
+
def print_table(results)
|
82
|
+
@stream.puts Terminal::Table.new(
|
83
|
+
rows: results,
|
84
|
+
style: {
|
85
|
+
border_x: '',
|
86
|
+
border_y: '',
|
87
|
+
border_i: '',
|
88
|
+
padding_left: 0,
|
89
|
+
padding_right: 3,
|
90
|
+
border_top: false,
|
91
|
+
border_bottom: false
|
92
|
+
}
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
# @param [Hash] A hash representing the task
|
97
|
+
def print_task_info(task)
|
98
|
+
# Building lots of strings...
|
99
|
+
pretty_params = ""
|
100
|
+
task_info = ""
|
101
|
+
usage = "bolt task run --nodes, -n <node-name> #{task['name']}"
|
102
|
+
|
103
|
+
if task['parameters']
|
104
|
+
task['parameters'].each do |k, v|
|
105
|
+
pretty_params << "- #{k}: #{v['type']}\n"
|
106
|
+
pretty_params << " #{v['description']}\n" if v['description']
|
107
|
+
usage << if !v['type'].to_s.include? "Optional"
|
108
|
+
" #{k}=<value>"
|
109
|
+
else
|
110
|
+
" [#{k}=<value>]"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
usage << " [--noop]" if task['supports_noop']
|
116
|
+
|
117
|
+
task_info << "\n#{task['name']}"
|
118
|
+
task_info << " - #{task['description']}" if task['description']
|
119
|
+
task_info << "\n\n"
|
120
|
+
task_info << "USAGE:\n#{usage}\n\n"
|
121
|
+
task_info << "PARAMETERS:\n#{pretty_params}\n" if task['parameters']
|
122
|
+
@stream.puts(task_info)
|
123
|
+
end
|
124
|
+
|
80
125
|
def print_plan(result)
|
81
|
-
|
126
|
+
# If a hash or array, pretty-print as JSON
|
127
|
+
if result.is_a?(Hash) || result.is_a?(Array)
|
128
|
+
if result.empty?
|
129
|
+
# Avoids extra lines for an empty result
|
130
|
+
@stream.puts(result.to_json)
|
131
|
+
else
|
132
|
+
@stream.puts(::JSON.pretty_generate(result))
|
133
|
+
end
|
134
|
+
else
|
135
|
+
@stream.puts result.to_s
|
136
|
+
end
|
82
137
|
end
|
83
138
|
|
84
139
|
def fatal_error(e); end
|
85
140
|
end
|
141
|
+
|
142
|
+
def print_message(message)
|
143
|
+
@stream.puts(message)
|
144
|
+
end
|
86
145
|
end
|
87
146
|
end
|
data/lib/bolt/outputter/json.rb
CHANGED
@@ -43,7 +43,16 @@ module Bolt
|
|
43
43
|
elapsed_time)
|
44
44
|
end
|
45
45
|
|
46
|
+
def print_table(results)
|
47
|
+
@stream.puts results.to_json
|
48
|
+
end
|
49
|
+
|
50
|
+
def print_task_info(task)
|
51
|
+
@stream.puts task.to_json
|
52
|
+
end
|
53
|
+
|
46
54
|
def print_plan(result)
|
55
|
+
# Ruby JSON patches most objects to have a to_json method.
|
47
56
|
@stream.puts result.to_json
|
48
57
|
end
|
49
58
|
|
@@ -53,6 +62,8 @@ module Bolt
|
|
53
62
|
@stream.puts e.to_json
|
54
63
|
@stream.puts '}' if @object_open
|
55
64
|
end
|
65
|
+
|
66
|
+
def print_message(message); end
|
56
67
|
end
|
57
68
|
end
|
58
69
|
end
|
data/lib/bolt/target.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Bolt
|
2
|
+
class Target
|
3
|
+
attr_reader :host, :options
|
4
|
+
|
5
|
+
def self.from_asserted_hash(hash)
|
6
|
+
new(hash['host'], hash['options'])
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(host, options = {})
|
10
|
+
@host = host
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def eql?(other)
|
15
|
+
self.class.equal?(other.class) && @host == other.host && @options == other.options
|
16
|
+
end
|
17
|
+
alias == eql?
|
18
|
+
|
19
|
+
def hash
|
20
|
+
@host.hash ^ @options.hash
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
# Use Puppet::Pops::Types::StringConverter if it is available
|
25
|
+
if Object.const_defined?(:Puppet) && Puppet.const_defined?(:Pops)
|
26
|
+
Puppet::Pops::Types::StringConverter.singleton.convert(self)
|
27
|
+
else
|
28
|
+
"Target('#{@host}', #{@options})"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/bolt/version.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
Puppet::DataTypes.create_type('ExecutionResult') do
|
2
|
+
interface <<-PUPPET
|
3
|
+
attributes => {
|
4
|
+
'result_hash' => Hash[
|
5
|
+
String[1],
|
6
|
+
Struct[
|
7
|
+
Optional[value] => Data,
|
8
|
+
Optional[error] => Struct[
|
9
|
+
msg => String[1],
|
10
|
+
Optional[kind] => String[1],
|
11
|
+
Optional[issue_code] => String[1],
|
12
|
+
Optional[details] => Hash[String[1], Data]]]]
|
13
|
+
},
|
14
|
+
functions => {
|
15
|
+
count => Callable[[], Integer],
|
16
|
+
empty => Callable[[], Boolean],
|
17
|
+
error_nodes => Callable[[], ExecutionResult],
|
18
|
+
names => Callable[[], Array[String[1]]],
|
19
|
+
ok => Callable[[], Boolean],
|
20
|
+
ok_nodes => Callable[[], ExecutionResult],
|
21
|
+
value => Callable[[String[1]], Variant[Error, Data]],
|
22
|
+
values => Callable[[], Array[Variant[Error,Data]]],
|
23
|
+
'[]' => Callable[[String[1]], Variant[Error, Data]]
|
24
|
+
}
|
25
|
+
PUPPET
|
26
|
+
|
27
|
+
load_file('bolt/executionresult')
|
28
|
+
|
29
|
+
implementation_class Bolt::ExecutionResult
|
30
|
+
end
|
@@ -39,15 +39,15 @@ Puppet::Functions.create_function(:file_upload, Puppet::Functions::InternalFunct
|
|
39
39
|
end
|
40
40
|
|
41
41
|
# Ensure that that given targets are all Target instances
|
42
|
-
targets = targets.flatten.map { |t| t.is_a?(String) ?
|
42
|
+
targets = targets.flatten.map { |t| t.is_a?(String) ? Bolt::Target.new(t) : t }
|
43
43
|
if targets.empty?
|
44
44
|
call_function('debug', "Simulating file upload of '#{found}' - no targets given - no action taken")
|
45
|
-
|
45
|
+
Bolt::ExecutionResult::EMPTY_RESULT
|
46
46
|
else
|
47
47
|
# Awaits change in the executor, enabling it receive Target instances
|
48
48
|
hosts = targets.map(&:host)
|
49
49
|
|
50
|
-
|
50
|
+
Bolt::ExecutionResult.from_bolt(
|
51
51
|
executor.file_upload(executor.from_uris(hosts), found, destination)
|
52
52
|
)
|
53
53
|
end
|
@@ -30,16 +30,16 @@ Puppet::Functions.create_function(:run_command) do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# Ensure that that given targets are all Target instances
|
33
|
-
targets = targets.flatten.map { |t| t.is_a?(String) ?
|
33
|
+
targets = targets.flatten.map { |t| t.is_a?(String) ? Bolt::Target.new(t) : t }
|
34
34
|
|
35
35
|
if targets.empty?
|
36
36
|
call_function('debug', "Simulating run_command('#{command}') - no targets given - no action taken")
|
37
|
-
|
37
|
+
Bolt::ExecutionResult::EMPTY_RESULT
|
38
38
|
else
|
39
39
|
# Awaits change in the executor, enabling it receive Target instances
|
40
40
|
hosts = targets.map(&:host)
|
41
41
|
|
42
|
-
|
42
|
+
Bolt::ExecutionResult.from_bolt(executor.run_command(executor.from_uris(hosts), command))
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -54,15 +54,15 @@ Puppet::Functions.create_function(:run_script, Puppet::Functions::InternalFuncti
|
|
54
54
|
end
|
55
55
|
|
56
56
|
# Ensure that that given targets are all Target instances)
|
57
|
-
targets = [targets].flatten.map { |t| t.is_a?(String) ?
|
57
|
+
targets = [targets].flatten.map { |t| t.is_a?(String) ? Bolt::Target.new(t) : t }
|
58
58
|
if targets.empty?
|
59
59
|
call_function('debug', "Simulating run_script of '#{found}' - no targets given - no action taken")
|
60
|
-
|
60
|
+
Bolt::ExecutionResult::EMPTY_RESULT
|
61
61
|
else
|
62
62
|
# Awaits change in the executor, enabling it receive Target instances
|
63
63
|
hosts = targets.map(&:host)
|
64
64
|
|
65
|
-
|
65
|
+
Bolt::ExecutionResult.from_bolt(
|
66
66
|
executor.run_script(executor.from_uris(hosts), found, args_hash['arguments'])
|
67
67
|
)
|
68
68
|
end
|
@@ -25,7 +25,7 @@ Puppet::Functions.create_function(:run_task) do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def run_task(task_name, targets, task_args = nil)
|
28
|
-
|
28
|
+
Bolt::ExecutionResult.from_bolt(
|
29
29
|
run_task_raw(task_name, targets, task_args)
|
30
30
|
)
|
31
31
|
end
|
@@ -58,9 +58,17 @@ Puppet::Functions.create_function(:run_task) do
|
|
58
58
|
end || (raise Puppet::ParseError, 'Task parameters did not match')
|
59
59
|
task = task_signature.task
|
60
60
|
|
61
|
+
if executor.noop
|
62
|
+
if task.supports_noop
|
63
|
+
use_args['_noop'] = true
|
64
|
+
else
|
65
|
+
raise Puppet::ParseError, 'Task does not support noop'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
61
69
|
# Ensure that that given targets are all Target instances
|
62
70
|
targets = [targets] unless targets.is_a?(Array)
|
63
|
-
targets = targets.flatten.map { |t| t.is_a?(String) ?
|
71
|
+
targets = targets.flatten.map { |t| t.is_a?(String) ? Bolt::Target.new(t) : t }
|
64
72
|
if targets.empty?
|
65
73
|
call_function('debug', "Simulating run of task #{task.name} - no targets given - no action taken")
|
66
74
|
Puppet::Pops::EMPTY_HASH
|