Ask Your Question

How use puppet data types in templates

asked 2018-02-01 16:38:31 -0600

Gadd gravatar image

Hi, how use in correct way puppet data types when you use call_function and lookup, for example

puppet server version 4.9

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

In this way there is an error.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2018-02-04 03:37:21 -0600

Henrik Lindberg gravatar image

updated 2018-02-04 03:38:23 -0600

The example will not work because 'Array' is a string and not an instance of a puppet data type. There is a type parser in puppet 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 (in puppet language):

<%= 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) in ERB:


or example (using type factory) in ERB:


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

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

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

edit flag offensive delete link more

answered 2018-02-03 12:52:34 -0600

First, let's establish how'd lookup() be called in the Puppet language (I guess, writing an epp() template isn't sufficient in your case).

lookup('somekey', Array, 'deep')

Then, confer to § “Puppet data types in Ruby”. Thus you have to write

scope.call_function('lookup', ['somekey', Array, 'deep'])
edit flag offensive delete link more


Sorry but that is wrong! `Array` is a Ruby array, not the puppet data type!!

Henrik Lindberg gravatar imageHenrik Lindberg ( 2018-02-04 03:33:00 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2018-02-01 16:38:31 -0600

Seen: 301 times

Last updated: Feb 04