bolt 0.23.0 → 0.24.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/functions/apply_prep.rb +5 -2
- data/bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb +5 -1
- data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +5 -8
- data/lib/bolt/applicator.rb +11 -8
- data/lib/bolt/boltdir.rb +13 -5
- data/lib/bolt/catalog.rb +22 -47
- data/lib/bolt/config.rb +1 -26
- data/lib/bolt/executor.rb +1 -1
- data/lib/bolt/outputter.rb +0 -9
- data/lib/bolt/outputter/human.rb +29 -14
- data/lib/bolt/outputter/json.rb +12 -1
- data/lib/bolt/pal.rb +12 -10
- data/lib/bolt/target.rb +0 -6
- data/lib/bolt/task.rb +53 -10
- data/lib/bolt/transport/base.rb +1 -6
- data/lib/bolt/transport/local.rb +11 -13
- data/lib/bolt/transport/local/shell.rb +2 -2
- data/lib/bolt/transport/ssh.rb +16 -11
- data/lib/bolt/transport/winrm.rb +8 -11
- data/lib/bolt/version.rb +1 -1
- data/lib/bolt_ext/schemas/task.json +12 -5
- data/libexec/apply_catalog.rb +3 -1
- data/libexec/bolt_catalog +4 -0
- data/vendored/puppet/lib/puppet.rb +2 -1
- data/vendored/puppet/lib/puppet/application/agent.rb +2 -6
- data/vendored/puppet/lib/puppet/application/apply.rb +100 -60
- data/vendored/puppet/lib/puppet/application/cert.rb +26 -291
- data/vendored/puppet/lib/puppet/application/device.rb +0 -5
- data/vendored/puppet/lib/puppet/application/lookup.rb +1 -1
- data/vendored/puppet/lib/puppet/application/ssl.rb +133 -0
- data/vendored/puppet/lib/puppet/application_support.rb +1 -2
- data/vendored/puppet/lib/puppet/configurer.rb +34 -50
- data/vendored/puppet/lib/puppet/configurer/downloader.rb +1 -1
- data/vendored/puppet/lib/puppet/configurer/plugin_handler.rb +1 -1
- data/vendored/puppet/lib/puppet/daemon.rb +1 -1
- data/vendored/puppet/lib/puppet/defaults.rb +40 -117
- data/vendored/puppet/lib/puppet/face/epp.rb +2 -2
- data/vendored/puppet/lib/puppet/face/help.rb +21 -7
- data/vendored/puppet/lib/puppet/face/node/clean.rb +14 -10
- data/vendored/puppet/lib/puppet/feature/base.rb +7 -23
- data/vendored/puppet/lib/puppet/feature/eventlog.rb +1 -1
- data/vendored/puppet/lib/puppet/file_serving/base.rb +2 -2
- data/vendored/puppet/lib/puppet/file_serving/fileset.rb +1 -1
- data/vendored/puppet/lib/puppet/file_serving/metadata.rb +2 -2
- data/vendored/puppet/lib/puppet/functions.rb +133 -0
- data/vendored/puppet/lib/puppet/functions/eyaml_lookup_key.rb +4 -5
- data/vendored/puppet/lib/puppet/functions/filter.rb +7 -6
- data/vendored/puppet/lib/puppet/functions/new.rb +37 -53
- data/vendored/puppet/lib/puppet/functions/warning.rb +1 -1
- data/vendored/puppet/lib/puppet/functions/yaml_data.rb +4 -5
- data/vendored/puppet/lib/puppet/gettext/config.rb +1 -1
- data/vendored/puppet/lib/puppet/graph.rb +0 -2
- data/vendored/puppet/lib/puppet/indirector/catalog/json.rb +14 -3
- data/vendored/puppet/lib/puppet/indirector/catalog/yaml.rb +0 -16
- data/vendored/puppet/lib/puppet/indirector/certificate/file.rb +0 -1
- data/vendored/puppet/lib/puppet/indirector/facts/yaml.rb +4 -2
- data/vendored/puppet/lib/puppet/indirector/key/file.rb +1 -6
- data/vendored/puppet/lib/puppet/indirector/node/exec.rb +1 -3
- data/vendored/puppet/lib/puppet/indirector/node/yaml.rb +0 -6
- data/vendored/puppet/lib/puppet/indirector/request.rb +1 -1
- data/vendored/puppet/lib/puppet/indirector/ssl_file.rb +3 -44
- data/vendored/puppet/lib/puppet/indirector/yaml.rb +4 -4
- data/vendored/puppet/lib/puppet/info_service/task_information_service.rb +7 -3
- data/vendored/puppet/lib/puppet/loaders.rb +1 -0
- data/vendored/puppet/lib/puppet/module/task.rb +198 -29
- data/vendored/puppet/lib/puppet/module_tool/applications/unpacker.rb +1 -1
- data/vendored/puppet/lib/puppet/network/format_support.rb +13 -8
- data/vendored/puppet/lib/puppet/network/formats.rb +93 -2
- data/vendored/puppet/lib/puppet/network/http/api/indirected_routes.rb +10 -3
- data/vendored/puppet/lib/puppet/node/facts.rb +11 -1
- data/vendored/puppet/lib/puppet/parser/catalog_compiler.rb +56 -0
- data/vendored/puppet/lib/puppet/parser/compiler.rb +3 -1
- data/vendored/puppet/lib/puppet/parser/functions.rb +3 -1
- data/vendored/puppet/lib/puppet/parser/functions/filter.rb +1 -1
- data/vendored/puppet/lib/puppet/parser/functions/generate.rb +1 -1
- data/vendored/puppet/lib/puppet/parser/functions/sprintf.rb +12 -1
- data/vendored/puppet/lib/puppet/parser/functions/tagged.rb +1 -4
- data/vendored/puppet/lib/puppet/parser/scope.rb +1 -1
- data/vendored/puppet/lib/puppet/parser/script_compiler.rb +7 -2
- data/vendored/puppet/lib/puppet/pops/evaluator/deferred_resolver.rb +5 -3
- data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_converter.rb +23 -4
- data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_support.rb +3 -4
- data/vendored/puppet/lib/puppet/pops/functions/dispatch.rb +4 -0
- data/vendored/puppet/lib/puppet/pops/issues.rb +8 -0
- data/vendored/puppet/lib/puppet/pops/loader/loader.rb +2 -2
- data/vendored/puppet/lib/puppet/pops/loader/loader_paths.rb +3 -1
- data/vendored/puppet/lib/puppet/pops/loader/module_loaders.rb +30 -9
- data/vendored/puppet/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +62 -0
- data/vendored/puppet/lib/puppet/pops/loader/static_loader.rb +0 -1
- data/vendored/puppet/lib/puppet/pops/loader/task_instantiator.rb +13 -70
- data/vendored/puppet/lib/puppet/pops/loaders.rb +19 -29
- data/vendored/puppet/lib/puppet/pops/lookup/hiera_config.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/model/model_label_provider.rb +4 -1
- data/vendored/puppet/lib/puppet/pops/pcore.rb +10 -33
- data/vendored/puppet/lib/puppet/pops/serialization.rb +2 -0
- data/vendored/puppet/lib/puppet/pops/serialization/from_data_converter.rb +2 -1
- data/vendored/puppet/lib/puppet/pops/serialization/to_data_converter.rb +11 -3
- data/vendored/puppet/lib/puppet/pops/serialization/to_stringified_converter.rb +226 -0
- data/vendored/puppet/lib/puppet/pops/types/p_object_type.rb +3 -0
- data/vendored/puppet/lib/puppet/pops/validation/checker4_0.rb +97 -47
- data/vendored/puppet/lib/puppet/pops/validation/validator_factory_4_0.rb +7 -8
- data/vendored/puppet/lib/puppet/property/keyvalue.rb +70 -8
- data/vendored/puppet/lib/puppet/provider/aix_object.rb +483 -0
- data/vendored/puppet/lib/puppet/provider/file/windows.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/group/aix.rb +51 -112
- data/vendored/puppet/lib/puppet/provider/package/gem.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/pip.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/puppet_gem.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/rpm.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/windows/package.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/zypper.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/service/systemd.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/service/windows.rb +37 -40
- data/vendored/puppet/lib/puppet/provider/user/aix.rb +142 -254
- data/vendored/puppet/lib/puppet/resource.rb +20 -3
- data/vendored/puppet/lib/puppet/resource/catalog.rb +2 -12
- data/vendored/puppet/lib/puppet/rest/routes.rb +97 -34
- data/vendored/puppet/lib/puppet/settings.rb +1 -1
- data/vendored/puppet/lib/puppet/settings/file_setting.rb +1 -1
- data/vendored/puppet/lib/puppet/ssl/base.rb +1 -9
- data/vendored/puppet/lib/puppet/ssl/certificate_request.rb +1 -13
- data/vendored/puppet/lib/puppet/ssl/certificate_request_attributes.rb +1 -1
- data/vendored/puppet/lib/puppet/ssl/host.rb +114 -232
- data/vendored/puppet/lib/puppet/ssl/key.rb +1 -5
- data/vendored/puppet/lib/puppet/ssl/oids.rb +1 -1
- data/vendored/puppet/lib/puppet/test/test_helper.rb +0 -4
- data/vendored/puppet/lib/puppet/transaction/event.rb +3 -7
- data/vendored/puppet/lib/puppet/transaction/persistence.rb +1 -1
- data/vendored/puppet/lib/puppet/type/exec.rb +18 -16
- data/vendored/puppet/lib/puppet/type/file.rb +3 -3
- data/vendored/puppet/lib/puppet/type/file/source.rb +20 -7
- data/vendored/puppet/lib/puppet/type/group.rb +3 -5
- data/vendored/puppet/lib/puppet/type/notify.rb +1 -1
- data/vendored/puppet/lib/puppet/type/package.rb +2 -5
- data/vendored/puppet/lib/puppet/type/schedule.rb +1 -1
- data/vendored/puppet/lib/puppet/type/service.rb +3 -6
- data/vendored/puppet/lib/puppet/type/tidy.rb +1 -1
- data/vendored/puppet/lib/puppet/type/user.rb +13 -20
- data/vendored/puppet/lib/puppet/util.rb +8 -9
- data/vendored/puppet/lib/puppet/util/execution.rb +3 -3
- data/vendored/puppet/lib/puppet/util/feature.rb +61 -39
- data/vendored/puppet/lib/puppet/util/log/destinations.rb +1 -1
- data/vendored/puppet/lib/puppet/util/rdoc.rb +1 -1
- data/vendored/puppet/lib/puppet/util/run_mode.rb +1 -1
- data/vendored/puppet/lib/puppet/util/storage.rb +1 -1
- data/vendored/puppet/lib/puppet/util/suidmanager.rb +7 -5
- data/vendored/puppet/lib/puppet/util/tag_set.rb +1 -1
- data/vendored/puppet/lib/puppet/util/tagging.rb +1 -1
- data/vendored/puppet/lib/puppet/util/windows.rb +18 -2
- data/vendored/puppet/lib/puppet/util/windows/adsi.rb +154 -205
- data/vendored/puppet/lib/puppet/util/windows/service.rb +770 -0
- data/vendored/puppet/lib/puppet/util/yaml.rb +41 -5
- data/vendored/puppet/lib/puppet/version.rb +1 -1
- data/vendored/puppet/lib/puppet_pal.rb +280 -24
- metadata +8 -38
- data/lib/bolt/catalog/compiler.rb +0 -48
- data/lib/bolt/catalog/loaders.rb +0 -19
- data/vendored/puppet/lib/puppet/application/ca.rb +0 -11
- data/vendored/puppet/lib/puppet/application/certificate.rb +0 -17
- data/vendored/puppet/lib/puppet/application/certificate_request.rb +0 -7
- data/vendored/puppet/lib/puppet/application/certificate_revocation_list.rb +0 -7
- data/vendored/puppet/lib/puppet/face/ca.rb +0 -266
- data/vendored/puppet/lib/puppet/face/certificate.rb +0 -167
- data/vendored/puppet/lib/puppet/face/certificate_request.rb +0 -56
- data/vendored/puppet/lib/puppet/face/certificate_revocation_list.rb +0 -56
- data/vendored/puppet/lib/puppet/graph/random_prioritizer.rb +0 -16
- data/vendored/puppet/lib/puppet/graph/title_hash_prioritizer.rb +0 -16
- data/vendored/puppet/lib/puppet/indirector/certificate/ca.rb +0 -9
- data/vendored/puppet/lib/puppet/indirector/certificate/disabled_ca.rb +0 -22
- data/vendored/puppet/lib/puppet/indirector/certificate_request/ca.rb +0 -22
- data/vendored/puppet/lib/puppet/indirector/certificate_request/disabled_ca.rb +0 -22
- data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/ca.rb +0 -8
- data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/disabled_ca.rb +0 -22
- data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/file.rb +0 -8
- data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/rest.rb +0 -11
- data/vendored/puppet/lib/puppet/indirector/certificate_status.rb +0 -4
- data/vendored/puppet/lib/puppet/indirector/certificate_status/file.rb +0 -91
- data/vendored/puppet/lib/puppet/indirector/certificate_status/rest.rb +0 -11
- data/vendored/puppet/lib/puppet/indirector/key/ca.rb +0 -16
- data/vendored/puppet/lib/puppet/indirector/key/disabled_ca.rb +0 -22
- data/vendored/puppet/lib/puppet/indirector/ldap.rb +0 -86
- data/vendored/puppet/lib/puppet/indirector/node/ldap.rb +0 -275
- data/vendored/puppet/lib/puppet/provider/aixobject.rb +0 -392
- data/vendored/puppet/lib/puppet/provider/cron/crontab.rb +0 -297
- data/vendored/puppet/lib/puppet/ssl/certificate_authority.rb +0 -475
- data/vendored/puppet/lib/puppet/ssl/certificate_authority/autosign_command.rb +0 -45
- data/vendored/puppet/lib/puppet/ssl/certificate_authority/interface.rb +0 -324
- data/vendored/puppet/lib/puppet/ssl/certificate_factory.rb +0 -219
- data/vendored/puppet/lib/puppet/ssl/certificate_revocation_list.rb +0 -111
- data/vendored/puppet/lib/puppet/ssl/inventory.rb +0 -55
- data/vendored/puppet/lib/puppet/type/cron.rb +0 -480
@@ -1,275 +0,0 @@
|
|
1
|
-
require 'puppet/node'
|
2
|
-
require 'puppet/indirector/ldap'
|
3
|
-
|
4
|
-
class Puppet::Node::Ldap < Puppet::Indirector::Ldap
|
5
|
-
desc "Search in LDAP for node configuration information. See
|
6
|
-
the [LDAP Nodes](https://puppet.com/docs/puppet/latest/nodes_ldap.html) page for more information. This will first
|
7
|
-
search for whatever the certificate name is, then (if that name
|
8
|
-
contains a `.`) for the short name, then `default`.
|
9
|
-
Requires ruby-ldap with MRI ruby or jruby-ldap with puppetserver/jruby"
|
10
|
-
|
11
|
-
# The attributes that Puppet class information is stored in.
|
12
|
-
def class_attributes
|
13
|
-
Puppet[:ldapclassattrs].split(/\s*,\s*/)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Separate this out so it's relatively atomic. It's tempting to call
|
17
|
-
# process instead of name2hash() here, but it ends up being
|
18
|
-
# difficult to test because all exceptions get caught by ldapsearch.
|
19
|
-
# LAK:NOTE Unfortunately, the ldap support is too stupid to throw anything
|
20
|
-
# but LDAP::ResultError, even on bad connections, so we are rough-handed
|
21
|
-
# with our error handling.
|
22
|
-
def name2hash(name)
|
23
|
-
info = nil
|
24
|
-
ldapsearch(search_filter(name)) { |entry| info = entry2hash(entry) }
|
25
|
-
info
|
26
|
-
end
|
27
|
-
|
28
|
-
# Look for our node in ldap.
|
29
|
-
def find(request)
|
30
|
-
names = [request.key]
|
31
|
-
names << request.key.sub(/\..+/, '') if request.key.include?(".") # we assume it's an fqdn
|
32
|
-
names << "default"
|
33
|
-
|
34
|
-
facts = request.options[:facts].is_a?(Puppet::Node::Facts) ? request.options[:facts] : nil
|
35
|
-
|
36
|
-
node = nil
|
37
|
-
names.each do |name|
|
38
|
-
next unless info = name2hash(name)
|
39
|
-
|
40
|
-
merge_parent(info) if info[:parent]
|
41
|
-
info[:environment] ||= request.environment
|
42
|
-
node = info2node(request.key, info, facts)
|
43
|
-
break
|
44
|
-
end
|
45
|
-
|
46
|
-
node
|
47
|
-
end
|
48
|
-
|
49
|
-
# Find more than one node. LAK:NOTE This is a bit of a clumsy API, because the 'search'
|
50
|
-
# method currently *requires* a key. It seems appropriate in some cases but not others,
|
51
|
-
# and I don't really know how to get rid of it as a requirement but allow it when desired.
|
52
|
-
def search(request)
|
53
|
-
if classes = request.options[:class]
|
54
|
-
classes = [classes] unless classes.is_a?(Array)
|
55
|
-
filter = "(&(objectclass=puppetClient)(puppetclass=" + classes.join(")(puppetclass=") + "))"
|
56
|
-
else
|
57
|
-
filter = "(objectclass=puppetClient)"
|
58
|
-
end
|
59
|
-
|
60
|
-
infos = []
|
61
|
-
ldapsearch(filter) { |entry| infos << entry2hash(entry, request.options[:fqdn]) }
|
62
|
-
|
63
|
-
return infos.collect do |info|
|
64
|
-
merge_parent(info) if info[:parent]
|
65
|
-
info[:environment] ||= request.environment
|
66
|
-
info2node(info[:name], info)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# The parent attribute, if we have one.
|
71
|
-
def parent_attribute
|
72
|
-
if pattr = Puppet[:ldapparentattr] and ! pattr.empty?
|
73
|
-
pattr
|
74
|
-
else
|
75
|
-
nil
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
# The attributes that Puppet will stack as array over the full
|
80
|
-
# hierarchy.
|
81
|
-
def stacked_attributes
|
82
|
-
Puppet[:ldapstackedattrs].split(/\s*,\s*/)
|
83
|
-
end
|
84
|
-
|
85
|
-
# Convert the found entry into a simple hash.
|
86
|
-
def entry2hash(entry, fqdn = false)
|
87
|
-
result = {}
|
88
|
-
|
89
|
-
cn = entry.dn[ /cn\s*=\s*([^,\s]+)/i,1]
|
90
|
-
dcs = entry.dn.scan(/dc\s*=\s*([^,\s]+)/i)
|
91
|
-
result[:name] = fqdn ? ([cn]+dcs).join('.') : cn
|
92
|
-
result[:parent] = get_parent_from_entry(entry) if parent_attribute
|
93
|
-
result[:classes] = get_classes_from_entry(entry)
|
94
|
-
result[:stacked] = get_stacked_values_from_entry(entry)
|
95
|
-
result[:parameters] = get_parameters_from_entry(entry)
|
96
|
-
|
97
|
-
# delete from parameters to prevent "Already declered variable $environment" error
|
98
|
-
result[:environment] = result[:parameters].delete(:environment) if result[:parameters][:environment]
|
99
|
-
|
100
|
-
result[:stacked_parameters] = {}
|
101
|
-
|
102
|
-
if result[:stacked]
|
103
|
-
result[:stacked].each do |value|
|
104
|
-
param = value.split('=', 2)
|
105
|
-
result[:stacked_parameters][param[0]] = param[1]
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
if result[:stacked_parameters]
|
110
|
-
result[:stacked_parameters].each do |param, value|
|
111
|
-
result[:parameters][param] = value unless result[:parameters].include?(param)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
result[:parameters] = convert_parameters(result[:parameters])
|
116
|
-
|
117
|
-
result
|
118
|
-
end
|
119
|
-
|
120
|
-
# Default to all attributes.
|
121
|
-
def search_attributes
|
122
|
-
ldapattrs = Puppet[:ldapattrs]
|
123
|
-
|
124
|
-
# results in everything getting returned
|
125
|
-
return nil if ldapattrs == "all"
|
126
|
-
|
127
|
-
search_attrs = class_attributes + ldapattrs.split(/\s*,\s*/)
|
128
|
-
|
129
|
-
if pattr = parent_attribute
|
130
|
-
search_attrs << pattr
|
131
|
-
end
|
132
|
-
|
133
|
-
search_attrs
|
134
|
-
end
|
135
|
-
|
136
|
-
# The ldap search filter to use.
|
137
|
-
def search_filter(name)
|
138
|
-
filter = Puppet[:ldapstring]
|
139
|
-
|
140
|
-
if filter.include? "%s"
|
141
|
-
# Don't replace the string in-line, since that would hard-code our node
|
142
|
-
# info.
|
143
|
-
filter = filter.gsub('%s', name)
|
144
|
-
end
|
145
|
-
filter
|
146
|
-
end
|
147
|
-
|
148
|
-
private
|
149
|
-
|
150
|
-
# Add our hash of ldap information to the node instance.
|
151
|
-
def add_to_node(node, information)
|
152
|
-
node.classes = information[:classes].uniq unless information[:classes].nil? or information[:classes].empty?
|
153
|
-
node.parameters = information[:parameters] unless information[:parameters].nil? or information[:parameters].empty?
|
154
|
-
node.environment = information[:environment] if information[:environment]
|
155
|
-
end
|
156
|
-
|
157
|
-
def convert_parameters(parameters)
|
158
|
-
result = {}
|
159
|
-
parameters.each do |param, value|
|
160
|
-
if value.is_a?(Array)
|
161
|
-
result[param] = value.collect { |v| convert(v) }
|
162
|
-
else
|
163
|
-
result[param] = convert(value)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
result
|
167
|
-
end
|
168
|
-
|
169
|
-
# Convert any values if necessary.
|
170
|
-
def convert(value)
|
171
|
-
case value
|
172
|
-
when Integer; value
|
173
|
-
when "true"; true
|
174
|
-
when "false"; false
|
175
|
-
else
|
176
|
-
value
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
# Find information for our parent and merge it into the current info.
|
181
|
-
def find_and_merge_parent(parent, information)
|
182
|
-
parent_info = name2hash(parent) || raise(Puppet::Error.new(_("Could not find parent node '%{parent}'") % { parent: parent }))
|
183
|
-
information[:classes] += parent_info[:classes]
|
184
|
-
parent_info[:parameters].each do |param, value|
|
185
|
-
# Specifically test for whether it's set, so false values are handled correctly.
|
186
|
-
information[:parameters][param] = value unless information[:parameters].include?(param)
|
187
|
-
end
|
188
|
-
information[:environment] ||= parent_info[:environment]
|
189
|
-
parent_info[:parent]
|
190
|
-
end
|
191
|
-
|
192
|
-
# Take a name and a hash, and return a node instance.
|
193
|
-
def info2node(name, info, facts = nil)
|
194
|
-
node = Puppet::Node.new(name)
|
195
|
-
|
196
|
-
add_to_node(node, info)
|
197
|
-
|
198
|
-
node.fact_merge(facts)
|
199
|
-
|
200
|
-
node
|
201
|
-
end
|
202
|
-
|
203
|
-
def merge_parent(info)
|
204
|
-
parent = info[:parent]
|
205
|
-
|
206
|
-
# Preload the parent array with the node name.
|
207
|
-
parents = [info[:name]]
|
208
|
-
while parent
|
209
|
-
raise ArgumentError, _("Found loop in LDAP node parents; %{parent} appears twice") % { parent: parent } if parents.include?(parent)
|
210
|
-
parents << parent
|
211
|
-
parent = find_and_merge_parent(parent, info)
|
212
|
-
end
|
213
|
-
|
214
|
-
info
|
215
|
-
end
|
216
|
-
|
217
|
-
def get_classes_from_entry(entry)
|
218
|
-
result = class_attributes.inject([]) do |array, attr|
|
219
|
-
if values = entry.vals(attr)
|
220
|
-
values.each do |v| array << v end
|
221
|
-
end
|
222
|
-
array
|
223
|
-
end
|
224
|
-
result.uniq
|
225
|
-
end
|
226
|
-
|
227
|
-
# Workaround jruby-ldap 0.0.2 missing the #to_hash method
|
228
|
-
#
|
229
|
-
# @see https://github.com/jruby/jruby-ldap/pull/5
|
230
|
-
#
|
231
|
-
# @param entry [LDAP::Entry] The LDAP::Entry object to convert to a hash
|
232
|
-
# @return [Hash] The hash of the provided LDAP::Entry object with keys
|
233
|
-
# downcased (puppet variables need to start with lowercase char)
|
234
|
-
def ldap_entry_to_hash(entry)
|
235
|
-
h = {}
|
236
|
-
entry.get_attributes.each { |a| h[a.downcase.to_sym] = entry[a] }
|
237
|
-
h[:dn] = [entry.dn]
|
238
|
-
h
|
239
|
-
end
|
240
|
-
|
241
|
-
def get_parameters_from_entry(entry)
|
242
|
-
stacked_params = stacked_attributes
|
243
|
-
ldap_entry_to_hash(entry).inject({}) do |hash, ary|
|
244
|
-
unless stacked_params.include?(ary[0]) # don't add our stacked parameters to the main param list
|
245
|
-
if ary[1].length == 1
|
246
|
-
hash[ary[0]] = ary[1].shift
|
247
|
-
else
|
248
|
-
hash[ary[0]] = ary[1]
|
249
|
-
end
|
250
|
-
end
|
251
|
-
hash
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
def get_parent_from_entry(entry)
|
256
|
-
pattr = parent_attribute
|
257
|
-
|
258
|
-
return nil unless values = entry.vals(pattr)
|
259
|
-
|
260
|
-
if values.length > 1
|
261
|
-
raise Puppet::Error,
|
262
|
-
_("Node entry %{entry} specifies more than one parent: %{parents}") % { entry: entry.dn, parents: values.inspect }
|
263
|
-
end
|
264
|
-
return(values.empty? ? nil : values.shift)
|
265
|
-
end
|
266
|
-
|
267
|
-
def get_stacked_values_from_entry(entry)
|
268
|
-
stacked_attributes.inject([]) do |result, attr|
|
269
|
-
if values = entry.vals(attr)
|
270
|
-
result += values
|
271
|
-
end
|
272
|
-
result
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
@@ -1,392 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Common code for AIX providers. This class implements basic structure for
|
3
|
-
# AIX resources.
|
4
|
-
# Author:: Hector Rivas Gandara <keymon@gmail.com>
|
5
|
-
#
|
6
|
-
class Puppet::Provider::AixObject < Puppet::Provider
|
7
|
-
desc "Generic AIX resource provider"
|
8
|
-
|
9
|
-
# The real provider must implement these functions.
|
10
|
-
def lscmd( _value = @resource[:name] )
|
11
|
-
raise Puppet::Error, "Method not defined #{@resource.class.name} #{@resource.name}: Base AixObject provider doesn't implement lscmd"
|
12
|
-
end
|
13
|
-
|
14
|
-
def addcmd( _extra_attrs = [] )
|
15
|
-
raise Puppet::Error, "Method not defined #{@resource.class.name} #{@resource.name}: Base AixObject provider doesn't implement addcmd"
|
16
|
-
end
|
17
|
-
|
18
|
-
def modifycmd( _attributes_hash = {} )
|
19
|
-
raise Puppet::Error, "Method not defined #{@resource.class.name} #{@resource.name}: Base AixObject provider doesn't implement modifycmd"
|
20
|
-
end
|
21
|
-
|
22
|
-
def deletecmd
|
23
|
-
raise Puppet::Error, "Method not defined #{@resource.class.name} #{@resource.name}: Base AixObject provider doesn't implement deletecmd"
|
24
|
-
end
|
25
|
-
|
26
|
-
# Valid attributes to be managed by this provider.
|
27
|
-
# It is a list of hashes
|
28
|
-
# :aix_attr AIX command attribute name
|
29
|
-
# :puppet_prop Puppet property name
|
30
|
-
# :to Optional. Method name that adapts puppet property to aix command value.
|
31
|
-
# :from Optional. Method to adapt aix command line value to puppet property. Optional
|
32
|
-
class << self
|
33
|
-
attr_accessor :attribute_mapping
|
34
|
-
end
|
35
|
-
|
36
|
-
# Mapping from Puppet property to AIX attribute.
|
37
|
-
def self.attribute_mapping_to
|
38
|
-
if ! @attribute_mapping_to
|
39
|
-
@attribute_mapping_to = {}
|
40
|
-
attribute_mapping.each { |elem|
|
41
|
-
attribute_mapping_to[elem[:puppet_prop]] = {
|
42
|
-
:key => elem[:aix_attr],
|
43
|
-
:method => elem[:to]
|
44
|
-
}
|
45
|
-
}
|
46
|
-
end
|
47
|
-
@attribute_mapping_to
|
48
|
-
end
|
49
|
-
|
50
|
-
# Mapping from AIX attribute to Puppet property.
|
51
|
-
def self.attribute_mapping_from
|
52
|
-
if ! @attribute_mapping_from
|
53
|
-
@attribute_mapping_from = {}
|
54
|
-
attribute_mapping.each { |elem|
|
55
|
-
attribute_mapping_from[elem[:aix_attr]] = {
|
56
|
-
:key => elem[:puppet_prop],
|
57
|
-
:method => elem[:from]
|
58
|
-
}
|
59
|
-
}
|
60
|
-
end
|
61
|
-
@attribute_mapping_from
|
62
|
-
end
|
63
|
-
|
64
|
-
# This functions translates a key and value using the given mapping.
|
65
|
-
# Mapping can be nil (no translation) or a hash with this format
|
66
|
-
# {:key => new_key, :method => translate_method}
|
67
|
-
# It returns a list with the pair [key, value]
|
68
|
-
def translate_attr(key, value, mapping)
|
69
|
-
return [key, value] unless mapping
|
70
|
-
return nil unless mapping[key]
|
71
|
-
|
72
|
-
if mapping[key][:method]
|
73
|
-
new_value = method(mapping[key][:method]).call(value)
|
74
|
-
else
|
75
|
-
new_value = value
|
76
|
-
end
|
77
|
-
[mapping[key][:key], new_value]
|
78
|
-
end
|
79
|
-
|
80
|
-
# Loads an AIX attribute (key=value) and stores it in the given hash with
|
81
|
-
# puppet semantics. It translates the pair using the given mapping.
|
82
|
-
#
|
83
|
-
# This operation works with each property one by one,
|
84
|
-
# subclasses must reimplement this if more complex operations are needed
|
85
|
-
def load_attribute(key, value, mapping, objectinfo)
|
86
|
-
if mapping.nil?
|
87
|
-
objectinfo[key] = value
|
88
|
-
elsif mapping[key].nil?
|
89
|
-
# is not present in mapping, ignore it.
|
90
|
-
true
|
91
|
-
elsif mapping[key][:method].nil?
|
92
|
-
objectinfo[mapping[key][:key]] = value
|
93
|
-
else
|
94
|
-
objectinfo[mapping[key][:key]] = method(mapping[key][:method]).call(value)
|
95
|
-
end
|
96
|
-
|
97
|
-
return objectinfo
|
98
|
-
end
|
99
|
-
|
100
|
-
# Gets the given command line argument for the given key and value,
|
101
|
-
# using the given mapping to translate key and value.
|
102
|
-
# All the objectinfo hash (@resource or @property_hash) is passed.
|
103
|
-
#
|
104
|
-
# This operation works with each property one by one,
|
105
|
-
# and default behaviour is return the arguments as key=value pairs.
|
106
|
-
# Subclasses must reimplement this if more complex operations/arguments
|
107
|
-
# are needed
|
108
|
-
#
|
109
|
-
def get_arguments(key, value, mapping, objectinfo)
|
110
|
-
if mapping.nil?
|
111
|
-
new_key = key
|
112
|
-
new_value = value
|
113
|
-
elsif mapping[key].nil?
|
114
|
-
# is not present in mapping, ignore it.
|
115
|
-
new_key = nil
|
116
|
-
new_value = nil
|
117
|
-
elsif mapping[key][:method].nil?
|
118
|
-
new_key = mapping[key][:key]
|
119
|
-
new_value = value
|
120
|
-
else
|
121
|
-
new_key = mapping[key][:key]
|
122
|
-
new_value = method(mapping[key][:method]).call(value)
|
123
|
-
end
|
124
|
-
|
125
|
-
# convert it to string
|
126
|
-
new_value = Array(new_value).join(',')
|
127
|
-
|
128
|
-
if new_key
|
129
|
-
return [ "#{new_key}=#{new_value}" ]
|
130
|
-
else
|
131
|
-
return []
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
# Convert the provider properties (hash) to AIX command arguments
|
136
|
-
# (list of strings)
|
137
|
-
# This function will translate each value/key and generate the argument using
|
138
|
-
# the get_arguments function.
|
139
|
-
def hash2args(hash, mapping=self.class.attribute_mapping_to)
|
140
|
-
return "" unless hash
|
141
|
-
arg_list = []
|
142
|
-
hash.each {|key, val|
|
143
|
-
arg_list += self.get_arguments(key, val, mapping, hash)
|
144
|
-
}
|
145
|
-
arg_list
|
146
|
-
end
|
147
|
-
|
148
|
-
# Parse AIX command attributes from the output of an AIX command, that
|
149
|
-
# which format is a list of space separated of key=value pairs:
|
150
|
-
# "uid=100 groups=a,b,c".
|
151
|
-
# It returns a hash.
|
152
|
-
#
|
153
|
-
# If a mapping is provided, the keys are translated as defined in the
|
154
|
-
# mapping hash. And only values included in mapping will be added
|
155
|
-
#
|
156
|
-
# NOTE: it will ignore the items not including '='
|
157
|
-
def parse_attr_list(str, mapping=self.class.attribute_mapping_from)
|
158
|
-
properties = {}
|
159
|
-
attrs = []
|
160
|
-
if str.nil? or (attrs = str.split()).empty?
|
161
|
-
return nil
|
162
|
-
end
|
163
|
-
|
164
|
-
attrs.each { |i|
|
165
|
-
if i.include? "=" # Ignore if it does not include '='
|
166
|
-
(key_str, val) = i.split('=')
|
167
|
-
# Check the key
|
168
|
-
if key_str.nil? or key_str.empty?
|
169
|
-
info _("Empty key in string 'i'?")
|
170
|
-
continue
|
171
|
-
end
|
172
|
-
key_str.strip!
|
173
|
-
key = key_str.to_sym
|
174
|
-
val.strip! if val
|
175
|
-
|
176
|
-
properties = self.load_attribute(key, val, mapping, properties)
|
177
|
-
end
|
178
|
-
}
|
179
|
-
properties.empty? ? nil : properties
|
180
|
-
end
|
181
|
-
|
182
|
-
# Parse AIX command output in a colon separated list of attributes,
|
183
|
-
# This function is useful to parse the output of commands like lsfs -c:
|
184
|
-
# #MountPoint:Device:Vfs:Nodename:Type:Size:Options:AutoMount:Acct
|
185
|
-
# /:/dev/hd4:jfs2::bootfs:557056:rw:yes:no
|
186
|
-
# /home:/dev/hd1:jfs2:::2129920:rw:yes:no
|
187
|
-
# /usr:/dev/hd2:jfs2::bootfs:9797632:rw:yes:no
|
188
|
-
#
|
189
|
-
# If a mapping is provided, the keys are translated as defined in the
|
190
|
-
# mapping hash. And only values included in mapping will be added
|
191
|
-
def parse_colon_list(str, key_list, mapping=self.class.attribute_mapping_from)
|
192
|
-
properties = {}
|
193
|
-
attrs = []
|
194
|
-
if str.nil? or (attrs = str.split(':')).empty?
|
195
|
-
return nil
|
196
|
-
end
|
197
|
-
|
198
|
-
attrs.each { |val|
|
199
|
-
key = key_list.shift.to_sym
|
200
|
-
properties = self.load_attribute(key, val, mapping, properties)
|
201
|
-
}
|
202
|
-
properties.empty? ? nil : properties
|
203
|
-
end
|
204
|
-
|
205
|
-
# Default parsing function for AIX commands.
|
206
|
-
# It will choose the method depending of the first line.
|
207
|
-
# For the colon separated list it will:
|
208
|
-
# 1. Get keys from first line.
|
209
|
-
# 2. Parse next line.
|
210
|
-
def parse_command_output(output, mapping=self.class.attribute_mapping_from)
|
211
|
-
lines = output.split("\n")
|
212
|
-
# if it begins with #something:... is a colon separated list.
|
213
|
-
if lines[0] =~ /^#.*:/
|
214
|
-
self.parse_colon_list(lines[1], lines[0][1..-1].split(':'), mapping)
|
215
|
-
else
|
216
|
-
self.parse_attr_list(lines[0], mapping)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
# Retrieve all the information of an existing resource.
|
221
|
-
# It will execute 'lscmd' command and parse the output, using the mapping
|
222
|
-
# 'attribute_mapping_from' to translate the keys and values.
|
223
|
-
def getinfo(refresh = false)
|
224
|
-
if @objectinfo.nil? or refresh == true
|
225
|
-
# Execute lsuser, split all attributes and add them to a dict.
|
226
|
-
begin
|
227
|
-
output = execute(self.lscmd)
|
228
|
-
@objectinfo = self.parse_command_output(output)
|
229
|
-
# All attributes without translation
|
230
|
-
@objectosinfo = self.parse_command_output(output, nil)
|
231
|
-
rescue Puppet::ExecutionFailure => detail
|
232
|
-
# Print error if needed. FIXME: Do not check the user here.
|
233
|
-
Puppet.debug "aix.getinfo(): Could not find #{@resource.class.name} #{@resource.name}: #{detail}"
|
234
|
-
end
|
235
|
-
end
|
236
|
-
@objectinfo
|
237
|
-
end
|
238
|
-
|
239
|
-
# Like getinfo, but it will not use the mapping to translate the keys and values.
|
240
|
-
# It might be useful to retrieve some raw information.
|
241
|
-
def getosinfo(refresh = false)
|
242
|
-
if @objectosinfo.nil? or refresh == true
|
243
|
-
getinfo(refresh)
|
244
|
-
end
|
245
|
-
@objectosinfo || Hash.new
|
246
|
-
end
|
247
|
-
|
248
|
-
|
249
|
-
# List all elements of given type. It works for colon separated commands and
|
250
|
-
# list commands.
|
251
|
-
# It returns a list of names.
|
252
|
-
def self.list_all
|
253
|
-
names = []
|
254
|
-
begin
|
255
|
-
output = execute([self.command(:list), 'ALL'])
|
256
|
-
|
257
|
-
output = output.split("\n").select{ |line| line != /^#/ }
|
258
|
-
|
259
|
-
output.each do |line|
|
260
|
-
name = line.split(/[ :]/)[0]
|
261
|
-
names << name if not name.empty?
|
262
|
-
end
|
263
|
-
rescue Puppet::ExecutionFailure => detail
|
264
|
-
# Print error if needed
|
265
|
-
Puppet.debug "aix.list_all(): Could not get all resources of type #{@resource.class.name}: #{detail}"
|
266
|
-
end
|
267
|
-
names
|
268
|
-
end
|
269
|
-
|
270
|
-
|
271
|
-
#-------------
|
272
|
-
# Provider API
|
273
|
-
# ------------
|
274
|
-
|
275
|
-
# Clear out the cached values.
|
276
|
-
def flush
|
277
|
-
@property_hash.clear if @property_hash
|
278
|
-
@objectinfo.clear if @objectinfo
|
279
|
-
end
|
280
|
-
|
281
|
-
# Check that the user exists
|
282
|
-
def exists?
|
283
|
-
!!getinfo(true) # !! => converts to bool
|
284
|
-
end
|
285
|
-
|
286
|
-
# Return all existing instances
|
287
|
-
# The method for returning a list of provider instances. Note that it returns
|
288
|
-
# providers, preferably with values already filled in, not resources.
|
289
|
-
def self.instances
|
290
|
-
objects=[]
|
291
|
-
list_all.each { |entry|
|
292
|
-
objects << new(:name => entry, :ensure => :present)
|
293
|
-
}
|
294
|
-
objects
|
295
|
-
end
|
296
|
-
|
297
|
-
#- **ensure**
|
298
|
-
# The basic state that the object should be in. Valid values are
|
299
|
-
# `present`, `absent`, `role`.
|
300
|
-
# From ensurable: exists?, create, delete
|
301
|
-
def ensure
|
302
|
-
if exists?
|
303
|
-
:present
|
304
|
-
else
|
305
|
-
:absent
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
# Create a new instance of the resource
|
310
|
-
def create
|
311
|
-
if exists?
|
312
|
-
info _("already exists")
|
313
|
-
# The object already exists
|
314
|
-
return nil
|
315
|
-
end
|
316
|
-
|
317
|
-
begin
|
318
|
-
execute(self.addcmd)
|
319
|
-
rescue Puppet::ExecutionFailure => detail
|
320
|
-
raise Puppet::Error, _("Could not create %{resource} %{name}: %{detail}") % { resource: @resource.class.name, name: @resource.name, detail: detail }, detail.backtrace
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
# Delete this instance of the resource
|
325
|
-
def delete
|
326
|
-
unless exists?
|
327
|
-
info _("already absent")
|
328
|
-
# the object already doesn't exist
|
329
|
-
return nil
|
330
|
-
end
|
331
|
-
|
332
|
-
begin
|
333
|
-
execute(self.deletecmd)
|
334
|
-
rescue Puppet::ExecutionFailure => detail
|
335
|
-
raise Puppet::Error, _("Could not delete %{resource} %{name}: %{detail}") % { resource: @resource.class.name, name: @resource.name, detail: detail }, detail.backtrace
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
#--------------------------------
|
340
|
-
# Call this method when the object is initialized.
|
341
|
-
# It creates getter/setter methods for each property our resource type supports.
|
342
|
-
# If setter or getter already defined it will not be overwritten
|
343
|
-
def self.mk_resource_methods
|
344
|
-
[resource_type.validproperties, resource_type.parameters].flatten.each do |prop|
|
345
|
-
next if prop == :ensure
|
346
|
-
define_method(prop) { get(prop) || :absent} unless public_method_defined?(prop)
|
347
|
-
define_method(prop.to_s + "=") { |*vals| set(prop, *vals) } unless public_method_defined?(prop.to_s + "=")
|
348
|
-
end
|
349
|
-
end
|
350
|
-
|
351
|
-
# Define the needed getters and setters as soon as we know the resource type
|
352
|
-
def self.resource_type=(resource_type)
|
353
|
-
super
|
354
|
-
mk_resource_methods
|
355
|
-
end
|
356
|
-
|
357
|
-
# Retrieve a specific value by name.
|
358
|
-
def get(param)
|
359
|
-
(hash = getinfo(false)) ? hash[param] : nil
|
360
|
-
end
|
361
|
-
|
362
|
-
# Set a property.
|
363
|
-
def set(param, value)
|
364
|
-
@property_hash[param.intern] = value
|
365
|
-
|
366
|
-
if getinfo().nil?
|
367
|
-
# This is weird...
|
368
|
-
raise Puppet::Error, _("Trying to update parameter '%{param}' to '%{value}' for a resource that does not exists %{resource} %{name}: %{detail}") % { param: param, value: value, resource: @resource.class.name, name: @resource.name, detail: detail }
|
369
|
-
end
|
370
|
-
if value == getinfo()[param.to_sym]
|
371
|
-
return
|
372
|
-
end
|
373
|
-
|
374
|
-
#self.class.validate(param, value)
|
375
|
-
if cmd = modifycmd({param =>value})
|
376
|
-
begin
|
377
|
-
execute(cmd)
|
378
|
-
rescue Puppet::ExecutionFailure => detail
|
379
|
-
raise Puppet::Error, _("Could not set %{param} on %{resource}[%{name}]: %{detail}") % { param: param, resource: @resource.class.name, name: @resource.name, detail: detail }, detail.backtrace
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
# Refresh de info.
|
384
|
-
getinfo(true)
|
385
|
-
end
|
386
|
-
|
387
|
-
def initialize(resource)
|
388
|
-
super
|
389
|
-
@objectinfo = nil
|
390
|
-
@objectosinfo = nil
|
391
|
-
end
|
392
|
-
end
|