Ask Your Question
0

Using hiera hash for epp

asked 2016-10-24 14:54:49 -0500

esmalling gravatar image

updated 2016-10-24 16:40:17 -0500

Given a hash in hiera such as:

some::property:
  foo: 'abcd'
  bar: '1234'

... and manifest code such as:

$val = hiera_hash('some:property')
file{ '/path/to/foo.txt':
  ensure => present,
  content => epp('bar/foo..txt.epp', $val),
  ...
}

When compiled I am getting errors like:

...error during compilation: Evaluation Error: Error while evaluating a Function Call, 'epp' parameter 'parameters' expects a Hash[Pattern[/^\w+$/], Any] value, got Struct[{'foo' => String, 'var' => String }]...

Can I coerce that Struct into a Hash or is there some other way to do what I'm trying to do?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-10-24 15:32:00 -0500

nshobe gravatar image

"Struct" actually IS a hash: https://docs.puppet.com/puppet/latest...dataabstract.html#struct

Looks like maybe it's unhappy with the location your pointing it to in order to find the epp template file? Or maybe it's unhappy with the example hash. I'd have assume it should be something like:

some::property: foo: 'abcd' bar: '1234'

Only change is the added colon after "some".

edit flag offensive delete link more

Comments

Oops - that was a typo in that example. I do actually have two ":" chars there. Updating above...

esmalling gravatar imageesmalling ( 2016-10-24 16:40:07 -0500 )edit

I also thought about the path to the .epp being wrong but if I simply set $val = { 'foo' => 'abcd', 'bar' => '1234' } right in the manifest it works. It seems to me that there may be a bug in the epp parameter checking code that is ignoring the fact that Struct is a Hash.

esmalling gravatar imageesmalling ( 2016-10-24 16:42:48 -0500 )edit
0

answered 2016-10-26 13:04:30 -0500

aharden gravatar image

Hey Eric (?),

I've never used the epp function, but I'm wondering what would happen if you forced $val to be a Hash? (Assuming you're running Puppet 4+)

Hash $val = hiera_hash('some::property')

The hiera_hash function may be returning a Struct because it's a more abstract data type.

edit flag offensive delete link more

Comments

Doing so gives me the error described here: https://tickets.puppetlabs.com/browse/PUP-6022: error during compilation: This Type-Name has no effect. A value was produced and then forgotten (one or more preceding expressions may have the wrong form)

esmalling gravatar imageesmalling ( 2016-10-26 15:04:12 -0500 )edit

Oh yeah - that usage pattern is for parameters, not for variables. It seems redundant, but perhaps: $val = Hash(hiera_hash('some::property')) Per https://docs.puppet.com/puppet/4.7/reference/function.html#conversion-to-hash-and-struct.

aharden gravatar imageaharden ( 2016-10-28 07:13:17 -0500 )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

1 follower

Stats

Asked: 2016-10-24 14:54:49 -0500

Seen: 144 times

Last updated: Oct 26 '16