Class: Bolt::Plugin::Task
- Inherits:
-
Object
- Object
- Bolt::Plugin::Task
- Defined in:
- lib/bolt/plugin/task.rb
Instance Attribute Summary collapse
-
#executor ⇒ Object
Returns the value of attribute executor.
-
#inventory ⇒ Object
Returns the value of attribute inventory.
-
#pal ⇒ Object
Returns the value of attribute pal.
Instance Method Summary collapse
- #hooks ⇒ Object
-
#initialize(context:, **_opts) ⇒ Task
constructor
A new instance of Task.
- #name ⇒ Object
- #puppet_library(opts, target, apply_prep) ⇒ Object
- #resolve_reference(opts) ⇒ Object
- #run_task(opts) ⇒ Object
- #validate_options(opts) ⇒ Object (also: #validate_resolve_reference)
Constructor Details
#initialize(context:, **_opts) ⇒ Task
Returns a new instance of Task.
16 17 18 |
# File 'lib/bolt/plugin/task.rb', line 16 def initialize(context:, **_opts) @context = context end |
Instance Attribute Details
#executor ⇒ Object
Returns the value of attribute executor.
14 15 16 |
# File 'lib/bolt/plugin/task.rb', line 14 def executor @executor end |
#inventory ⇒ Object
Returns the value of attribute inventory.
14 15 16 |
# File 'lib/bolt/plugin/task.rb', line 14 def inventory @inventory end |
#pal ⇒ Object
Returns the value of attribute pal.
14 15 16 |
# File 'lib/bolt/plugin/task.rb', line 14 def pal @pal end |
Instance Method Details
#hooks ⇒ Object
6 7 8 |
# File 'lib/bolt/plugin/task.rb', line 6 def hooks %i[validate_resolve_reference puppet_library resolve_reference] end |
#name ⇒ Object
10 11 12 |
# File 'lib/bolt/plugin/task.rb', line 10 def name 'task' end |
#puppet_library(opts, target, apply_prep) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bolt/plugin/task.rb', line 49 def puppet_library(opts, target, apply_prep) params = opts['parameters'] || {} run_opts = {} run_opts[:run_as] = opts['_run_as'] if opts['_run_as'] begin task = apply_prep.get_task(opts['task'], params) rescue Bolt::Error => e raise Bolt::Plugin::PluginError::ExecutionError.new(e., name, 'puppet_library') end proc do apply_prep.run_task([target], task, params, run_opts).first end end |
#resolve_reference(opts) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/bolt/plugin/task.rb', line 39 def resolve_reference(opts) result = run_task(opts) unless result.value.include?('value') raise Bolt::ValidationError, "Task result did not return 'value': #{result.value}" end result['value'] end |
#run_task(opts) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bolt/plugin/task.rb', line 20 def run_task(opts) params = opts['parameters'] || {} = { catch_errors: true } raise Bolt::ValidationError, "Task plugin requires that the 'task' is specified" unless opts['task'] task = @context.get_validated_task(opts['task'], params) result = @context.run_local_task(task, params, ).first raise Bolt::Error.new(result.error_hash['msg'], result.error_hash['kind']) if result.error_hash result end |
#validate_options(opts) ⇒ Object Also known as: validate_resolve_reference
33 34 35 36 |
# File 'lib/bolt/plugin/task.rb', line 33 def (opts) raise Bolt::ValidationError, "Task plugin requires that the 'task' is specified" unless opts['task'] @context.get_validated_task(opts['task'], opts['parameters'] || {}) end |