bolt 2.9.0 → 2.13.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of bolt might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Puppetfile +2 -2
- data/bolt-modules/boltlib/lib/puppet/datatypes/applyresult.rb +2 -0
- data/bolt-modules/boltlib/lib/puppet/datatypes/resourceinstance.rb +28 -0
- data/bolt-modules/boltlib/lib/puppet/datatypes/result.rb +2 -0
- data/bolt-modules/boltlib/lib/puppet/datatypes/resultset.rb +2 -0
- data/bolt-modules/boltlib/lib/puppet/datatypes/target.rb +4 -3
- data/bolt-modules/boltlib/lib/puppet/functions/apply_prep.rb +1 -1
- data/bolt-modules/boltlib/lib/puppet/functions/get_resources.rb +1 -1
- data/bolt-modules/boltlib/lib/puppet/functions/run_plan.rb +61 -0
- data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +4 -2
- data/bolt-modules/boltlib/lib/puppet/functions/run_task_with.rb +8 -2
- data/bolt-modules/boltlib/lib/puppet/functions/set_resources.rb +144 -0
- data/bolt-modules/boltlib/types/planresult.pp +1 -0
- data/bolt-modules/file/lib/puppet/functions/file/exists.rb +3 -1
- data/bolt-modules/file/lib/puppet/functions/file/join.rb +1 -1
- data/bolt-modules/file/lib/puppet/functions/file/read.rb +2 -1
- data/bolt-modules/file/lib/puppet/functions/file/readable.rb +3 -1
- data/bolt-modules/file/lib/puppet/functions/file/write.rb +3 -1
- data/lib/bolt/analytics.rb +21 -2
- data/lib/bolt/applicator.rb +7 -2
- data/lib/bolt/apply_result.rb +1 -1
- data/lib/bolt/apply_target.rb +3 -2
- data/lib/bolt/bolt_option_parser.rb +18 -8
- data/lib/bolt/catalog.rb +4 -1
- data/lib/bolt/cli.rb +15 -5
- data/lib/bolt/config.rb +44 -16
- data/lib/bolt/config/transport/ssh.rb +47 -1
- data/lib/bolt/inventory.rb +2 -1
- data/lib/bolt/inventory/inventory.rb +5 -0
- data/lib/bolt/inventory/target.rb +17 -1
- data/lib/bolt/node/output.rb +1 -1
- data/lib/bolt/pal.rb +3 -0
- data/lib/bolt/pal/yaml_plan.rb +1 -0
- data/lib/bolt/plugin.rb +13 -7
- data/lib/bolt/plugin/puppetdb.rb +5 -2
- data/lib/bolt/project.rb +25 -7
- data/lib/bolt/puppetdb/config.rb +14 -26
- data/lib/bolt/resource_instance.rb +129 -0
- data/lib/bolt/shell/bash.rb +1 -1
- data/lib/bolt/target.rb +12 -1
- data/lib/bolt/transport/ssh.rb +6 -2
- data/lib/bolt/transport/ssh/connection.rb +4 -0
- data/lib/bolt/transport/ssh/exec_connection.rb +110 -0
- data/lib/bolt/transport/winrm/connection.rb +4 -0
- data/lib/bolt/version.rb +1 -1
- data/lib/bolt_server/pe/pal.rb +1 -38
- data/lib/bolt_spec/bolt_context.rb +1 -4
- data/lib/bolt_spec/plans/mock_executor.rb +1 -0
- data/lib/bolt_spec/run.rb +2 -5
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fd39267ed3b68619b0e9f40f8415446d0061ebe5367650d50e6e5ab3229d8b9
|
4
|
+
data.tar.gz: b4d88aee228eeccb8c9ed8ebcb6221960c3197f1ac43d4a195e5c3d4a8833a9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a225b8e5e695da5268aa9b748c57c06944046ebc4865d76ec8d0f446ec37d0584f2fca2d19ee9910cd5ed5555f8cc15910693a66e813b0b0e6aab48dd9e8789
|
7
|
+
data.tar.gz: 6d2853adea34d7b0006ac0d643f1af8cda862903618fde138cf64079d9b9c433815537c7f70c483fcbb00287462f4762285d5e8e5147b6327c7c5c71346412b4
|
data/Puppetfile
CHANGED
@@ -6,7 +6,7 @@ moduledir File.join(File.dirname(__FILE__), 'modules')
|
|
6
6
|
|
7
7
|
# Core modules used by 'apply'
|
8
8
|
mod 'puppetlabs-service', '1.2.0'
|
9
|
-
mod 'puppetlabs-puppet_agent', '3.0
|
9
|
+
mod 'puppetlabs-puppet_agent', '3.2.0'
|
10
10
|
mod 'puppetlabs-facts', '1.0.0'
|
11
11
|
|
12
12
|
# Core types and providers for Puppet 6
|
@@ -24,7 +24,7 @@ mod 'puppetlabs-zone_core', '1.0.3'
|
|
24
24
|
# Useful additional modules
|
25
25
|
mod 'puppetlabs-package', '1.1.0'
|
26
26
|
mod 'puppetlabs-puppet_conf', '0.6.0'
|
27
|
-
mod 'puppetlabs-python_task_helper', '0.4.
|
27
|
+
mod 'puppetlabs-python_task_helper', '0.4.3'
|
28
28
|
mod 'puppetlabs-reboot', '3.0.0'
|
29
29
|
mod 'puppetlabs-ruby_task_helper', '0.5.1'
|
30
30
|
mod 'puppetlabs-ruby_plugin_helper', '0.1.0'
|
@@ -17,5 +17,7 @@ Puppet::DataTypes.create_type('ApplyResult') do
|
|
17
17
|
|
18
18
|
load_file('bolt/apply_result')
|
19
19
|
|
20
|
+
# Needed for Puppet to recognize Bolt::ApplyResult as a Puppet object when deserializing
|
21
|
+
Bolt::ApplyResult.include(Puppet::Pops::Types::PuppetObject)
|
20
22
|
implementation_class Bolt::ApplyResult
|
21
23
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Puppet::DataTypes.create_type('ResourceInstance') do
|
4
|
+
interface <<-PUPPET
|
5
|
+
attributes => {
|
6
|
+
'target' => Target,
|
7
|
+
'type' => Variant[String[1], Type[Resource]],
|
8
|
+
'title' => String[1],
|
9
|
+
'state' => Optional[Hash[String[1], Data]],
|
10
|
+
'desired_state' => Optional[Hash[String[1], Data]],
|
11
|
+
'events' => Optional[Array[Hash[String[1], Data]]]
|
12
|
+
},
|
13
|
+
functions => {
|
14
|
+
add_event => Callable[[Hash[String[1], Data]], Array[Hash[String[1], Data]]],
|
15
|
+
set_state => Callable[[Hash[String[1], Data]], Hash[String[1], Data]],
|
16
|
+
overwrite_state => Callable[[Hash[String[1], Data]], Hash[String[1], Data]],
|
17
|
+
set_desired_state => Callable[[Hash[String[1], Data]], Hash[String[1], Data]],
|
18
|
+
overwrite_desired_state => Callable[[Hash[String[1], Data]], Hash[String[1], Data]],
|
19
|
+
reference => Callable[[], String],
|
20
|
+
'[]' => Callable[[String[1]], Data]
|
21
|
+
}
|
22
|
+
PUPPET
|
23
|
+
|
24
|
+
load_file('bolt/resource_instance')
|
25
|
+
# Needed for Puppet to recognize Bolt::ResourceInstance as a Puppet object when deserializing
|
26
|
+
Bolt::ResourceInstance.include(Puppet::Pops::Types::PuppetObject)
|
27
|
+
implementation_class Bolt::ResourceInstance
|
28
|
+
end
|
@@ -19,5 +19,7 @@ Puppet::DataTypes.create_type('Result') do
|
|
19
19
|
|
20
20
|
load_file('bolt/result')
|
21
21
|
|
22
|
+
# Needed for Puppet to recognize Bolt::Result as a Puppet object when deserializing
|
23
|
+
Bolt::Result.include(Puppet::Pops::Types::PuppetObject)
|
22
24
|
implementation_class Bolt::Result
|
23
25
|
end
|
@@ -25,5 +25,7 @@ Puppet::DataTypes.create_type('ResultSet') do
|
|
25
25
|
|
26
26
|
load_file('bolt/result_set')
|
27
27
|
|
28
|
+
# Needed for Puppet to recognize Bolt::ResultSet as a Puppet object when deserializing
|
29
|
+
Bolt::ResultSet.include(Puppet::Pops::Types::PuppetObject)
|
28
30
|
implementation_class Bolt::ResultSet
|
29
31
|
end
|
@@ -8,8 +8,6 @@ Puppet::DataTypes.create_type('Target') do
|
|
8
8
|
target_implementation_class = Bolt::Target
|
9
9
|
end
|
10
10
|
|
11
|
-
require 'bolt/target'
|
12
|
-
|
13
11
|
interface <<-PUPPET
|
14
12
|
attributes => {
|
15
13
|
uri => { type => Optional[String[1]], kind => given_or_derived },
|
@@ -20,7 +18,8 @@ Puppet::DataTypes.create_type('Target') do
|
|
20
18
|
vars => { type => Optional[Hash[String[1], Data]], kind => given_or_derived },
|
21
19
|
facts => { type => Optional[Hash[String[1], Data]], kind => given_or_derived },
|
22
20
|
features => { type => Optional[Array[String[1]]], kind => given_or_derived },
|
23
|
-
plugin_hooks => { type => Optional[Hash[String[1], Data]], kind => given_or_derived }
|
21
|
+
plugin_hooks => { type => Optional[Hash[String[1], Data]], kind => given_or_derived },
|
22
|
+
resources => { type => Optional[Hash[String[1], ResourceInstance]], kind => given_or_derived }
|
24
23
|
},
|
25
24
|
functions => {
|
26
25
|
host => Callable[[], Optional[String]],
|
@@ -33,5 +32,7 @@ Puppet::DataTypes.create_type('Target') do
|
|
33
32
|
}
|
34
33
|
PUPPET
|
35
34
|
|
35
|
+
# Needed for Puppet to recognize targets as Puppet objects when deserializing
|
36
|
+
target_implementation_class.include(Puppet::Pops::Types::PuppetObject)
|
36
37
|
implementation_class target_implementation_class
|
37
38
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'bolt/task'
|
4
4
|
|
5
5
|
# Installs the `puppet-agent` package on targets if needed, then collects facts,
|
6
|
-
# including any custom facts found in Bolt's
|
6
|
+
# including any custom facts found in Bolt's module path. The package is
|
7
7
|
# installed using either the configured plugin or the `task` plugin with the
|
8
8
|
# `puppet_agent::install` task.
|
9
9
|
#
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'bolt/task'
|
4
4
|
|
5
|
-
# Query the state of resources on a list of targets using resource definitions in Bolt's
|
5
|
+
# Query the state of resources on a list of targets using resource definitions in Bolt's module path.
|
6
6
|
# The results are returned as a list of hashes representing each resource.
|
7
7
|
#
|
8
8
|
# Requires the Puppet Agent be installed on the target, which can be accomplished with apply_prep
|
@@ -109,6 +109,15 @@ Puppet::Functions.create_function(:run_plan, Puppet::Functions::InternalFunction
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
+
# Wrap Sensitive parameters for plans that are run from the CLI, as it's impossible to pass
|
113
|
+
# a Sensitive value that way. We don't do this for plans run from the run_plan function, as
|
114
|
+
# it can receive Sensitive values as arguments.
|
115
|
+
# This should only happen after expanding target params, otherwise things will blow up if
|
116
|
+
# the targets are wrapped as Sensitive. Hopefully nobody does that, though...
|
117
|
+
if options[:bolt_api_call]
|
118
|
+
params = wrap_sensitive_parameters(params, closure.parameters)
|
119
|
+
end
|
120
|
+
|
112
121
|
# wrap plan execution in logging messages
|
113
122
|
executor.log_plan(plan_name) do
|
114
123
|
result = nil
|
@@ -169,6 +178,58 @@ Puppet::Functions.create_function(:run_plan, Puppet::Functions::InternalFunction
|
|
169
178
|
end
|
170
179
|
end
|
171
180
|
|
181
|
+
# Wrap any Sensitive parameters in the Sensitive wrapper type, unless they are already
|
182
|
+
# wrapped as Sensitive. This will also raise a helpful warning if the type expression
|
183
|
+
# is a complex data type using Sensitive, as we don't handle those cases.
|
184
|
+
def wrap_sensitive_parameters(params, param_models)
|
185
|
+
models = param_models.each_with_object({}) { |param, acc| acc[param.name] = param }
|
186
|
+
|
187
|
+
params.each_with_object({}) do |(name, value), acc|
|
188
|
+
model = models[name]
|
189
|
+
|
190
|
+
if sensitive_type?(model.type_expr)
|
191
|
+
acc[name] = Puppet::Pops::Types::PSensitiveType::Sensitive.new(value)
|
192
|
+
else
|
193
|
+
if model.type_expr.to_s.include?('Sensitive')
|
194
|
+
# Include the location for regular plans. YAML plans don't have this info, so
|
195
|
+
# the location will be suppressed.
|
196
|
+
file = defined?(model.file) ? model.file : :default
|
197
|
+
line = defined?(model.line) ? model.line : :default
|
198
|
+
|
199
|
+
Puppet.warn_once(
|
200
|
+
'unsupported_sensitive_type',
|
201
|
+
name,
|
202
|
+
"Parameter '#{name}' is a complex type using Sensitive, unable to automatically wrap as Sensitive",
|
203
|
+
file,
|
204
|
+
line
|
205
|
+
)
|
206
|
+
end
|
207
|
+
|
208
|
+
acc[name] = value
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
# Whether the type is a supported Sensitive type. We only support wrapping parameterized
|
214
|
+
# and non-parameterized Sensitive types (e.g. Sensitive, Sensitive[String])
|
215
|
+
def sensitive_type?(type_expr)
|
216
|
+
# Parameterized Sensitive type (e.g. Sensitive[String])
|
217
|
+
# left_expr is defined whenever the type is parameterized. If this is a parameterized
|
218
|
+
# Sensitive type, then we check the cased_value, which is the stringified version of
|
219
|
+
# the left expression's type.
|
220
|
+
(defined?(type_expr.left_expr) && type_expr.left_expr.cased_value == 'Sensitive') ||
|
221
|
+
# Non-parameterized Sensitive type (Sensitive)
|
222
|
+
# cased_value is defined whenever the type is non-parameterized. If the type expression
|
223
|
+
# defines cased_value, then this is a simple type and we just need to check that it's
|
224
|
+
# Sensitive.
|
225
|
+
(defined?(type_expr.cased_value) && type_expr.cased_value == 'Sensitive') ||
|
226
|
+
# Sensitive type from YAML plans
|
227
|
+
# Type expressions from YAML plans are a different class than those from regular plans.
|
228
|
+
# As long as the type expression is PSensitiveType we can be sure that the type is
|
229
|
+
# either a parameterized or non-parameterized Sensitive type.
|
230
|
+
type_expr.instance_of?(Puppet::Pops::Types::PSensitiveType)
|
231
|
+
end
|
232
|
+
|
172
233
|
def targets_to_param(targets, params, param_types)
|
173
234
|
nodes_param = param_types.include?('nodes')
|
174
235
|
targets_param = param_types['targets']&.any? { |p| p.match?(/TargetSpec/) }
|
@@ -88,8 +88,10 @@ Puppet::Functions.create_function(:run_task) do
|
|
88
88
|
|
89
89
|
task = Bolt::Task.from_task_signature(task_signature)
|
90
90
|
|
91
|
-
# Set the default value for any params that have one and were not provided
|
92
|
-
params = task.parameter_defaults.merge(params)
|
91
|
+
# Set the default value for any params that have one and were not provided or are undef
|
92
|
+
params = task.parameter_defaults.merge(params) do |_, default, passed|
|
93
|
+
passed.nil? ? default : passed
|
94
|
+
end
|
93
95
|
|
94
96
|
task_signature.runnable_with?(params) do |mismatch_message|
|
95
97
|
raise with_stack(:TYPE_MISMATCH, mismatch_message)
|
@@ -124,7 +124,10 @@ Puppet::Functions.create_function(:run_task_with) do
|
|
124
124
|
# If parameters are mismatched, create a failing result for the target that will later
|
125
125
|
# be added to the ResultSet.
|
126
126
|
unless pcp_only
|
127
|
-
params
|
127
|
+
# Set the default value for any params that have one and were not provided or are undef
|
128
|
+
params = task.parameter_defaults.merge(params) do |_, default, passed|
|
129
|
+
passed.nil? ? default : passed
|
130
|
+
end
|
128
131
|
|
129
132
|
type_match = task_signature.runnable_with?(params) do |mismatch_message|
|
130
133
|
exception = with_stack(:TYPE_MISMATCH, mismatch_message)
|
@@ -157,7 +160,10 @@ Puppet::Functions.create_function(:run_task_with) do
|
|
157
160
|
end
|
158
161
|
end
|
159
162
|
|
160
|
-
|
163
|
+
# Set the default value for any params that have one and were not provided or are undef
|
164
|
+
mapping[target] = task.parameter_defaults.merge(params) do |_, default, passed|
|
165
|
+
passed.nil? ? default : passed
|
166
|
+
end
|
161
167
|
end
|
162
168
|
|
163
169
|
# Add a noop parameter if the function was called with the noop metaparameter.
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bolt/error'
|
4
|
+
|
5
|
+
# Sets one or more ResourceInstances on a Target. This function does not apply or modify
|
6
|
+
# resources on a target.
|
7
|
+
#
|
8
|
+
# For more information about resources see [the
|
9
|
+
# documentation](https://puppet.com/docs/puppet/latest/lang_resources.html).
|
10
|
+
#
|
11
|
+
# > **Note:** The `ResourceInstance` data type is under active development and is subject to
|
12
|
+
# change. You can read more about the data type in the [experimental features
|
13
|
+
# documentation](experimental_features.md#resourceinstance-data-type).
|
14
|
+
#
|
15
|
+
# > **Note:** Not available in apply block
|
16
|
+
Puppet::Functions.create_function(:set_resources) do
|
17
|
+
# Set a single resource from a data hash.
|
18
|
+
# @param target The `Target` object to add a resource to. See {get_targets}.
|
19
|
+
# @param resource The resource data hash used to set a resource on the target.
|
20
|
+
# @return An array with the added `ResourceInstance` object.
|
21
|
+
# @example Add a resource to a target from a data hash.
|
22
|
+
# $resource_hash = {
|
23
|
+
# 'type' => File,
|
24
|
+
# 'title' => '/etc/puppetlabs',
|
25
|
+
# 'state' => { 'ensure' => 'present' }
|
26
|
+
# }
|
27
|
+
#
|
28
|
+
# $target.set_resources($resource_hash)
|
29
|
+
dispatch :set_single_resource_from_hash do
|
30
|
+
param 'Target', :target
|
31
|
+
param 'Hash', :resource
|
32
|
+
return_type 'Array[ResourceInstance]'
|
33
|
+
end
|
34
|
+
|
35
|
+
# Set a single resource from a `ResourceInstance` object
|
36
|
+
# @param target The `Target` object to add a resource to. See {get_targets}.
|
37
|
+
# @param resource The `ResourceInstance` object to set on the target.
|
38
|
+
# @return An array with the added `ResourceInstance` object.
|
39
|
+
# @example Add a resource to a target from a `ResourceInstance` object.
|
40
|
+
# $resource_instance = ResourceInstance.new(
|
41
|
+
# 'target' => $target,
|
42
|
+
# 'type' => File,
|
43
|
+
# 'title' => '/etc/puppetlabs',
|
44
|
+
# 'state' => { 'ensure' => 'present' }
|
45
|
+
# )
|
46
|
+
#
|
47
|
+
# $target.set_resources($resource_instance)
|
48
|
+
dispatch :set_single_resource_from_object do
|
49
|
+
param 'Target', :target
|
50
|
+
param 'ResourceInstance', :resource
|
51
|
+
return_type 'Array[ResourceInstance]'
|
52
|
+
end
|
53
|
+
|
54
|
+
# Set multiple resources from an array of data hashes and `ResourceInstance` objects.
|
55
|
+
# @param target The `Target` object to add resources to. See {get_targets}.
|
56
|
+
# @param resources The resource data hashes and `ResourceInstance` objects to set on the target.
|
57
|
+
# @return An array of the added `ResourceInstance` objects.
|
58
|
+
# @example Add resources from resource data hashes returned from an apply block.
|
59
|
+
# $apply_results = apply($targets) {
|
60
|
+
# File { '/etc/puppetlabs':
|
61
|
+
# ensure => present
|
62
|
+
# }
|
63
|
+
# Package { 'openssl':
|
64
|
+
# ensure => installed
|
65
|
+
# }
|
66
|
+
# }
|
67
|
+
#
|
68
|
+
# $apply_results.each |$result| {
|
69
|
+
# $result.target.set_resources($result.report['resource_statuses'].values)
|
70
|
+
# }
|
71
|
+
# @example Add resources retrieved with [`get_resources`](#get_resources) to a target.
|
72
|
+
# $resources = $target.get_resources(Package).first['resources']
|
73
|
+
# $target.set_resources($resources)
|
74
|
+
dispatch :set_resources do
|
75
|
+
param 'Target', :target
|
76
|
+
param 'Array[Variant[Hash, ResourceInstance]]', :resources
|
77
|
+
return_type 'Array[ResourceInstance]'
|
78
|
+
end
|
79
|
+
|
80
|
+
def set_single_resource_from_hash(target, resource)
|
81
|
+
set_resources(target, [resource])
|
82
|
+
end
|
83
|
+
|
84
|
+
def set_single_resource_from_object(target, resource)
|
85
|
+
set_resources(target, [resource])
|
86
|
+
end
|
87
|
+
|
88
|
+
def set_resources(target, resources)
|
89
|
+
unless Puppet[:tasks]
|
90
|
+
raise Puppet::ParseErrorWithIssue
|
91
|
+
.from_issue_and_stack(
|
92
|
+
Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING,
|
93
|
+
action: 'set_resources'
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
Puppet.lookup(:bolt_executor).report_function_call(self.class.name)
|
98
|
+
inventory = Puppet.lookup(:bolt_inventory)
|
99
|
+
|
100
|
+
resources.uniq.map do |resource|
|
101
|
+
if resource.is_a?(Hash)
|
102
|
+
# ResourceInstance expects a Target object, so either get a specified target from
|
103
|
+
# the inventory or use the target this function was called on.
|
104
|
+
resource_target = if resource.key?('target')
|
105
|
+
inventory.get_target(resource['target'])
|
106
|
+
else
|
107
|
+
target
|
108
|
+
end
|
109
|
+
|
110
|
+
# Observed state from get_resources() is under the 'parameters' key
|
111
|
+
resource_state = resource['state'] || resource['parameters']
|
112
|
+
|
113
|
+
# Type from apply results is under the 'resource_type' key
|
114
|
+
resource_type = resource['type'] || resource['resource_type']
|
115
|
+
|
116
|
+
init_hash = {
|
117
|
+
'target' => resource_target,
|
118
|
+
'type' => resource_type,
|
119
|
+
'title' => resource['title'],
|
120
|
+
'state' => resource_state,
|
121
|
+
'desired_state' => resource['desired_state'],
|
122
|
+
'events' => resource['events']
|
123
|
+
}
|
124
|
+
|
125
|
+
# Calling Bolt::ResourceInstance.new or Bolt::ResourceInstance.from_asserted_hash
|
126
|
+
# will not perform any validation on the parameters. Instead, we need to use the
|
127
|
+
# Puppet constructor to initialize the object, which will first validate the parameters
|
128
|
+
# and then call Bolt::ResourceInstance.from_asserted_hash internally. To do this we
|
129
|
+
# first need to get the Puppet datatype and then call the new function on that type.
|
130
|
+
type = Puppet::Pops::Types::TypeParser.singleton.parse('ResourceInstance')
|
131
|
+
resource = call_function('new', type, init_hash)
|
132
|
+
end
|
133
|
+
|
134
|
+
unless resource.target == target
|
135
|
+
file, line = Puppet::Pops::PuppetStack.top_of_stack
|
136
|
+
raise Bolt::ValidationError, "Cannot set resource #{resource.reference} for target "\
|
137
|
+
"#{resource.target} on target #{target}. "\
|
138
|
+
"#{Puppet::Util::Errors.error_location(file, line)}"
|
139
|
+
end
|
140
|
+
|
141
|
+
target.set_resource(resource)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Check if a file exists
|
3
|
+
# Check if a local file exists using Puppet's
|
4
|
+
# `Puppet::Parser::Files.find_file()` function. This will only check files that
|
5
|
+
# are on the machine Bolt is run on.
|
4
6
|
Puppet::Functions.create_function(:'file::exists', Puppet::Functions::InternalFunction) do
|
5
7
|
# @param filename Absolute path or Puppet file path.
|
6
8
|
# @return Whether the file exists.
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Read a file and return its contents.
|
3
|
+
# Read a file on localhost and return its contents using ruby's `File.read`. This will
|
4
|
+
# only read files on the machine you run Bolt on.
|
4
5
|
Puppet::Functions.create_function(:'file::read', Puppet::Functions::InternalFunction) do
|
5
6
|
# @param filename Absolute path or Puppet file path.
|
6
7
|
# @return The file's contents.
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Check if a file is readable
|
3
|
+
# Check if a local file is readable using Puppet's
|
4
|
+
# `Puppet::Parser::Files.find_file()` function. This will only check files on the
|
5
|
+
# machine you run Bolt on.
|
4
6
|
Puppet::Functions.create_function(:'file::readable', Puppet::Functions::InternalFunction) do
|
5
7
|
# @param filename Absolute path or Puppet file path.
|
6
8
|
# @return Whether the file is readable.
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Write a string to a file.
|
3
|
+
# Write a string to a file on localhost using ruby's `File.write`. This will
|
4
|
+
# only write files to the machine you run Bolt on. Use `write_file()` to write
|
5
|
+
# to remote targets.
|
4
6
|
Puppet::Functions.create_function(:'file::write') do
|
5
7
|
# @param filename Absolute path.
|
6
8
|
# @param content File content to write.
|