On 2014-05-12 16:43, Ramin K wrote:
On 12/5/14 3:16 PM, Lori Cho wrote:
I have two variables and I want to compare them to each other. However,
the regex doesn't return true, because it seems to treat the variable in
the // as a literal.
Something like this:
$variable1 = 'foo'
$variable2 = 'foobar'
if($variable2 =~ /$variable1/) {
notify {"it works":}
} else {
notify {"regex did not work":}
}
root@test-slincsplunk1101r(~)# puppet apply /srv/tmp/test.pp
notice: regex did not work
notice: /Stage[main]//Notify[regex did not work]/message: defined
'message' as 'regex did not work'
How can I do this?
The docs say it's not available.
https://docs.puppetlabs.com/puppet/latest/reference/lang_datatypes.html#regular-expressions
"Alternate forms of regex quoting are not allowed and Ruby-style
variable interpolation is not available."
Ramin
In Puppet 3.7 with future parser the right hand side can be any
expression that evaluates to a regular expression or a string (if string
it is
interpreted as a regexp and the string should not be enclosed in / /).
This will be standard in Puppet 4.0.
e.g
# The variable is a regexp string
if($variable2 =~ $variable) {
#...
# interpolated as part of a regext
if($variable2 =~ "xxxxx$variable") {
#...
Hope that helps
Regards
- henrik
--
Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/
--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/m6ihq0%24ohm%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.