Thanks! I will give it a whirl. On Thursday, April 23, 2015 at 7:12:01 AM UTC-7, jcbollinger wrote: > > > > On Wednesday, April 22, 2015 at 6:36:01 PM UTC-5, TheNerd wrote: >> >> Hi, >> >> So I have have the following ruby script for puppet, located in >> /etc/puppetlabs/puppet/environments/production/modules/base/lib/facter >> >> >> Facter.add(:appname) do >> setcode do >> Facter.value(:hostname)[5..-1][/(.*?)(\-|\z)/,1] >> end >> end >> >> >> >> The goal is to get it to match what facter returns for hostname then >> parse it. It should match everything after the last dash to the end >> excluding numbers. >> >> It will match in this example: >> >> site-dns2 the script will return dns which is correct but if i have a >> host name that looks like this: >> >> site-project-appname3 the script returns project not appname. appname >> would be the desired result. >> >> So I need the above to match everything after the last - to the end >> excluding numbers. >> >> Any ideas? >> >> > > Your fact is directly derivative of a standard fact. If it is strictly > for Puppet's consumption, then It would be better implemented as an > ordinary top-scope variable. Compute it unconditionally at the beginning > of your site manifest: > > $appname = regsubst($hostname, '^(?:.*-)?([^-0-9]*)[0-9]*$', '\1') > > If you must do the job with a Ruby regex, then the regex above would work > in that context, too. It matches any string, ignores all hyphens and any > characters preceding a hyphen, ignores any trailing digits, and captures > whatever is left as its single capture group. > > > John > >
-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/1cbf18cf-6f07-4264-9f23-ab128228b8e1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.