Class: BoltSpec::Run::BoltRunner
- Inherits:
-
Object
- Object
- BoltSpec::Run::BoltRunner
- Defined in:
- lib/bolt_spec/run.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#inventory ⇒ Object
readonly
Returns the value of attribute inventory.
Class Method Summary collapse
-
.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.
Instance Method Summary collapse
- #apply_manifest(code, targets, filename = nil, noop = false) ⇒ Object
-
#initialize(config, inventory) ⇒ BoltRunner
constructor
A new instance of BoltRunner.
- #pal ⇒ 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, inventory) ⇒ BoltRunner
Returns a new instance of BoltRunner.
141 142 143 144 145 |
# File 'lib/bolt_spec/run.rb', line 141 def initialize(config, inventory) @config = config @inventory = inventory @analytics = Bolt::Analytics::NoopClient.new end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
139 140 141 |
# File 'lib/bolt_spec/run.rb', line 139 def config @config end |
#inventory ⇒ Object (readonly)
Returns the value of attribute inventory.
139 140 141 |
# File 'lib/bolt_spec/run.rb', line 139 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
131 132 133 134 135 136 137 |
# File 'lib/bolt_spec/run.rb', line 131 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
192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/bolt_spec/run.rb', line 192 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 |
#pal ⇒ Object
154 155 156 |
# File 'lib/bolt_spec/run.rb', line 154 def pal @pal ||= Bolt::PAL.new(config.modulepath, config.hiera_config, config.compile_concurrency) end |
#puppetdb_client ⇒ Object
147 148 149 150 151 152 |
# File 'lib/bolt_spec/run.rb', line 147 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
158 159 160 |
# File 'lib/bolt_spec/run.rb', line 158 def resolve_targets(target_spec) @inventory.get_targets(target_spec).map(&:name) end |
#run_command(command, targets, options) ⇒ Object
174 175 176 177 178 |
# File 'lib/bolt_spec/run.rb', line 174 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
169 170 171 172 |
# File 'lib/bolt_spec/run.rb', line 169 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
180 181 182 183 184 |
# File 'lib/bolt_spec/run.rb', line 180 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
163 164 165 166 |
# File 'lib/bolt_spec/run.rb', line 163 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
186 187 188 189 190 |
# File 'lib/bolt_spec/run.rb', line 186 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 |