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
-
#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.
139 140 141 142 143 144 |
# File 'lib/bolt_spec/run.rb', line 139 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
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 |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
203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/bolt_spec/run.rb', line 203 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
146 147 148 |
# File 'lib/bolt_spec/run.rb', line 146 def config @config ||= Bolt::Config.new(Bolt::Project.new(@project_path), @config_data) end |
#inventory ⇒ Object
150 151 152 |
# File 'lib/bolt_spec/run.rb', line 150 def inventory @inventory ||= Bolt::Inventory.create_version(@inventory_data, config.transport, config.transports, plugins) end |
#pal ⇒ Object
162 163 164 165 166 167 |
# File 'lib/bolt_spec/run.rb', line 162 def pal @pal ||= Bolt::PAL.new(config.modulepath, config.hiera_config, config.project.resource_types, config.compile_concurrency) end |
#plugins ⇒ Object
154 155 156 |
# File 'lib/bolt_spec/run.rb', line 154 def plugins @plugins ||= Bolt::Plugin.setup(config, pal) end |
#puppetdb_client ⇒ Object
158 159 160 |
# File 'lib/bolt_spec/run.rb', line 158 def puppetdb_client plugins.puppetdb_client end |
#resolve_targets(target_spec) ⇒ Object
169 170 171 |
# File 'lib/bolt_spec/run.rb', line 169 def resolve_targets(target_spec) @inventory.get_targets(target_spec).map(&:name) end |
#run_command(command, targets, options) ⇒ Object
185 186 187 188 189 |
# File 'lib/bolt_spec/run.rb', line 185 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
180 181 182 183 |
# File 'lib/bolt_spec/run.rb', line 180 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
191 192 193 194 195 |
# File 'lib/bolt_spec/run.rb', line 191 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
174 175 176 177 |
# File 'lib/bolt_spec/run.rb', line 174 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
197 198 199 200 201 |
# File 'lib/bolt_spec/run.rb', line 197 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 |