Ask Your Question

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

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

jaksky gravatar image

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


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: [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


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

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

doc75 gravatar image


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($ |$str| { join("\"${str}\"" }, ',')

I have not tested it, so sorry if it does not work the first time. This answer is inspired from:

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


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

Seen: 1,785 times

Last updated: Mar 21 '15