Hey Nan, Thank you for pointing out the issue around "puts" and why the fact was never actually obtaining a value. That makes sense and definitely fixes my problem.
Also, the irb is awesome and has significantly cut down my debugging time. Thank you for the quick response and for your help. Much appreciated. Cheers, Mike On Tuesday, September 2, 2014 1:04:17 PM UTC-7, Nan Liu wrote: > > On Tue, Sep 2, 2014 at 12:20 PM, Mike Reed <[email protected] > <javascript:>> wrote: > >> Hello all, >> >> I'm attempting to create a custom fact to identify the network to which a >> node belongs to. Below is the fact definition (I realize this fact isn't >> complete but wanted to test what I have so far): >> >> require 'facter' >> Facter.add('network_geo') do >> setcode do >> hostname = Facter.value(:hostname) >> hostname_array = hostname.split('-') >> >> # debug info >> puts "My network is #{hostname_array}" >> end >> end >> >> I then added the fact into a module named sys_ident and more >> specifically, into a directory like so: >> /modules/sys_ident/lib/facter/network_geo.rb >> >> For debugging purposes, I created a quick init.pp for the sys_ident >> module and added this: >> >> class sys_ident { >> notify{"My network identity is: ${network_geo}" :} >> notify{"My hostname identity is: ${hostname}" :} >> } >> >> I then turned on pluginsync on both the puppetmaster and client within >> puppet.conf. >> >> After an initial run on my puppet client, I'm getting the following: >> >> seanconnery-02:/$ sudo puppet agent -tv >> Info: Retrieving pluginfacts >> Info: Retrieving plugin >> Info: Loading facts in /var/lib/puppet/lib/facter/network_geo.rb >> My network is ["seanconnery", "02"] >> My network is ["seanconnery", "02"] >> Info: Caching catalog for seanconnery-02.domain >> Info: Applying configuration version '1409685071' >> Notice: My network identity is: >> Notice: /Stage[main]/Sys_ident/Notify[My network identity is: ]/message: >> defined 'message' as 'My network identity is: ' >> Notice: My hostname identity is: seanconnery-02 >> Notice: /Stage[main]/Sys_ident/Notify[My hostname identity is: >> seanconnery-02]/message: defined 'message' as 'My hostname identity is: >> seanconnery-02' >> Notice: Finished catalog run in 0.04 seconds >> >> As you can see from the output, I'm not receiving the expected output >> from my "network_geo" notify parameter (also not sure why I'm getting the >> "My network" twice. If I run facter from the puppet client, I get nothing >> in return: >> >> seanconnery-02:/$ facter -p network_geo >> >> For good measure, running the same command with the "hostname" fact >> produces this: >> >> seanconnery-02:/$ facter -p hostname >> seanconnery-02 >> >> Based on the output from my client run, it does look like the fact is >> making it to the client but I can't seem to actually invoke it. >> >> I feel that things are generally in the right place and after >> considerable troubleshooting, the only thing I can think of is a potential >> order-of-operations problem. >> >> Does anybody have any suggestions as to why this may be occurring? >> > > The puts command simply print a message and never returned a value for the > fact. You probably meant something along the lines of: > > Facter.add('network_geo') do > setcode do > hostname_array = Facter.value(:hostname).split('-') > > # debug info > puts "My network is #{hostname_array}" > hostname_array.first > end > end > > If you are developing facts, it's much easier to just drop into IRB and > get everything working there rather than doing round trip debugging between > puppet and facter: > > irb(main):001:0> require 'facter' > => true > irb(main):002:0> Facter.value("hostname") > => "demo-1" > irb(main):003:0> Facter.value("hostname").split('-') > => ["demo", "1"] > > irb(main):006:0> Facter.add('network_geo') do > irb(main):007:1* setcode do > irb(main):008:2* hostname_array = Facter.value(:hostname).split('-') > irb(main):009:2> > irb(main):010:2* # debug info > irb(main):011:2* puts "My network is #{hostname_array}" > irb(main):012:2> hostname_array.first > irb(main):013:2> end > irb(main):014:1> end > irb(main):015:0> Facter.value(:network_geo) > My network is ["demo", "1"] > => "demo" > > If you run your existing fact in irb, you'll see the output is nil instead: > > Facter.value(:network_geo) > My network is ["demo", "1"] > => nil > > HTH, > > Nan > -- 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/35c55615-1dfd-4898-99cd-047a165abeed%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
