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.



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

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.



83
84
85
# File 'lib/bolt_spec/run.rb', line 83

def config
  @config
end

#inventoryObject (readonly)

Returns the value of attribute inventory.



83
84
85
# File 'lib/bolt_spec/run.rb', line 83

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



75
76
77
78
79
80
81
# File 'lib/bolt_spec/run.rb', line 75

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

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



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/bolt_spec/run.rb', line 130

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

#palObject



98
99
100
# File 'lib/bolt_spec/run.rb', line 98

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

#puppetdb_clientObject



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

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



102
103
104
# File 'lib/bolt_spec/run.rb', line 102

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

#run_command(command, targets, options) ⇒ Object



118
119
120
121
122
# File 'lib/bolt_spec/run.rb', line 118

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



113
114
115
116
# File 'lib/bolt_spec/run.rb', line 113

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



124
125
126
127
128
# File 'lib/bolt_spec/run.rb', line 124

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



107
108
109
110
# File 'lib/bolt_spec/run.rb', line 107

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