On Wednesday, February 11, 2015 at 7:04:18 AM UTC-6, Robert Reilly wrote:
>
> All, I am getting the following problem with facter on 5 of my nodes,
> Fact resolution fact='enviro', resolution='<anonymous>' resolved to an
> invalid value: Expected (?-mix:xxx(vs|sv).{2,7}\d{1,2}) to be one of
> [Integer, Float, TrueClass, FalseClass, NilClass, String, Array, Hash], but
> was Regexp, this seems to only happen to one application running on rhel
> 5.8 puppet agent 3.5.1 facter 2.0.1
>
>
Do you have other machines running RHEL 5? Is it possible that Facter on
this machine is running under the distribution's Ruby (which is version
1.8.5, no longer supported by Puppet)?
> here is my fact
>
> Facter.add(:enviro) do
> setcode do
> hostname = Facter.value('hostname')
> if ( hostname =~ /^.{5}d{1}/i )
> enviro="dev"
> enviro
> elsif (hostname =~ /^.{5}q{1}/i )
> enviro="qa"
> enviro
> elsif (hostname =~ /^.{4,5}u{1}/i )
> enviro="uat"
> enviro
> elsif (hostname =~ /^.{5}p{1}/i )
> enviro="prod"
> enviro
> elsif (hostname =~ /^.{5}xxx/i )
> enviro="prod"
> enviro
> else
> enviro="unclassified"
> enviro
> end
> end
> end
> ~
>
That's a slightly odd way to write it, but it looks like it should work.
Note that it is pointless for your blocks to end with "enviro" as a
standalone statement when the statement immediately preceding is an
assignment to that variable. The combination has exactly the same
semantics as the assignment alone. Also, it is always pointless to use a
'{1}' quantifier in a regex, as it has the same effect as no quantifier at
all.
Though I don't see a reason why your fact code should fail, I would
probably use much simpler code for the job, myself. Perhaps something like
this:
Facter.add(:enviro) do
setcode do
case Facter.value('hostname')
when /^.{5}d/i
'dev'
when /^.{5}q/i
'qa'
when /^.{4,5}u/i
'uat'
when /^.{5}p/i
'prod'
when /^.{5}xxx/i
'prod'
else
'unclassified'
end
end
end
Not only is it easier to read, there is much less room for any question
about its semantics. There is exactly one (compound) statement at the top
level of the setcode block, so its value determines the fact value. There
are no variable assignments, so it is clear that no value can be carried
forward from an earlier part of the code to a later part. Even someone
with little Ruby experience would have a good chance of understanding what
it's doing if told that the setcode block produces a value.
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/d3da2294-2cba-4265-819e-ab73b5ad2123%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.