Ask Your Question

Is it possible to have conditionals in hiera yaml?

asked 2014-05-13 08:08:19 -0600

Manish gravatar image

I am trying to achieve following. - I have certain variables defined in hiera yaml for a.yaml - Some of the variables I want to read from the external facts. - However whenever an external fact is not defined I want to use some default.

So for example

key1: value1
key2: %{value2_from_facts} | value2

In this case if custom fact 'value2fromfacts' is not defined, I want key2 to have value2. Is this possible?

Is there any better alternative to having defaults assigned to hiera variable if the facts used are not resolved?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-05-15 05:30:22 -0600

spend gravatar image

Can't you just put the fact in your hiera hierarchy, and as normal fall through to a default?

edit flag offensive delete link more

answered 2016-05-24 03:28:30 -0600

pascal gravatar image

Please have a look at any yaml documentation (my personal favourite is the official docu:, the puppet pages are also quiet good by now). It is a data format, not a programming language.

Hiera does add some variable replacement to the base format, but still no logic.

Any default handling must be done in puppet code (unless I missed some feature in the latest 4.x releases).

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: 2014-05-13 08:08:19 -0600

Seen: 1,814 times

Last updated: May 24 '16