Search code examples
puppethiera

Complex hiera lookup not working


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 ?


Solution

  • 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')}"