bolt 2.12.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/bolt-modules/boltlib/lib/puppet/datatypes/resourceinstance.rb +3 -2
- 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_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 +65 -43
- data/lib/bolt/applicator.rb +4 -1
- data/lib/bolt/catalog.rb +4 -1
- data/lib/bolt/config.rb +1 -3
- data/lib/bolt/pal.rb +1 -0
- data/lib/bolt/resource_instance.rb +5 -2
- data/lib/bolt/version.rb +1 -1
- metadata +2 -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
|
@@ -11,12 +11,13 @@ Puppet::DataTypes.create_type('ResourceInstance') do
|
|
11
11
|
'events' => Optional[Array[Hash[String[1], Data]]]
|
12
12
|
},
|
13
13
|
functions => {
|
14
|
-
add_event => Callable[[Hash[String[1], Data]], [Hash[String[1], Data]]],
|
14
|
+
add_event => Callable[[Hash[String[1], Data]], Array[Hash[String[1], Data]]],
|
15
15
|
set_state => Callable[[Hash[String[1], Data]], Hash[String[1], Data]],
|
16
16
|
overwrite_state => Callable[[Hash[String[1], Data]], Hash[String[1], Data]],
|
17
17
|
set_desired_state => Callable[[Hash[String[1], Data]], Hash[String[1], Data]],
|
18
18
|
overwrite_desired_state => Callable[[Hash[String[1], Data]], Hash[String[1], Data]],
|
19
|
-
reference => Callable[[], String]
|
19
|
+
reference => Callable[[], String],
|
20
|
+
'[]' => Callable[[String[1]], Data]
|
20
21
|
}
|
21
22
|
PUPPET
|
22
23
|
|
@@ -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
|
@@ -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.
|
@@ -14,26 +14,61 @@ require 'bolt/error'
|
|
14
14
|
#
|
15
15
|
# > **Note:** Not available in apply block
|
16
16
|
Puppet::Functions.create_function(:set_resources) do
|
17
|
-
# Set
|
18
|
-
# @param target The `Target` object to add
|
19
|
-
# @param
|
20
|
-
# @return
|
21
|
-
# @example Add
|
22
|
-
# $
|
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(
|
23
41
|
# 'target' => $target,
|
24
|
-
# 'type' =>
|
42
|
+
# 'type' => File,
|
25
43
|
# 'title' => '/etc/puppetlabs',
|
26
44
|
# 'state' => { 'ensure' => 'present' }
|
27
45
|
# )
|
28
|
-
#
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
+
# }
|
35
71
|
# @example Add resources retrieved with [`get_resources`](#get_resources) to a target.
|
36
|
-
# $target.apply_prep
|
37
72
|
# $resources = $target.get_resources(Package).first['resources']
|
38
73
|
# $target.set_resources($resources)
|
39
74
|
dispatch :set_resources do
|
@@ -42,21 +77,12 @@ Puppet::Functions.create_function(:set_resources) do
|
|
42
77
|
return_type 'Array[ResourceInstance]'
|
43
78
|
end
|
44
79
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
# 'type' => 'file',
|
52
|
-
# 'title' => '/etc/puppetlabs',
|
53
|
-
# 'state' => { 'ensure' => 'present' }
|
54
|
-
# }
|
55
|
-
# $target.set_resources($resource)
|
56
|
-
dispatch :set_resource do
|
57
|
-
param 'Target', :target
|
58
|
-
param 'Variant[Hash, ResourceInstance]', :resource
|
59
|
-
return_type 'Array[ResourceInstance]'
|
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])
|
60
86
|
end
|
61
87
|
|
62
88
|
def set_resources(target, resources)
|
@@ -68,11 +94,8 @@ Puppet::Functions.create_function(:set_resources) do
|
|
68
94
|
)
|
69
95
|
end
|
70
96
|
|
97
|
+
Puppet.lookup(:bolt_executor).report_function_call(self.class.name)
|
71
98
|
inventory = Puppet.lookup(:bolt_inventory)
|
72
|
-
executor = Puppet.lookup(:bolt_executor)
|
73
|
-
executor.report_function_call(self.class.name)
|
74
|
-
|
75
|
-
inventory_target = inventory.get_target(target)
|
76
99
|
|
77
100
|
resources.uniq.map do |resource|
|
78
101
|
if resource.is_a?(Hash)
|
@@ -81,15 +104,18 @@ Puppet::Functions.create_function(:set_resources) do
|
|
81
104
|
resource_target = if resource.key?('target')
|
82
105
|
inventory.get_target(resource['target'])
|
83
106
|
else
|
84
|
-
|
107
|
+
target
|
85
108
|
end
|
86
109
|
|
87
110
|
# Observed state from get_resources() is under the 'parameters' key
|
88
111
|
resource_state = resource['state'] || resource['parameters']
|
89
112
|
|
113
|
+
# Type from apply results is under the 'resource_type' key
|
114
|
+
resource_type = resource['type'] || resource['resource_type']
|
115
|
+
|
90
116
|
init_hash = {
|
91
117
|
'target' => resource_target,
|
92
|
-
'type' =>
|
118
|
+
'type' => resource_type,
|
93
119
|
'title' => resource['title'],
|
94
120
|
'state' => resource_state,
|
95
121
|
'desired_state' => resource['desired_state'],
|
@@ -105,18 +131,14 @@ Puppet::Functions.create_function(:set_resources) do
|
|
105
131
|
resource = call_function('new', type, init_hash)
|
106
132
|
end
|
107
133
|
|
108
|
-
unless resource.target ==
|
134
|
+
unless resource.target == target
|
109
135
|
file, line = Puppet::Pops::PuppetStack.top_of_stack
|
110
136
|
raise Bolt::ValidationError, "Cannot set resource #{resource.reference} for target "\
|
111
|
-
"#{resource.target} on target #{
|
137
|
+
"#{resource.target} on target #{target}. "\
|
112
138
|
"#{Puppet::Util::Errors.error_location(file, line)}"
|
113
139
|
end
|
114
140
|
|
115
|
-
|
141
|
+
target.set_resource(resource)
|
116
142
|
end
|
117
143
|
end
|
118
|
-
|
119
|
-
def set_resource(target, resource)
|
120
|
-
set_resources(target, [resource])
|
121
|
-
end
|
122
144
|
end
|
data/lib/bolt/applicator.rb
CHANGED
@@ -14,7 +14,8 @@ require 'open3'
|
|
14
14
|
|
15
15
|
module Bolt
|
16
16
|
class Applicator
|
17
|
-
def initialize(inventory, executor, modulepath, plugin_dirs,
|
17
|
+
def initialize(inventory, executor, modulepath, plugin_dirs, project,
|
18
|
+
pdb_client, hiera_config, max_compiles, apply_settings)
|
18
19
|
# lazy-load expensive gem code
|
19
20
|
require 'concurrent'
|
20
21
|
|
@@ -22,6 +23,7 @@ module Bolt
|
|
22
23
|
@executor = executor
|
23
24
|
@modulepath = modulepath
|
24
25
|
@plugin_dirs = plugin_dirs
|
26
|
+
@project = project
|
25
27
|
@pdb_client = pdb_client
|
26
28
|
@hiera_config = hiera_config ? validate_hiera_config(hiera_config) : nil
|
27
29
|
@apply_settings = apply_settings || {}
|
@@ -188,6 +190,7 @@ module Bolt
|
|
188
190
|
scope = {
|
189
191
|
code_ast: ast,
|
190
192
|
modulepath: @modulepath,
|
193
|
+
project: @project.to_h,
|
191
194
|
pdb_config: @pdb_client.config.to_hash,
|
192
195
|
hiera_config: @hiera_config,
|
193
196
|
plan_vars: plan_vars,
|
data/lib/bolt/catalog.rb
CHANGED
@@ -58,6 +58,8 @@ module Bolt
|
|
58
58
|
target = request['target']
|
59
59
|
pdb_client = Bolt::PuppetDB::Client.new(Bolt::PuppetDB::Config.new(request['pdb_config']))
|
60
60
|
options = request['puppet_config'] || {}
|
61
|
+
project = request['project'] || {}
|
62
|
+
bolt_project = Struct.new(:name, :path).new(project['name'], project['path']) unless project.empty?
|
61
63
|
with_puppet_settings(request['hiera_config']) do
|
62
64
|
Puppet[:rich_data] = true
|
63
65
|
Puppet[:node_name_value] = target['name']
|
@@ -67,7 +69,8 @@ module Bolt
|
|
67
69
|
Puppet::Pal.in_tmp_environment('bolt_catalog', env_conf) do |pal|
|
68
70
|
inv = Bolt::ApplyInventory.new(request['config'])
|
69
71
|
Puppet.override(bolt_pdb_client: pdb_client,
|
70
|
-
bolt_inventory: inv
|
72
|
+
bolt_inventory: inv,
|
73
|
+
bolt_project: bolt_project) do
|
71
74
|
Puppet.lookup(:pal_current_node).trusted_data = target['trusted']
|
72
75
|
pal.with_catalog_compiler do |compiler|
|
73
76
|
# Deserializing needs to happen inside the catalog compiler so
|
data/lib/bolt/config.rb
CHANGED
@@ -47,9 +47,7 @@ module Bolt
|
|
47
47
|
"targets on the command line and from plans.",
|
48
48
|
"log" => "The configuration of the logfile output. Configuration can be set for "\
|
49
49
|
"`console` and the path to a log file, such as `~/.puppetlabs/bolt/debug.log`.",
|
50
|
-
"modulepath" => "
|
51
|
-
"of directories or a string containing a list of directories separated by the "\
|
52
|
-
"OS-specific PATH separator.",
|
50
|
+
"modulepath" => "An array of directories that Bolt loads content (e.g. plans and tasks) from.",
|
53
51
|
"plugin_hooks" => "Which plugins a specific hook should use.",
|
54
52
|
"plugins" => "A map of plugins and their configuration data.",
|
55
53
|
"puppetdb" => "A map containing options for configuring the Bolt PuppetDB client.",
|
data/lib/bolt/pal.rb
CHANGED
@@ -30,8 +30,7 @@ module Bolt
|
|
30
30
|
@target = resource_hash['target']
|
31
31
|
@type = resource_hash['type'].to_s.capitalize
|
32
32
|
@title = resource_hash['title']
|
33
|
-
|
34
|
-
@state = resource_hash['state'] || resource_hash['parameters'] || {}
|
33
|
+
@state = resource_hash['state'] || {}
|
35
34
|
@desired_state = resource_hash['desired_state'] || {}
|
36
35
|
@events = resource_hash['events'] || []
|
37
36
|
end
|
@@ -89,6 +88,10 @@ module Bolt
|
|
89
88
|
end
|
90
89
|
alias to_s reference
|
91
90
|
|
91
|
+
def [](attribute)
|
92
|
+
@state[attribute]
|
93
|
+
end
|
94
|
+
|
92
95
|
def add_event(event)
|
93
96
|
@events << event
|
94
97
|
end
|
data/lib/bolt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bolt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|