On 02/02/18 12:16, Ilya wrote:
Hi, how use in correct way puppet data types when you use call_function and lookup in templates, for example


puppet server version 4.9

|<%=scope.call_function('lookup',['somekey','Array','deep'])-%>|

In this way there is an error.

Yes, that will not work because 'Array' is a string and not an instance of a data type. There is a type parser that can be used to turn strings into data type instances. Strongly recommend to use EPP instead of ERB though - as that would completely remove the problem and you would simply write:

<%= lookup('somekey', Array, 'deep') %>

If you really need to stay with ERB you can call the type parser (give type as string) or the type factory, or work directly with the types.

Using the type parser is recommended and specifying the types as strings
as that is how it is done in the 4.x function API and the code is the
easiest to read.

For example (using type parser):

<%=scope.call_function('lookup',
    ['somekey',
     Puppet::Pops::Types::TypeParser.singleton.parse('Array'),
     'deep'])-%>


or example (using type factory):

<%=scope.call_function('lookup',
    ['somekey',
     Puppet::Pops::Types::TypeFactory.array_of(
       Puppet::Pops::Types::TypeFactory.any),
     'deep'])-%>

In your particular case you could use an available constant for Array[Any] like this:

<%=scope.call_function('lookup',
    ['somekey', Puppet::Pops::Types::PArrayType::DEFAULT, 'deep'])-%>

but calling the types directly is only convenient when the DEFAULT is suitable.

Hope this helps.
Best,
- henrik

--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
You received this message because you are subscribed to the Google Groups "Puppet 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/p52f7g%247d6%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to