Regex for case statements

19 views
Skip to first unread message

teja...@gmail.com

unread,
May 6, 2017, 9:30:46 PM5/6/17
to Puppet Users
Hello,

I'm stuck at this point while adding a case statement regex for hostname's macthing...
Here is my sample code I'm working on...

class clearlogs::components::idm {

        case $::hostname {
                'idm-wc-(\d+)p': {

                                file { "/etc/cron.d/idm.sh":
                                        ensure    => present,
                                        mode      => '0755',
                                        owner     => 'root',
                                        group     => 'root',
                                        content   => template('clearlogs/idm.erb'),
                                }

                                cron { 'clearinglogs':
                                        command   => 'sh /etc/cron.d/idm.sh',
                                        user      => 'root',
                                        weekday   => [Monday, Wednesday, Saturday],
                                        hour      => '01',
                                        minute    => '00',
                                        require   => File['/etc/cron.d/idm.sh'],
                                }
                }
        }

}

This code simply does copying of script and running cron job for my hostnames say idm-wc-1p, idm-wc-2p, idm-wc-3p, idm-wc-4p, idm-wc-5p.

So please correct me where i'm doing wrong. It's not working for me....And I'm using puppet open source(3.7.8) without future parser.

Thanks for the help!

Ramin K

unread,
May 7, 2017, 12:55:18 AM5/7/17
to puppet...@googlegroups.com
On 5/6/2017 6:10 PM, teja...@gmail.com wrote:
> Hello,
>
> I'm stuck at this point while adding a case statement regex for
> hostname's macthing...
> Here is my sample code I'm working on...
>
> class clearlogs::components::idm {
>
> case $::hostname {
> 'idm-wc-(\d+)p': {

https://docs.puppet.com/puppet/3.8/lang_conditional.html#syntax-2

needs to be between slashes, /idm-wc-(\d+)p/: {}

If you have regex problems, I find http://rubular.com/ fairly useful for
testing.

Ramin
Reply all
Reply to author
Forward
0 new messages