Puppet Function: stdlib::str2resource
- Defined in:
-
lib/puppet/functions/stdlib/str2resource.rb
- Function type:
- Ruby 4.x API
Summary
This converts a string to a puppet resource.
This attempts to convert a string like 'File[/foo]' into the
puppet resource `File['/foo']` as detected by the catalog.
Things like 'File[/foo, /bar]' are not supported as a
title might contain things like ',' or ' '. There is
no clear value seperator to use.
This function can depend on the parse order of your
manifests/modules as it inspects the catalog thus far.
Overview
stdlib::str2resource(String $res_string) ⇒ Any
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/puppet/functions/stdlib/str2resource.rb', line 15
Puppet::Functions.create_function(:'stdlib::str2resource') do
dispatch :str2resource do
param 'String', :res_string
return_type 'Any'
end
def str2resource(res_string)
type_name, title = Puppet::Resource.type_and_title(res_string, nil)
resource = closure_scope.findresource(type_name, title)
if resource.nil?
raise(Puppet::ParseError, "stdlib::str2resource(): could not find #{type_name}[#{title}], this is parse order dependent and values should not be quoted")
end
resource
end
end
|