On 4/22/15 4:36 PM, 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?
Better to use the programming language than rely on regex in this case.
#!/usr/bin/env ruby
# vim:syntax=ruby
test = [ 'site-dns2', 'site-project-appname3', 'dashsite---',
'singlesite2', 'site-really-long-name2' ]
test.each do |h|
h = h.split('-')[-1].tr('^A-Z,a-z','')
puts h
end
something along those lines should work.
Ramin
--
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/55383659.2050203%40badapple.net.
For more options, visit https://groups.google.com/d/optout.