Try :
setcode { network }

>From puppett docs:


   1. A call to Facter.add('fact_name'), which determines the name of the
   fact
   2. A setcode statement for simple resolutions, which is evaluated to
   determine the fact’s value.


On Wed, Jan 13, 2016 at 12:42 AM, Mike Reed <[email protected]> wrote:

> Hello all,
>
> I'm having some trouble with a custom fact and I was hoping somebody could
> tell me what I'm doing wrong.
>
> Here is an example of the code:
>
> require 'facter'
> Facter.add('network') do
>   setcode do
>     hostname = Facter.value(:hostname)
>     ipaddress = Facter.value(:ipaddress)
>     case
>       when
> ipaddres.match(/^(\d[10]\.)(\d[10]\.)([1][2][7]\.)([1-9][1-9][1-9])?/)
>         network = 'net1'
>       when hostname.match(/^nettwo/)
>         network = 'net2'
>       when hostname.match(/^netthree/)
>         network = 'net3'
>       when hostname.match(/^netfour/)
>         network = 'net4'
>       else
>         network = 'nonet'
>       end
>     network
>     end
> end
>
> I've gotten myself into a pickle in that most hosts have a hostname prefix
> to designate what network they are on.  In this case, I don't have a prefix
> but the physical ip is different and my thoughts were to regex match the ip
> address and bingo...but no luck.
>
> Puppet runs and pluginsync does pull down the fact but I never get the
> value of network back.   No errors are displayed or logged when running
> 'facter -p' but again, I never get the value of network back.  I've done
> quite a bit of reading and can't figure out why this one doesn't work.
>
> Does anybody perhaps have any suggestions as to how I might accomplish
> this?
>
> Thank you in advance for your assistance.
>
> Cheers,
>
> Mike
>
> --
> 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/cbf9ea68-fffd-4e14-a467-486d8832bc0e%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/cbf9ea68-fffd-4e14-a467-486d8832bc0e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CALuoJ65V%2B5xzYgtBEWu-HPffkV_rhVT17LDJS%2BUtSXfz1RhbAg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to