Ask Your Question

Ordering of hiera_hash

asked 2015-12-06 06:47:35 -0600

hibbert gravatar image

updated 2015-12-06 17:02:37 -0600

ramindk gravatar image

I was looking into a way of producing a templated file entirely from hiera I have go this to work using a hiera_hash from the values in hiera and the template then looks like this:-

<% scope.function_hiera(["test_template_from_yaml", []]).each do |key,val| -%>
<%= key %>=<%= val %>
<% end -%>

The problem is that each time puppet is run the content of the file will change and the ordering of the values will shuffle. This could cause problems if the template will cause a service to restart.

Ideally I'd like the hiera_hash to be ordered the same way it is in the yaml file it is retrieved from. Is there anyway of ordering it like this - or some of other way?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-12-06 17:05:45 -0600

ramindk gravatar image

You have two options. The first is the sort by keys within your template. Check Stack Overflow or other code help site for syntax. The second option is to update the distro that runs your Puppet master to one that comes with Ruby 1.9.3 or better. 1.9.3+ preserves insert order of hash. Only matters on the master because templates are evaluated on the master.

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-12-06 06:47:35 -0600

Seen: 342 times

Last updated: Dec 06 '15