spaceship operator with a regex!?

398 views
Skip to first unread message

Guy Matz

unread,
Mar 19, 2012, 3:58:01 PM3/19/12
to puppet...@googlegroups.com
Hi!  Anyone knoe if it's possible to realize resources with the spaceship operator checking for regex equality?

Something like:

User<| group =~ /(qa|prod)/ |>

If not, anyone know of another way to do this sort of thing?

Thanks a lot!
Guy

Nan Liu

unread,
Mar 19, 2012, 5:00:32 PM3/19/12
to puppet...@googlegroups.com

No regex support, but I think you can do User <| (group == 'qa' or
group == 'prod') |>.

HTH,

Nan

Peter Berghold

unread,
Mar 20, 2012, 9:29:10 AM3/20/12
to puppet...@googlegroups.com
OK... this is similar to something that I've been scratching my head over...

Given something like

@@file { "blah: ${hostname}": .... }

and

@@file {"foo: ${hostname}": ...}

I'm going to have a bunch of exported resources

On one system I want to instantiate all the "blah:" and on another "foo:"

what mechanism can I use to make that happen?

if I just do File <| |> I'll get everything and if I do File<| tag == "blah" |> I'll miss everything... or am I missing something?




--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.




--
Peter L. Berghold
Owner, Shark River Technical Solutions LLC

jcbollinger

unread,
Mar 20, 2012, 5:19:04 PM3/20/12
to Puppet Users


On Mar 20, 8:29 am, Peter Berghold <salty.cowd...@gmail.com> wrote:
> OK... this is similar to something that I've been scratching my head over...
>
> Given something like
>
> @@file { "blah: ${hostname}": .... }
>
> and
>
> @@file {"foo: ${hostname}": ...}
>
> I'm going to have a bunch of exported resources
>
> On one system I want to instantiate all the "blah:" and on another "foo:"
>
> what mechanism can I use to make that happen?
>
> if I just do File <| |> I'll get everything and if I do File<| tag ==
> "blah" |> I'll miss everything... or am I missing something?


Maybe you are missing that you can set explicit tags in your resource
declarations, like so:

@@file { "blah: ${hostname}": tag = 'blah', ... }

by which you could make File<<| tag == 'blah' |>> do what you want.

Perhaps you are missing that resources automatically get tagged with
the names of the classes that declare them, and the names of the
classes that declare those, etc.. Depending on where your exported
resources are declared, you might be able to use that to power File<<|
tag == 'mymodule::myclass' |>>.

It could be that you are missing that defined type instances can be
exported just like any other resource, so that you could also do

define blah () {
file { "/etc/blah/${name}": ... }
}

@@blah { "${hostname}": }

...

Blah<<| |>>


None of that is intended to say that regex matching in the collection
predicate wouldn't be useful, but there are plenty of ways to be
selective about what resources get collected.


John
Reply all
Reply to author
Forward
0 new messages