On Thursday, December 19, 2019 at 11:24:20 AM UTC-6, Alexander Sorochynskyi 
wrote:
>
> Hi.
> I have some .yaml file:
>
> iptables::test:
>   ip:
>     1.1.1.1  : 'adm-1'
>     2.2.2.2  : 'adm-2'
>     3.3.3.3  : 'adm-3'
>
> And i want to parse this file in inline_template. 
>
> I do:
>
> $variable1 = hiera('iptables::test.ip')$variable2 = inline_template("<% 
> @variable1.each do |key,value| %>Allow From <%=key %> #<%=value %>\n<% end 
> -%>")
>
> But get error:
> Error 400 on SERVER: Could not find data item iptables::test.ip in any Hiera 
> data file and no default supplied
>
>
If you are on Puppet 4 or later, then you should be using the lookup() 
function instead of the deprecated hiera() family of functions.  On Puppet 
5.5 and later (and perhaps on earlier 5.x releases) that has the particular 
advantage that lookup() is documented to support the dotted key / subkey 
notation you are trying to use, whereas hiera() is not documented to 
support that on any version of Puppet.  The error message you present is 
characteristic of this problem: the system is attempting to interpret the 
whole string "iptables::test.ip" as an Hiera key, instead of recognizing it 
as a separate key ("iptables::test") and subkey ("ip").

 

> Could you help me how parse my .yaml in inline_template. Thank you.
>
>

On recent-enough Puppet, just switching from hiera() to lookup() will 
probably resolve the issue:

$variable1 = lookup('iptables::test.ip')
$variable2 = inline_template("<% @variable1.each do |key,value| %>Allow 
>From <%=key %> #<%=value %>\n<% end -%>")


Alternatively, look up the top-level key, then extract the wanted data from 
it separately, for example:

$variable1 = lookup('iptables::test')
# or $variable1 = hiera('iptables::test')
$variable2 = inline_template("<% @variable1['ip'].each do |key,value| 
%>Allow From <%=key %> #<%=value %>\n<% end -%>")



John


-- 
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/c0e52709-89d0-4561-9cea-59f601ad637d%40googlegroups.com.

Reply via email to