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's 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 an avaialble functionality in hiera that is similar to the Perl map function. If so, I could do something like:
controller::horizon_cache_server_ip: "%{hiera_map( {"$_:11211"}, %{hiera('controller_ips')})}"
thank
+3
source to share
2 answers
Mutation is a problem. It's easier with identical data thanks to the YAML binding 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 for the port to be saved independently.
controller::horizon_cache_server_port: 11211
the manifest should be structured so that you can combine IP addresses with a port.
+1
source to share
It depends on which puppet version you are using. I am puppet 3.x, you can do the following:
common::test::var1: a
common::test::var2: b
common::test::variable:
- "%{hiera('common::test::var1')}"
- "%{hiera('common::test::var2')}"
common::test::variable2:
- "%{hiera('common::test::var1')}:1"
- "%{hiera('common::test::var2')}:2"
In puppet 4.0 you can try using a combination of zip , hash functions from stdlib with the built-in map function . Something like:
$array3 = zip($array1, $array2)
$my_hash = hash($array3)
$my_hash.map |$key,$val|{ "${key}:${val}" }
+2
source to share