Hi all,
I have a small facter script which gives me the outcome of a subnet:
Facter.add("lokatie") do
setcode do
%x{facter ipaddress | awk -F"." ''{print
$2}''}.chomp
end
end
This script gives me either 84 or 85 as result.
What I really want is to label 84 as ''AAA'' and 85 as
''BBB'' (so facter
gives either AAA or BBB as a result), but I can''t seem to make it
work :-(
Can anyone push me in the right direction?
Regards,
Dennis
--
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.
Hi Dennis, On Tue, Nov 16, 2010 at 7:28 AM, Dennis vdM <cybernijntje@gmail.com> wrote:> Hi all, > > I have a small facter script which gives me the outcome of a subnet: > > Facter.add("lokatie") do > setcode do > %x{facter ipaddress | awk -F"." ''{print $2}''}.chomp > end > end > > This script gives me either 84 or 85 as result. > What I really want is to label 84 as ''AAA'' and 85 as ''BBB'' (so facter > gives either AAA or BBB as a result), but I can''t seem to make it > work :-( >is 84,85 the full list of numbers that need to be translated? if you know all of the values you want to translate, you could do something like: conversions = { ''84'' => ''AAA'', ''85'' => ''BBB'' } Facter.add("lokatie") do setcode do subnet = %x{facter ipaddress | awk -F"." ''{print $2}''}.chomp conversions[subnet] end end> > Can anyone push me in the right direction? > > Regards, > Dennis > > -- > 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<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://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.
Thanks Dan! The conversions action does exactly what I want. :-) On 16 nov, 18:02, Dan Bode <d...@puppetlabs.com> wrote:> Hi Dennis, > > > > > > On Tue, Nov 16, 2010 at 7:28 AM, Dennis vdM <cybernijn...@gmail.com> wrote: > > Hi all, > > > I have a small facter script which gives me the outcome of a subnet: > > > Facter.add("lokatie") do > > setcode do > > %x{facter ipaddress | awk -F"." ''{print $2}''}.chomp > > end > > end > > > This script gives me either 84 or 85 as result. > > What I really want is to label 84 as ''AAA'' and 85 as ''BBB'' (so facter > > gives either AAA or BBB as a result), but I can''t seem to make it > > work :-( > > is 84,85 the full list of numbers that need to be translated? if you know > all of the values you want to translate, you could do something like: > > conversions = { > ''84'' => ''AAA'', > ''85'' => ''BBB'' > > } > > Facter.add("lokatie") do > setcode do > subnet = %x{facter ipaddress | awk -F"." ''{print $2}''}.chomp > conversions[subnet] > end > end > > > > > > > Can anyone push me in the right direction? > > > Regards, > > Dennis > > > -- > > 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<puppet-users%2Bunsubscribe@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/puppet-users?hl=en.- Tekst uit oorspronkelijk bericht niet weergeven - > > - Tekst uit oorspronkelijk bericht weergeven -- Tekst uit oorspronkelijk bericht niet weergeven - > > - Tekst uit oorspronkelijk bericht weergeven --- 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.
FWIW, it''s probably better performance-wise to do the string
manipulations
in Ruby rather than shelling out to bash.
Facter.add "lokatie" do
setcode do
case Facter.value(:ipaddress).split(''.'')[1]
when ''84'': ''AAA''
when ''85'': ''BBB''
# ...
else
# ...
end
end
end
Peace,
--Jay
On Tue, Nov 16, 2010 at 9:12 AM, Dennis vdM <cybernijntje@gmail.com>
wrote:
> Thanks Dan!
>
> The conversions action does exactly what I want.
>
> :-)
>
> On 16 nov, 18:02, Dan Bode <d...@puppetlabs.com> wrote:
> > Hi Dennis,
> >
> >
> >
> >
> >
> > On Tue, Nov 16, 2010 at 7:28 AM, Dennis vdM
<cybernijn...@gmail.com>
> wrote:
> > > Hi all,
> >
> > > I have a small facter script which gives me the outcome of a
subnet:
> >
> > > Facter.add("lokatie") do
> > > setcode do
> > > %x{facter ipaddress | awk -F"." ''{print
$2}''}.chomp
> > > end
> > > end
> >
> > > This script gives me either 84 or 85 as result.
> > > What I really want is to label 84 as ''AAA'' and
85 as ''BBB'' (so facter
> > > gives either AAA or BBB as a result), but I can''t seem
to make it
> > > work :-(
> >
> > is 84,85 the full list of numbers that need to be translated? if you
know
> > all of the values you want to translate, you could do something like:
> >
> > conversions = {
> > ''84'' => ''AAA'',
> > ''85'' => ''BBB''
> >
> > }
> >
> > Facter.add("lokatie") do
> > setcode do
> > subnet = %x{facter ipaddress | awk -F"."
''{print $2}''}.chomp
> > conversions[subnet]
> > end
> > end
> >
> >
> >
> >
> >
> > > Can anyone push me in the right direction?
> >
> > > Regards,
> > > Dennis
> >
> > > --
> > > 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<puppet-users%2Bunsubscribe@googlegroups.com>
> <puppet-users%2Bunsubscribe@googlegroups.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/puppet-users?hl=en.- Tekst uit
> oorspronkelijk bericht niet weergeven -
> >
> > - Tekst uit oorspronkelijk bericht weergeven -- Tekst uit
oorspronkelijk
> bericht niet weergeven -
> >
> > - Tekst uit oorspronkelijk bericht weergeven -
>
> --
> 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<puppet-users%2Bunsubscribe@googlegroups.com>
> .
> For more options, visit this group at
> http://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.
On Sat, Nov 20, 2010 at 11:01 PM, Jay Adkisson <j4yferd@gmail.com> wrote:> FWIW, it''s probably better performance-wise to do the string manipulations > in Ruby rather than shelling out to bash. > > Facter.add "lokatie" do > setcode do > case Facter.value(:ipaddress).split(''.'')[1] > when ''84'': ''AAA'' > when ''85'': ''BBB'' > > In the interest of portability to Ruby 1.9, please consider using:case Facter.value(:ipaddress).split(''.'')[1] when ''84''; ''AAA'' when ''85''; ''BBB'' ... Note the semicolons instead of colons. -- Jos Backus jos at catnook.com -- 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.