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
- #hook_descriptions ⇒ Object
- #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.
24 25 26 |
# File 'lib/bolt/plugin/task.rb', line 24 def initialize(context:, **_opts) @context = context end |
Instance Attribute Details
#executor ⇒ Object
Returns the value of attribute executor.
22 23 24 |
# File 'lib/bolt/plugin/task.rb', line 22 def executor @executor end |
#inventory ⇒ Object
Returns the value of attribute inventory.
22 23 24 |
# File 'lib/bolt/plugin/task.rb', line 22 def inventory @inventory end |
#pal ⇒ Object
Returns the value of attribute pal.
22 23 24 |
# File 'lib/bolt/plugin/task.rb', line 22 def pal @pal end |
Instance Method Details
#hook_descriptions ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/bolt/plugin/task.rb', line 10 def hook_descriptions { puppet_library: 'Run a task to install the Puppet agent package.', resolve_reference: 'Run a task as a plugin.', validate_resolve_reference: nil } end |
#hooks ⇒ Object
6 7 8 |
# File 'lib/bolt/plugin/task.rb', line 6 def hooks hook_descriptions.keys end |
#name ⇒ Object
18 19 20 |
# File 'lib/bolt/plugin/task.rb', line 18 def name 'task' end |
#puppet_library(opts, target, apply_prep) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/bolt/plugin/task.rb', line 57 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 = @context.get_validated_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
47 48 49 50 51 52 53 54 55 |
# File 'lib/bolt/plugin/task.rb', line 47 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
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bolt/plugin/task.rb', line 28 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
41 42 43 44 |
# File 'lib/bolt/plugin/task.rb', line 41 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 |