Search code examples
puppethiera

How can I avoid "write everything twice" in my hiera data?


Is there a better way to format my hiera data? I want to avoid the "write everything twice" problem.

Here is what I have now:

[root@puppet-el7-001 ~]# cat example.yaml 
---
controller_ips: 
 - 10.0.0.51
 - 10.0.0.52
 - 10.0.0.53
controller::horizon_cache_server_ip: 
 - 10.0.0.51:11211
 - 10.0.0.52:11211
 - 10.0.0.53:11211

I was wondering if there is functionality avaialble in hiera that is like Perl's map function. If so then I could do something like:

controller::horizon_cache_server_ip: "%{hiera_map( {"$_:11211"}, %{hiera('controller_ips')})}"

Thanks


Solution

  • The mutation is a problem. It is simpler with identical data thanks to YAML's referencing capability.

    controller_ips: &CONTROLLERS
     - 10.0.0.51
     - 10.0.0.52
     - 10.0.0.53
    controller::horizon_cache_server_ip: *CONTROLLERS
    

    You will need more logic so that the port can be stored independently.

    controller::horizon_cache_server_port: 11211
    

    The manifest needs to be structured in a way that allows you to combine the IPs with the port.