Use value from a hash defined in hiera datasource elsewhere in the same hiera datasource

29 views
Skip to first unread message

Craig Wickesser

unread,
Mar 21, 2015, 1:43:48 PM3/21/15
to puppet...@googlegroups.com
I have a hiera (YAML based) data source:

--------------------------------------------------------------

# /etc/puppet/hieradata/foo.yaml

webapp::options:
  http_port: 8080
  timeout: 500

####################
#
# Set the http_port for "foo"
#
####################

# any of these approaches gave an empty value
foo::http_port: "%{hiera('options['http_port']')}"
foo::http_port: "%{hiera('options::http_port')}"
foo::http_port: "%{hiera('options.http_port')}"

--------------------------------------------------------------

The "foo" class needs to know the http_port of the webap, and in my case it should be set to whatever value is in webapp::options['http_port']. The only work around I found is to do this:


--------------------------------------------------------------

# /etc/puppet/hieradata/foo.yaml

webapp_http_port: 8080
webapp::options:
  http_port: "%{hiera('webapp_http_port')}"
  timeout: 500

####################
#
# Set the http_port for "foo"
#
####################

foo::http_port: "%{hiera('webapp_http_port')}"

--------------------------------------------------------------

But I was hoping to just extract the value from the hash. Thoughts?

Wil Cooley

unread,
Mar 23, 2015, 3:55:43 PM3/23/15
to puppet...@googlegroups.com
On Sat, Mar 21, 2015 at 10:43 AM Craig Wickesser <code...@gmail.com> wrote:

But I was hoping to just extract the value from the hash. Thoughts?

Unless I am misunderstanding, I don't think that's possible. The 2nd bullet in "Notes" box in "Interpolation Tokens" in the Hiera Guide (http://docs.puppetlabs.com/hiera/1/variables.html#interpolation-tokens) says:

    Additionally, Hiera cannot interpolate an individual element of any array or hash, even if that element’s value is a string.

Wil
Reply all
Reply to author
Forward
0 new messages