Class: BoltSpec::Run::BoltRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/bolt_spec/run.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_data, inventory_data, boltdir_path) ⇒ BoltRunner

Returns a new instance of BoltRunner.



139
140
141
142
143
144
# File 'lib/bolt_spec/run.rb', line 139

def initialize(config_data, inventory_data, boltdir_path)
  @config_data = config_data || {}
  @inventory_data = inventory_data || {}
  @boltdir_path = boltdir_path
  @analytics = Bolt::Analytics::NoopClient.new
end

Class Method Details

.with_runner(config_data, inventory_data) ⇒ Object

Creates a temporary boltdir so no settings are picked up WARNING: puppetdb config and orch config which do not use the boltdir may still be loaded



132
133
134
135
136
137
# File 'lib/bolt_spec/run.rb', line 132

def self.with_runner(config_data, inventory_data)
  Dir.mktmpdir do |boltdir_path|
    runner = new(config_data, inventory_data, boltdir_path)
    yield runner
  end
end

Instance Method Details

#apply_manifest(code, targets, filename = nil, noop = false) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/bolt_spec/run.rb', line 206

def apply_manifest(code, targets, filename = nil, noop = false)
  ast = pal.parse_manifest(code, filename)
  executor = Bolt::Executor.new(config.concurrency, @analytics, noop)
  targets = inventory.get_targets(targets)

  pal.in_plan_compiler(executor, inventory, puppetdb_client) do |compiler|
    compiler.call_function('apply_prep', targets)
  end

  pal.with_bolt_executor(executor, inventory, puppetdb_client) do
    Puppet.lookup(:apply_executor).apply_ast(ast, targets, catch_errors: true, noop: noop)
  end
end

#configObject



146
147
148
# File 'lib/bolt_spec/run.rb', line 146

def config
  @config ||= Bolt::Config.new(Bolt::Boltdir.new(@boltdir_path), @config_data)
end

#inventoryObject



150
151
152
# File 'lib/bolt_spec/run.rb', line 150

def inventory
  @inventory ||= Bolt::Inventory.create_version(@inventory_data, config, plugins)
end

#palObject



165
166
167
168
169
170
# File 'lib/bolt_spec/run.rb', line 165

def pal
  @pal ||= Bolt::PAL.new(config.modulepath,
                         config.hiera_config,
                         config.boltdir.resource_types,
                         config.compile_concurrency)
end

#pluginsObject



154
155
156
# File 'lib/bolt_spec/run.rb', line 154

def plugins
  @plugins ||= Bolt::Plugin.setup(config, pal, puppetdb_client, @analytics)
end

#puppetdb_clientObject



158
159
160
161
162
163
# File 'lib/bolt_spec/run.rb', line 158

def puppetdb_client
  @puppetdb_client ||= begin
                         puppetdb_config = Bolt::PuppetDB::Config.load_config(nil, config.puppetdb)
                         Bolt::PuppetDB::Client.new(puppetdb_config)
                       end
end

#resolve_targets(target_spec) ⇒ Object



172
173
174
# File 'lib/bolt_spec/run.rb', line 172

def resolve_targets(target_spec)
  @inventory.get_targets(target_spec).map(&:name)
end

#run_command(command, targets, options) ⇒ Object



188
189
190
191
192
# File 'lib/bolt_spec/run.rb', line 188

def run_command(command, targets, options)
  executor = Bolt::Executor.new(config.concurrency, @analytics)
  targets = inventory.get_targets(targets)
  executor.run_command(targets, command, options)
end

#run_plan(plan_name, params, noop: false) ⇒ Object

Adapted from CLI does not handle nodes or plan_job reporting



183
184
185
186
# File 'lib/bolt_spec/run.rb', line 183

def run_plan(plan_name, params, noop: false)
  executor = Bolt::Executor.new(config.concurrency, @analytics, noop)
  pal.run_plan(plan_name, params, executor, inventory, puppetdb_client)
end

#run_script(script, targets, arguments, options = {}) ⇒ Object



194
195
196
197
198
# File 'lib/bolt_spec/run.rb', line 194

def run_script(script, targets, arguments, options = {})
  executor = Bolt::Executor.new(config.concurrency, @analytics)
  targets = inventory.get_targets(targets)
  executor.run_script(targets, script, arguments, options)
end

#run_task(task_name, targets, params, noop: false) ⇒ Object

Adapted from CLI



177
178
179
180
# File 'lib/bolt_spec/run.rb', line 177

def run_task(task_name, targets, params, noop: false)
  executor = Bolt::Executor.new(config.concurrency, @analytics, noop)
  pal.run_task(task_name, targets, params, executor, inventory, nil) { |_ev| nil }
end

#upload_file(source, dest, targets, options = {}) ⇒ Object



200
201
202
203
204
# File 'lib/bolt_spec/run.rb', line 200

def upload_file(source, dest, targets, options = {})
  executor = Bolt::Executor.new(config.concurrency, @analytics)
  targets = inventory.get_targets(targets)
  executor.upload_file(targets, source, dest, options)
end