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
195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/bolt_spec/run.rb', line 195 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 157 158 159 |
# File 'lib/bolt_spec/run.rb', line 154 def pal @pal ||= Bolt::PAL.new(config.modulepath, config.hiera_config, config.boltdir.resource_types, 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
161 162 163 |
# File 'lib/bolt_spec/run.rb', line 161 def resolve_targets(target_spec) @inventory.get_targets(target_spec).map(&:name) end |
#run_command(command, targets, options) ⇒ Object
177 178 179 180 181 |
# File 'lib/bolt_spec/run.rb', line 177 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
172 173 174 175 |
# File 'lib/bolt_spec/run.rb', line 172 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
183 184 185 186 187 |
# File 'lib/bolt_spec/run.rb', line 183 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
166 167 168 169 |
# File 'lib/bolt_spec/run.rb', line 166 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
189 190 191 192 193 |
# File 'lib/bolt_spec/run.rb', line 189 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 |