Ask Your Question
0

Is there a better way of handling double quotes hiera to yaml

asked 2015-03-19 05:21:08 -0500

jaksky gravatar image

updated 2015-03-19 05:23:32 -0500

Hello,

I am using a hiera to keep environment/host specific configuration away from code. For generating configuration file - yaml I bump into following scenario:

Hieara config file:

elasticsearch::discovery_unicast_hosts: [ "HOSP-BD-02", "HOSP-BD-03", "HOSP-BD-04" ]

In generate yaml config appears:

discovery.zen.ping.unicast.hosts: [HOSP-BD-02,HOSP-BD-03,HOSP-BD-04]

and trouble is missing double quotes around every single item in the array. I did following processing of the array before inserting to erb template:

 $discovery_unicast_hosts_joined = join($elasticsearch::discovery_unicast_hosts, ",")

If I insert array directly

 ["HOSP-BD-02""HOSP-BD-03""HOSP-BD-04"]

quotes are there but missing comas. One simple and nasty stolution would be escape " in hieara what I am trying to avoid because it breaks consistency and is error prone.

elasticsearch::discovery_unicast_hosts: [ "\"HOSP-BD-02\"", "\"HOSP-BD-03\"", "\"HOSP-BD-04\"" ]

Is there a better way to solve this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-03-21 03:26:29 -0500

doc75 gravatar image

Hello,

Not sure to understand why you need the double quote. Are you goind to use the values in a template or do something else ?

You could try to use map function

joint($elasticsearch::discovery_unicast_hosts.map |$str| { join("\"${str}\"" }, ',')

I have not tested it, so sorry if it does not work the first time. This answer is inspired from: https://ask.puppetlabs.com/question/4195/joining-array-from-hieraconcat-other-value-in-erb/

Perhaps using template to get the value you need is also a good option.

$myvalue = template( 'module_name/template_name' )

Hope this helps.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-03-19 05:21:08 -0500

Seen: 1,218 times

Last updated: Mar 21 '15