Provisioning Templates and regex

Hi,

can I use regex in the Provision Template?

If I use this I got the error
<% if @host.location.to_s =~ /^DE/ -%>
There was an error rendering the KN Kickstart Default template: Safemode
doesn't allow to access 'match3' on @host.to_jail.location.to_jail.to_s =~
/^DE/

and for this
<% if @host.location.to_s =~ "DE.*" -%>
There was an error rendering the KN Kickstart Default template: undefined
method '=~' for String::Jail (String)

and <% if @host.location.to_s == "DE*" -%>
doesn't work

Could you help me!.
Should this work?

I'm using Foreman 1.3 on CentOS 6.4
Locations and Organizations is configuerd and enabled

thx

Hi, I have the exact same problem. Is there a solution ?

Hello,

regular expressions are considered to be unsafe, therefore you need to turn off “safe mode” in the Administer - Settings and it will work then. Beware that now any operator can put “Kernel.exit(0)” into a template which will cause the Foreman server to stop from now on.

Okay thank you

You can use the match function which is available inside safemode:

<% if @host.location.to_s.match(/^DE/) -%>

Or if you are only interested in the start or end of the string you can use something like

<% if @host.location.to_s.start_with?('DE') -%>
3 Likes