Thanks guys for the explanation; worked just fine.
Is there any other "good" hiera documentation apart from the one in 
Puppetlab doc?

-San




On Wednesday, April 16, 2014 6:59:27 PM UTC+1, jcbollinger wrote:
>
> On Wednesday, April 16, 2014 11:31:53 AM UTC-5, Sans wrote:
>>
>> Hi there,
>>
>> Trying to figure out how to use  hiera-array in my template. So, this is 
>> what I have in .yaml file:
>>
>
>
> No, you are just trying to use an array.  Your template can't tell where 
> the array came from or how it was constructed.
>
>  
>
>>
>>
>> my_coll_list:
>>>     - mon502.local
>>>     - mon522.local
>>>
>>
>> and in my nodes.pp, I have this:
>>
>> $my_colloctors = hiera_array('my_coll_list')
>>
>>
>>
>>
>
> You probably do not want to use hiera_array() for that.  Use plain hiera() 
> instead.  The former traverses your entire hierarchy, returning an array 
> whose elements are the values matching the specified key at each level.  
> The latter returns the value associated with the requested key at the 
> highest-priority level of your hierarchy that provides one, as whatever 
> data type is modeled by the data (an array, in your example).
>
>  
>
>> then in one of my ERB templates, I using that like this:
>>
>> COLLECTORS = <%= @my_colloctors %> 
>>>
>>
>>
>> if i understood correctly, according the Puppet documentation, using *array 
>> merge lookup,* I was expecting a result like this: COLLECTORS = 
>> ['mon502.local', 'mon522.local']
>> but what I'm getting is: COLLECTORS = mon502.localmon522.local
>>
>>  
>
>    1. You are confusing the Puppet DSL representation of an array with 
>    its (Ruby) stringification.  The latter is what your template will 
> produce, 
>    and it is simply the concatenation of the string values of the array 
>    elements.
>    2. The Puppet DSL form of the value of $my_colloctors that you 
>    actually have is in all likelihood [['mon502.local', 'mon522.local']].  
>    That is, an array whose only element is an array of your colloctors 
>    (whatever those are).  See my previous comments about hiera_array() vs. 
>    hiera().
>    
>  
>
>>
>> What am I missing here?
>>
>>
>
> If you really do want to collect collectors from multiple levels of your 
> hierarchy, then you will need to flatten the result.  Additionally, you 
> will need to format it into your template yourself.  There are many ways to 
> do that, but one would be something like this:
>
> COLLECTORS = [<%= @my_collectors.map { |c| "'#{c.to_s}'"}.join(', ') %>]
>
>
> 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/eff94c7e-1651-4c2f-a850-b723ed7406ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to