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.
156 157 158 159 160 161 162 163 |
# File 'lib/bolt_spec/run.rb', line 156 def initialize(config_data, inventory_data, project_path) Bolt::Logger.initialize_logging @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
149 150 151 152 153 154 |
# File 'lib/bolt_spec/run.rb', line 149 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
231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/bolt_spec/run.rb', line 231 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
165 166 167 |
# File 'lib/bolt_spec/run.rb', line 165 def config @config ||= Bolt::Config.new(Bolt::Project.create_project(@project_path), @config_data) end |
#download_file(source, dest, targets, options = {}) ⇒ Object
219 220 221 222 223 |
# File 'lib/bolt_spec/run.rb', line 219 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
169 170 171 |
# File 'lib/bolt_spec/run.rb', line 169 def inventory @inventory ||= Bolt::Inventory.create_version(@inventory_data, config.transport, config.transports, plugins) end |
#pal ⇒ Object
181 182 183 184 185 186 187 188 189 |
# File 'lib/bolt_spec/run.rb', line 181 def pal @pal ||= Bolt::PAL.new(Bolt::Config::Modulepath.new(config.modulepath), config.hiera_config, config.project.resource_types, config.compile_concurrency, config.trusted_external, config.apply_settings, config.project) end |
#plugins ⇒ Object
173 174 175 |
# File 'lib/bolt_spec/run.rb', line 173 def plugins @plugins ||= Bolt::Plugin.new(config, pal) end |
#puppetdb_client ⇒ Object
177 178 179 |
# File 'lib/bolt_spec/run.rb', line 177 def puppetdb_client plugins.puppetdb_client end |
#resolve_targets(target_spec) ⇒ Object
191 192 193 |
# File 'lib/bolt_spec/run.rb', line 191 def resolve_targets(target_spec) @inventory.get_targets(target_spec).map(&:name) end |
#run_command(command, targets, options) ⇒ Object
207 208 209 210 211 |
# File 'lib/bolt_spec/run.rb', line 207 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
202 203 204 205 |
# File 'lib/bolt_spec/run.rb', line 202 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
213 214 215 216 217 |
# File 'lib/bolt_spec/run.rb', line 213 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
196 197 198 199 |
# File 'lib/bolt_spec/run.rb', line 196 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
225 226 227 228 229 |
# File 'lib/bolt_spec/run.rb', line 225 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 |