On Oct 2, 2014 10:23 AM, "Mark Rosedale" <mros...@vivox.com> wrote:
>
> I have the following custom function that I'm trying to write.
>
Sorry this isn't an answer to your question, but I recently published a module of functions wrapping the standard system get*by* functions (well, wrapping Ruby's interfaces to the standard system functions): https://forge.puppetlabs.com/wcooley/name_service_lookups
This includes `gethostbyname` and `gethostbyaddr`; the main benefit over querying DNS directly is that it understands nsswitch, so /etc/hosts works and any other host database you might want to use.
But assuming you want to implement this anyway an exercise in learning Ruby & Puppet extensions, you might start by removing all the Puppet stuff and just get the lookups working as a simple standalone Ruby script.
Wil
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/02de838d-6cb2-495a-883d-98fb15782df9%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Credits go to Nan Liu:
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,
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/e2857e58-e52f-44ef-a30b-368fb6e4b9ae%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAF_B3dfyfjunB5UYZF2q577S-bL6QQPqCg2_TVL5p4ZekZf%3D9w%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/C2B7F2AE-CC89-4155-8165-3FD8304AB749%40superseb.nl.
Still haven't been able to hunt down the cause of this issue. Is there a way to test the code with the puppet wrapping on the cli?