You can put arbitrary Ruby code in your ERB templates, so anything you
can do with Ruby, you can do in ERB. For example, if you have a
Puppet variable named 'foo' with the value "4711", you can get "4712"
in your file by writing
<%= foo.to_i() + 1 %>
in your template.
Can you be more specific about what you mean by extracting a number
from a string? What kind of string value do you have, and what number
do you want to extract from it?
/Thomas Bellman
Sounds like a perfect custom fact.
http://reductivelabs.com/trac/puppet/wiki/AddingFacts
Then you can just reference "cluster_id" (or whatever) in your
templates and anywhere else that can use facter.
-Blake
> It's for a load balancing cluster, I want to create different
> variables in the erb file(s)
> using the cluster identifier, which is part of the hostname So from
> the hostname
> 'tc-dev-3' I just need the 3.
>
> From a very quick look at the ruby String reference, scan() or
> split() look like they will
> do the job.
sometimes I'm thinking in situations like these if not rather a facter
variable from a custom fact might be the better approach? with that you
could get off the ugly ruby code (ugly in sense of the structure of your
code) in a view more to a point where the better place might be for it.
so afterwards you can just use the facter variable inside the templates.
greets pete