Ryan
2010-May-07 13:05 UTC
[Puppet Users] Breaking down variables (and setting new ones) from within a manifest using regular expressions
Hello all! I''m hoping for your help on what I admit is a weird and uncommon problem. I''m working on a module that (among other things) creates a series of home folders. The format of the home folders looks something like this /filesys/home/#/letter/userid where # is a number between 0-15, letter is the first letter of the userid. Anyhow, I''m inserting a variable into the manifest something like this: $folders = ["/filesys/", "/filesys/home", "/filesys/home/0", "/ filesys/home/0/x/xyz123", /filesys/home/1/a/abc123"] and etc My problem is, I want to take that master variable and break it down so puppet can do different things to different pieces. For example, I was looking at making an if/else statement to take a regular expression that would strip out a userid and make that the variable puppet uses for the owner/group on each of the userid directories. Else, the owner/group would be sys or whatever else. I''m thinking of other stuff too, but my basic question is, does puppet support using regular expressions in if/else statements like this or am I really trying to get too crazy? Thanks in advance for bearing with me! --Ryan -- 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.
John Lyman
2010-May-07 16:00 UTC
[Puppet Users] Re: Breaking down variables (and setting new ones) from within a manifest using regular expressions
You probably want to use the regsubst function: http://docs.puppetlabs.com/references/stable/function.html#regsubst -- 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.
ed-rfmd
2010-May-11 13:56 UTC
[Puppet Users] Re: Breaking down variables (and setting new ones) from within a manifest using regular expressions
I use this to create two variables that I can use in a cron type: # The variable boot_time is set on the client in the /etc/init.d/ puppet-at-boot script # as a FACTER environmental variable i.e. export FACTER_BOOT_TIME=`date ''+%H:%M''` $boot_hour = regsubst($boot_time,''^([0-9]+)[:]([0-9]+)'',''\1'') $boot_minute = regsubst($boot_time,''^([0-9]+)[:]([0-9]+)'',''\2'') I think you would have to create the variables first, then use the variables in the if/else statements. Ed On May 7, 9:05 am, Ryan <dudei...@gmail.com> wrote:> Hello all! > > I''m hoping for your help on what I admit is a weird and uncommon > problem. > > I''m working on a module that (among other things) creates a series of > home folders. The format of the home folders looks something like > this /filesys/home/#/letter/userid where # is a number between 0-15, > letter is the first letter of the userid. > > Anyhow, I''m inserting a variable into the manifest something like > this: $folders = ["/filesys/", "/filesys/home", "/filesys/home/0", "/ > filesys/home/0/x/xyz123", /filesys/home/1/a/abc123"] and etc > > My problem is, I want to take that master variable and break it down > so puppet can do different things to different pieces. For example, I > was looking at making an if/else statement to take a regular > expression that would strip out a userid and make that the variable > puppet uses for the owner/group on each of the userid directories. > Else, the owner/group would be sys or whatever else. > > I''m thinking of other stuff too, but my basic question is, does puppet > support using regular expressions in if/else statements like this or > am I really trying to get too crazy? > > Thanks in advance for bearing with me! > > --Ryan > > -- > 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 athttp://groups.google.com/group/puppet-users?hl=en.-- 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.