Problem with conditional in a template

15 views
Skip to first unread message

Dan White

unread,
Dec 3, 2013, 12:54:22 PM12/3/13
to Puppet Users Mailing List
I started with

<% if @agent_environment == "production" then -%>

and this worked.

But then I needed to add a second possibility, so I tried:

<% if (@agent_environment == "production" || @agent_environment == "dmz_production") then -%>

and

<% if ((@agent_environment == "production") || (@agent_environment == "dmz_production")) then -%>

and

<% if (@agent_environment == "production" or @agent_environment == "dmz_production") then -%>

and

<% if ((@agent_environment == "production") or (@agent_environment == "dmz_production")) then -%>

and none of the above will work for either value
My goal is to avoid this:

<% if @agent_environment == "production" then -%>
...code...
<% end -%>

<% if @agent_environment == "dmz_production" then -%>
...duplicate code...
<% end -%>

Suggestions ?

“Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”
Bill Waterson (Calvin & Hobbes)

Ramin K

unread,
Dec 3, 2013, 1:22:40 PM12/3/13
to puppet...@googlegroups.com
I don't see any reason those wouldn't work, but there must be something.
I tend to use this format as I find it more compact.

if (['dbm','dbs']).include? @role -%>

fwiw, it might be better to move the data into Hiera and skip the if
statements altogether.

Ramin

Dan White

unread,
Dec 3, 2013, 2:02:53 PM12/3/13
to puppet...@googlegroups.com
Both excellent suggestions.
Moving this into hiera will take a bit of refactoring/untangling, but your code example should help in the meantime.

Thanks.


“Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”
Bill Waterson (Calvin & Hobbes)


From: "Ramin K" <ramin...@badapple.net>
To: puppet...@googlegroups.com
Sent: Tuesday, December 3, 2013 1:22:40 PM
Subject: Re: [Puppet Users] Problem with conditional in a template
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/529E2170.7050706%40badapple.net.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages