Module: BoltSpec::Run
- Defined in:
- lib/bolt_spec/run.rb
Defined Under Namespace
Classes: BoltRunner
Instance Method Summary collapse
- #apply_manifest(manifest, targets, execute: false, noop: false, config: nil, inventory: nil) ⇒ Object
- #run_command(command, targets, params = nil, config: nil, inventory: nil) ⇒ Object
- #run_plan(plan_name, params = nil, config: nil, inventory: nil) ⇒ Object
- #run_script(script, targets, arguments = nil, options = {}, config: nil, inventory: nil) ⇒ Object
- #run_task(task_name, targets, params = nil, config: nil, inventory: nil) ⇒ Object
Instance Method Details
#apply_manifest(manifest, targets, execute: false, noop: false, config: nil, inventory: nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/bolt_spec/run.rb', line 51 def apply_manifest(manifest, targets, execute: false, noop: false, config: nil, inventory: nil) # The execute parameter is equivalent to the --execute option if execute code = manifest else begin unless File.stat(manifest).readable? raise BOLT::FileError.new("The manifest '#{manifest}' is unreadable", manifest) end rescue Errno::ENOENT raise Bolt::FileError.new("The manifest '#{manifest}' does not exist", manifest) end code = File.read(File.(manifest)) filename = manifest end result = BoltRunner.with_runner(config, inventory) do |runner| runner.apply_manifest(code, targets, filename, noop) end JSON.parse(result.to_json) end |
#run_command(command, targets, params = nil, config: nil, inventory: nil) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/bolt_spec/run.rb', line 35 def run_command(command, targets, params = nil, config: nil, inventory: nil) result = BoltRunner.with_runner(config, inventory) do |runner| runner.run_command(command, targets, params) end result = result.to_a Bolt::Util.walk_keys(result, &:to_s) end |
#run_plan(plan_name, params = nil, config: nil, inventory: nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bolt_spec/run.rb', line 22 def run_plan(plan_name, params = nil, config: nil, inventory: nil) # Users copying code from run_task may forget that targets is not a parameter for run plan params ||= {} raise ArgumentError, "params must be a hash" unless params.is_a?(Hash) result = BoltRunner.with_runner(config, inventory) do |runner| runner.run_plan(plan_name, params || {}) end { "status" => result.status, "value" => JSON.parse(result.value.to_json) } end |
#run_script(script, targets, arguments = nil, options = {}, config: nil, inventory: nil) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/bolt_spec/run.rb', line 43 def run_script(script, targets, arguments = nil, = {}, config: nil, inventory: nil) result = BoltRunner.with_runner(config, inventory) do |runner| runner.run_script(script, targets, arguments, ) end result = result.to_a Bolt::Util.walk_keys(result, &:to_s) end |
#run_task(task_name, targets, params = nil, config: nil, inventory: nil) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/bolt_spec/run.rb', line 14 def run_task(task_name, targets, params = nil, config: nil, inventory: nil) result = BoltRunner.with_runner(config, inventory) do |runner| runner.run_task(task_name, targets, params || {}) end result = result.to_a Bolt::Util.walk_keys(result, &:to_s) end |