Hiera sophisticated search not working

I have the following definition in 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 have an empty string.

If I use %{hiera('keepalived')} , I have the whole hash, but I only need cluster_ip from this hash. How can I find cluster_ip ?

+5
source share
2 answers

I think this 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 logical, non-Puppet numbers, arrays, hashes, resource references, or an explicit undef value.

In addition, Hiera cannot interpolate a single element of any array or hash, even if this element value is a string.

You can always define cluster_ip as a variable:

 common::cluster_ip: "192.168.1.10" 

and how to use it:

 keepalived: cluster_name: "cluster.example.lan" cluster_ip: "%{hiera('common::cluster_ip')}" cluster_nic: "eth0" haproxy: bind_address: "%{hiera('common::cluster_ip')}" 
+8
source

Hiera uses. in string interpolation to search for subitems 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, an array index (based on 0) is used instead of the hash key.

See interpolate hash or array elements

+3
source

Source: https://habr.com/ru/post/1210730/


All Articles