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



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/bolt_spec/run.rb', line 116

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

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



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

def download_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.download_file(source, dest, targets, options)
  end
  result = result.to_a
  Bolt::Util.walk_keys(result, &:to_s)
end

#run_command(command, targets, options: {}, config: nil, inventory: nil) ⇒ Object



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

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)


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

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



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

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



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

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



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/bolt_spec/run.rb', line 100

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