Class: BoltSpec::Run::BoltRunner

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, inventory) ⇒ BoltRunner

Returns a new instance of BoltRunner.



58
59
60
61
62
# File 'lib/bolt_spec/run.rb', line 58

def initialize(config, inventory)
  @config = config
  @inventory = inventory
  @analytics = Bolt::Analytics::NoopClient.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



56
57
58
# File 'lib/bolt_spec/run.rb', line 56

def config
  @config
end

#inventoryObject (readonly)

Returns the value of attribute inventory.



56
57
58
# File 'lib/bolt_spec/run.rb', line 56

def inventory
  @inventory
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



48
49
50
51
52
53
54
# File 'lib/bolt_spec/run.rb', line 48

def self.with_runner(config_data, inventory_data)
  Dir.mktmpdir do |boltdir_path|
    config = Bolt::Config.new(Bolt::Boltdir.new(boltdir_path), config_data || {})
    inventory = Bolt::Inventory.new(inventory_data || {}, config)
    yield new(config, inventory)
  end
end

Instance Method Details

#palObject



71
72
73
# File 'lib/bolt_spec/run.rb', line 71

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

#puppetdb_clientObject



64
65
66
67
68
69
# File 'lib/bolt_spec/run.rb', line 64

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



75
76
77
# File 'lib/bolt_spec/run.rb', line 75

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

#run_command(command, targets, params = nil) ⇒ Object



91
92
93
94
95
# File 'lib/bolt_spec/run.rb', line 91

def run_command(command, targets, params = nil)
  executor = Bolt::Executor.new(config.concurrency, @analytics)
  targets = inventory.get_targets(targets)
  executor.run_command(targets, command, params || {})
end

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

Adapted from CLI does not handle nodes or plan_job reporting



86
87
88
89
# File 'lib/bolt_spec/run.rb', line 86

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_task(task_name, targets, params, noop: false) ⇒ Object

Adapted from CLI



80
81
82
83
# File 'lib/bolt_spec/run.rb', line 80

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