Class: BoltSpec::Run::BoltRunner
- Inherits:
-
Object
- Object
- BoltSpec::Run::BoltRunner
- Defined in:
- lib/bolt_spec/run.rb
Class Method Summary collapse
-
.with_runner(config_data, inventory_data) ⇒ Object
Creates a temporary project so no settings are picked up WARNING: puppetdb config and orch config which do not use the project may still be loaded.
Instance Method Summary collapse
- #apply_manifest(code, targets, filename = nil, noop = false) ⇒ Object
- #config ⇒ Object
- #download_file(source, dest, targets, options = {}) ⇒ Object
-
#initialize(config_data, inventory_data, project_path) ⇒ BoltRunner
constructor
A new instance of BoltRunner.
- #inventory ⇒ Object
- #pal ⇒ Object
- #plugins ⇒ Object
- #puppetdb_client ⇒ Object
- #resolve_targets(target_spec) ⇒ Object
- #run_command(command, targets, options) ⇒ Object
-
#run_plan(plan_name, params, noop: false) ⇒ Object
Adapted from CLI does not handle nodes or plan_job reporting.
- #run_script(script, targets, arguments, options = {}) ⇒ Object
-
#run_task(task_name, targets, params, noop: false) ⇒ Object
Adapted from CLI.
- #upload_file(source, dest, targets, options = {}) ⇒ Object
Constructor Details
#initialize(config_data, inventory_data, project_path) ⇒ BoltRunner
Returns a new instance of BoltRunner.
155 156 157 158 159 160 |
# File 'lib/bolt_spec/run.rb', line 155 def initialize(config_data, inventory_data, project_path) @config_data = config_data || {} @inventory_data = inventory_data || {} @project_path = project_path @analytics = Bolt::Analytics::NoopClient.new end |
Class Method Details
.with_runner(config_data, inventory_data) ⇒ Object
Creates a temporary project so no settings are picked up WARNING: puppetdb config and orch config which do not use the project may still be loaded
148 149 150 151 152 153 |
# File 'lib/bolt_spec/run.rb', line 148 def self.with_runner(config_data, inventory_data) Dir.mktmpdir do |project_path| runner = new(Bolt::Util.deep_clone(config_data), Bolt::Util.deep_clone(inventory_data), project_path) yield runner end end |
Instance Method Details
#apply_manifest(code, targets, filename = nil, noop = false) ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/bolt_spec/run.rb', line 225 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 |
#config ⇒ Object
162 163 164 |
# File 'lib/bolt_spec/run.rb', line 162 def config @config ||= Bolt::Config.new(Bolt::Project.create_project(@project_path), @config_data) end |
#download_file(source, dest, targets, options = {}) ⇒ Object
213 214 215 216 217 |
# File 'lib/bolt_spec/run.rb', line 213 def download_file(source, dest, targets, = {}) executor = Bolt::Executor.new(config.concurrency, @analytics) targets = inventory.get_targets(targets) executor.download_file(targets, source, dest, ) end |
#inventory ⇒ Object
166 167 168 |
# File 'lib/bolt_spec/run.rb', line 166 def inventory @inventory ||= Bolt::Inventory.create_version(@inventory_data, config.transport, config.transports, plugins) end |
#pal ⇒ Object
178 179 180 181 182 183 |
# File 'lib/bolt_spec/run.rb', line 178 def pal @pal ||= Bolt::PAL.new(config.modulepath, config.hiera_config, config.project.resource_types, config.compile_concurrency) end |
#plugins ⇒ Object
170 171 172 |
# File 'lib/bolt_spec/run.rb', line 170 def plugins @plugins ||= Bolt::Plugin.setup(config, pal) end |
#puppetdb_client ⇒ Object
174 175 176 |
# File 'lib/bolt_spec/run.rb', line 174 def puppetdb_client plugins.puppetdb_client end |
#resolve_targets(target_spec) ⇒ Object
185 186 187 |
# File 'lib/bolt_spec/run.rb', line 185 def resolve_targets(target_spec) @inventory.get_targets(target_spec).map(&:name) end |
#run_command(command, targets, options) ⇒ Object
201 202 203 204 205 |
# File 'lib/bolt_spec/run.rb', line 201 def run_command(command, targets, ) executor = Bolt::Executor.new(config.concurrency, @analytics) targets = inventory.get_targets(targets) executor.run_command(targets, command, ) end |
#run_plan(plan_name, params, noop: false) ⇒ Object
Adapted from CLI does not handle nodes or plan_job reporting
196 197 198 199 |
# File 'lib/bolt_spec/run.rb', line 196 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
207 208 209 210 211 |
# File 'lib/bolt_spec/run.rb', line 207 def run_script(script, targets, arguments, = {}) executor = Bolt::Executor.new(config.concurrency, @analytics) targets = inventory.get_targets(targets) executor.run_script(targets, script, arguments, ) end |
#run_task(task_name, targets, params, noop: false) ⇒ Object
Adapted from CLI
190 191 192 193 |
# File 'lib/bolt_spec/run.rb', line 190 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
219 220 221 222 223 |
# File 'lib/bolt_spec/run.rb', line 219 def upload_file(source, dest, targets, = {}) executor = Bolt::Executor.new(config.concurrency, @analytics) targets = inventory.get_targets(targets) executor.upload_file(targets, source, dest, ) end |