[Puppet Users] Using variables in regex

827 views
Skip to first unread message

Christian Casar

unread,
Jul 6, 2010, 9:40:04 AM7/6/10
to Puppet Users
Well, how do I use the content of a variable in regex?

$username = "user1"
file { "userdata.tar.bz2":
source => "puppet://$server/modules/$module/
userdata.tar.bz2",
ensure => $users ? {
/$username/ => absent,
default => present,
},
}

$users is a custom fact that contains all local users:

users => at avahi bin daemon dnsmasq ftp games haldaemon lp mail
messagebus nobody ntp polkituser postfix pulse root sshd suse uuidd
wwwrun man news uucp puppet user1

When I hardcode "user1" into the regex my test works fine and the file
is removed.

But things like /$variable/ or /\$variable/ or /#{variable}/ just
don't work.
Is it even possible in version 0.25.4?

Jeff McCune

unread,
Jul 6, 2010, 12:47:53 PM7/6/10
to puppet...@googlegroups.com
On Tue, Jul 6, 2010 at 6:40 AM, Christian Casar <c.c...@web.de> wrote:
> Well, how do I use the content of a variable in regex?
...

> But things like /$variable/ or /\$variable/ or /#{variable}/ just
> don't work.
> Is it even possible in version 0.25.4?

I couldn't get this to work either.

I get the same behavior against master, so this may not be fixed in
2.6. I recommend filing a bug for this.

Thanks,
--
Jeff McCune
http://www.puppetlabs.com/

Patrick Mohr

unread,
Jul 6, 2010, 1:40:25 PM7/6/10
to puppet...@googlegroups.com

Try changing #{variable} to ${variable}

Jeff McCune

unread,
Jul 6, 2010, 2:02:18 PM7/6/10
to puppet...@googlegroups.com
On Tue, Jul 6, 2010 at 10:40 AM, Patrick Mohr <kc7...@gmail.com> wrote:
>>
>> Is it even possible in version 0.25.4?
>
> Try changing #{variable} to ${variable}

I tried this, it doesn't work.

Here's my test:

# Regular Expression Test

$who = "jeff"
$party = "jeff, john, bill, carrie"

$match = $party? {
/"${jeff}"/ => "Jeff Match",
default => "Default Match"
}

notice("Match is [${match}]")

Christian Casar

unread,
Jul 7, 2010, 3:19:31 AM7/7/10
to Puppet Users
Ok, I going to file a bugreport for this.
Reply all
Reply to author
Forward
0 new messages