Hi folks, Does anyone know how to do case-insensitive regex in a puppet manifest? I tried obvious things, like adding an ''i'' at the end of my regex (ala perl) but that didn''t work. if ($operatingsystem =~ /(centos|redhat|oel)/) { ... } The following works (for centos), but it''s a bit clunky, if ($operatingsystem =~ /([Cc][Ee][Nn][Tt][Oo][Ss]|redhat|oel)/) { ... } For completion, I found the ''downcasefacts'' directive in puppet.conf, but that''s not really what I want. (Plus, ''downcasefacts'' is deprecated anyway.) -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Jacob Helwig
2011-Apr-05 22:48 UTC
Re: [Puppet Users] case insensitive regex (or if statement)
On Tue, 05 Apr 2011 15:24:12 -0700, Jeffrey wrote:> > Hi folks, > > Does anyone know how to do case-insensitive regex in a puppet > manifest? I tried obvious things, like adding an ''i'' at the end of my > regex (ala perl) but that didn''t work. > > if ($operatingsystem =~ /(centos|redhat|oel)/) { > ... > } > > The following works (for centos), but it''s a bit clunky, > > if ($operatingsystem =~ /([Cc][Ee][Nn][Tt][Oo][Ss]|redhat|oel)/) { > ... > } > > For completion, I found the ''downcasefacts'' directive in puppet.conf, > but that''s not really what I want. (Plus, ''downcasefacts'' is > deprecated anyway.) >After talking with Nick Lewis, we suspect that the following will work: if ($operatingsystem =~ /((?i:centos)|redhat|oel)/) { ... } Tested with the version of Puppet in the next branch, but should work in earlier versions. -- Jacob Helwig
On Tue, Apr 5, 2011 at 3:48 PM, Jacob Helwig <jacob@puppetlabs.com> wrote:> On Tue, 05 Apr 2011 15:24:12 -0700, Jeffrey wrote: >> >> Hi folks, >> >> Does anyone know how to do case-insensitive regex in a puppet >> manifest? I tried obvious things, like adding an ''i'' at the end of my >> regex (ala perl) but that didn''t work. >> >> if ($operatingsystem =~ /(centos|redhat|oel)/) { >> ... >> } >> >> The following works (for centos), but it''s a bit clunky, >> >> if ($operatingsystem =~ /([Cc][Ee][Nn][Tt][Oo][Ss]|redhat|oel)/) { >> ... >> } >> >> For completion, I found the ''downcasefacts'' directive in puppet.conf, >> but that''s not really what I want. (Plus, ''downcasefacts'' is >> deprecated anyway.) >> > > After talking with Nick Lewis, we suspect that the following will work: > > if ($operatingsystem =~ /((?i:centos)|redhat|oel)/) { > ... > }You can obtain the regex string that will work in Puppet via irb to_s: /(centos|redhat|oel)/i.to_s => "(?i-mx:(centos|redhat|oel))" Thanks, Nan -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Apr 5, 3:48 pm, Jacob Helwig <ja...@puppetlabs.com> wrote:> On Tue, 05 Apr 2011 15:24:12 -0700, Jeffrey wrote: > > > Hi folks, > > > Does anyone know how to do case-insensitive regex in a puppet > > manifest? I tried obvious things, like adding an ''i'' at the end of my > > regex (ala perl) but that didn''t work. > > > if ($operatingsystem =~ /(centos|redhat|oel)/) { > > ... > > } > > > The following works (for centos), but it''s a bit clunky, > > > if ($operatingsystem =~ /([Cc][Ee][Nn][Tt][Oo][Ss]|redhat|oel)/) { > > ... > > } > > > For completion, I found the ''downcasefacts'' directive in puppet.conf, > > but that''s not really what I want. (Plus, ''downcasefacts'' is > > deprecated anyway.) > > After talking with Nick Lewis, we suspect that the following will work: > > if ($operatingsystem =~ /((?i:centos)|redhat|oel)/) { > ... > } > > Tested with the version of Puppet in the next branch, but should work in > earlier versions.Thanks Jacob. I was able to get a case insensitive regex using this ? i: syntax. if ($operatingsystem =~ /(?i:centos|redhat|oel)/) { ... } For the record, I''m using puppet 2.6.6 on Centos 5.5. - Jeffrey -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.