I have the following definition in a yaml file:
keepalived:
cluster_name: "cluster.example.lan"
cluster_ip: "192.168.1.10"
cluster_nic: "eth0"
haproxy:
bind_address: %{hiera('keepalived::cluster_ip')}
And as a result in bind_address
I've got an empty string.
If I use %{hiera('keepalived')}
I've got the whole hash printed, but I need only cluster_ip
from this hash. How can I lookup the cluster_ip
?
When looking up a key, Hiera searches up to four hierarchy layers of data, in the following order: Global hierarchy. The current environment's hierarchy. The indicated module's hierarchy, if the key is of the form <MODULE NAME>::<SOMETHING> .
Hiera uses Puppet's facts to specify data sources, so you can structure your overrides to suit your infrastructure. While using facts for this purpose is common, data-sources can also be defined without the use of facts.
The Hiera configuration file is called hiera. yaml . It configures the hierarchy for a given layer of data.
I think it is not possible:
Hiera can only interpolate variables whose values are strings. (Numbers from Puppet are also passed as strings and can be used safely.) You cannot interpolate variables whose values are booleans, numbers not from Puppet, arrays, hashes, resource references, or an explicit undef value.
Additionally, Hiera cannot interpolate an individual element of any array or hash, even if that element’s value is a string.
You can always define cluster_ip as a variable:
common::cluster_ip: "192.168.1.10"
and than use it:
keepalived:
cluster_name: "cluster.example.lan"
cluster_ip: "%{hiera('common::cluster_ip')}"
cluster_nic: "eth0"
haproxy:
bind_address: "%{hiera('common::cluster_ip')}"
Hiera uses the . in a string interpolation to look up sub-elements in an array or hash. Change your hiera code to look like this:
keepalived:
cluster_name: "cluster.example.lan"
cluster_ip: "192.168.1.10"
cluster_nic: "eth0"
haproxy:
bind_address: %{hiera('keepalived.cluster_ip')}
For an array, you use the array index (0 based) instead of a hash key.
See interpolating hash or array elements
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With