Puppet3 | read values from different yaml file

86 views Asked by At

So I'm using puppet3 and I have X.yaml and Y.yaml. X.yaml has profiles::resolv_conf::nameservers: [ '1.1.1.1', '8.8.8.8', '2.2.2.2' ]in it. I want to add that [ '1.1.1.1', '8.8.8.8', '2.2.2.2' ] as a value to the servers: which is in Y.yaml:

 'dns_test':
plugin_type: 'dns_query'
options:
'servers': \['1.1.1.1', '8.8.8.8', "2.2.2.2"\]
'domains': \['google.com'\]
'record_type': 'A'
'timeout': 5
tags:
'input_source': 'dns_query'

By doing this I want to make sure that when someone change values in profiles::resolv_conf::nameservers: that value is changed in this telegraf plugin too.

I tried multiple solution but the one that was the closest was:

 'dns_test': 
plugin_type: 'dns_query'     
options:       
'servers': "%{hiera('profiles::resolv_conf::nameservers')}"       
'domains': ['google.com']       
'record_type': 'A'       
'timeout': 5     
 tags:       'input_source': 'dns_query' 

but problem is that puppet was adding extra " " to the value and final value in plugin conf was: "["1.1.1.1", "2.2.2.2", "8.8.8.8"]" instead of ["1.1.1.1", "2.2.2.2", "8.8.8.8"]

1

There are 1 answers

0
John Bollinger On BEST ANSWER

TL;DR: You can't.

From the current docs and the Puppet documentation archive, I confirm that no version of the %{hiera} interpolation function or its replacement, %{lookup}, ever supported interpolating values other than strings. That's expressed in the current docs like so:

The lookup and hiera interpolation functions look up a key and return the resulting value. The result of the lookup must be a string; any other result causes an error.

(Emphasis added)

What you're looking for would be supported by Hiera 5's %{alias} function, provided that the data are available somewhere else in the same hierarchy (which is also a requirement for %{hiera}). Since you're stuck on Puppet 3, however, you're probably on Hiera 2, and certainly not later than Hiera 3.

"But wait!" You may say. "I'm getting a successful interpolation, but the data are just munged". Specifically, you wrote:

problem is that puppet was adding extra " " to the value and final value

Since %{hiera()} interpolates only strings, it is not surprising that you got a string value, given that you got a value at all. I do find it a bit surprising that Puppet did not throw an error, but I'm not prepared to comment further on that without a minimum reproducible example that demonstrates the behavior.