Module: BoltSpec::Run

Defined in:
lib/bolt_spec/run.rb

Defined Under Namespace

Classes: BoltRunner

Instance Method Summary collapse

Instance Method Details

#apply_manifest(manifest, targets, execute: false, noop: false, config: nil, inventory: nil) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/bolt_spec/run.rb', line 99

def apply_manifest(manifest, targets, execute: false, noop: false, config: nil, inventory: nil)
  if config.nil? && defined?(bolt_config)
    config = bolt_config
  end

  if inventory.nil? && defined?(bolt_inventory)
    inventory = bolt_inventory
  end

  # 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.expand_path(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, options: {}, config: nil, inventory: nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/bolt_spec/run.rb', line 51

def run_command(command, targets, options: {}, config: nil, inventory: nil)
  if config.nil? && defined?(bolt_config)
    config = bolt_config
  end

  if inventory.nil? && defined?(bolt_inventory)
    inventory = bolt_inventory
  end

  result = BoltRunner.with_runner(config, inventory) do |runner|
    runner.run_command(command, targets, options)
  end
  result = result.to_a
  Bolt::Util.walk_keys(result, &:to_s)
end

#run_plan(plan_name, params, config: nil, inventory: nil) ⇒ Object

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bolt_spec/run.rb', line 31

def run_plan(plan_name, params, config: nil, inventory: nil)
  if config.nil? && defined?(bolt_config)
    config = bolt_config
  end

  if inventory.nil? && defined?(bolt_inventory)
    inventory = bolt_inventory
  end

  # Users copying code from run_task may forget that targets is not a parameter for run plan
  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, options: {}, config: nil, inventory: nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/bolt_spec/run.rb', line 67

def run_script(script, targets, arguments, options: {}, config: nil, inventory: nil)
  if config.nil? && defined?(bolt_config)
    config = bolt_config
  end

  if inventory.nil? && defined?(bolt_inventory)
    inventory = bolt_inventory
  end

  result = BoltRunner.with_runner(config, inventory) do |runner|
    runner.run_script(script, targets, arguments, options)
  end
  result = result.to_a
  Bolt::Util.walk_keys(result, &:to_s)
end

#run_task(task_name, targets, params, config: nil, inventory: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bolt_spec/run.rb', line 15

def run_task(task_name, targets, params, config: nil, inventory: nil)
  if config.nil? && defined?(bolt_config)
    config = bolt_config
  end

  if inventory.nil? && defined?(bolt_inventory)
    inventory = bolt_inventory
  end

  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

#upload_file(source, dest, targets, options: {}, config: nil, inventory: nil) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/bolt_spec/run.rb', line 83

def upload_file(source, dest, targets, options: {}, config: nil, inventory: nil)
  if config.nil? && defined?(bolt_config)
    config = bolt_config
  end

  if inventory.nil? && defined?(bolt_inventory)
    inventory = bolt_inventory
  end

  result = BoltRunner.with_runner(config, inventory) do |runner|
    runner.upload_file(source, dest, targets, options)
  end
  result = result.to_a
  Bolt::Util.walk_keys(result, &:to_s)
end