I can't get a custom fact to work in Windows

967 views
Skip to first unread message

Dan McManus

unread,
Feb 7, 2013, 5:04:47 PM2/7/13
to puppet...@googlegroups.com
Hello all!

I am using open source puppet 3.0.1 on both the client and master. The issue I am having is that I cannot get a simple custom fact to be recognized in my manifest. Hopefully I am missing something. 

I am trying to have a custom fact that will tell me whether the nsclient++ directory exists or not.
Here's the custom fact, which is located at /etc/puppet/environments/windows/modules/nscp-test/lib/facter

Facter.add(:nsclient) do
setcode do
if File.exists?("c:/program files/nsclient++")
  puts ''nsclient installed'
else
  puts 'no such directory'
end
end
end

my init.pp is dead simple:

class nscp-test {
        notify{$nsclient :}
}

Here's what happens when I run puppet agent --test on the client (windows 2003):

C:\Documents and Settings\All Users\Application Data\PuppetLabs\puppet\var\lib\facter>puppet agent --test
Info: Retrieving plugin
Info: Loading facts in C:/Documents and Settings/All Users/Application Data/PuppetLabs/puppet/var/lib/facter/nsclient.rb
no such directory
no such directory
Info: Caching catalog for <snipped>
Info: Applying configuration version '1360274145'
Notice: undef
Notice: /Stage[main]/Nscp-test/Notify[undef]/message: defined 'message' as 'undef'
Notice: Finished catalog run in 0.42 seconds

from the command line,  facter --puppet nsclient works just fine.

So am I missing something dead simple, or what? This is my first time doing custom facts.

Thanks,

Dan

Justin Stoller

unread,
Feb 7, 2013, 5:28:19 PM2/7/13
to puppet...@googlegroups.com
On Thu, Feb 7, 2013 at 2:04 PM, Dan McManus <mothb...@gmail.com> wrote:
Hello all!

I am using open source puppet 3.0.1 on both the client and master. The issue I am having is that I cannot get a simple custom fact to be recognized in my manifest. Hopefully I am missing something. 

I am trying to have a custom fact that will tell me whether the nsclient++ directory exists or not.
Here's the custom fact, which is located at /etc/puppet/environments/windows/modules/nscp-test/lib/facter

Facter.add(:nsclient) do
setcode do
if File.exists?("c:/program files/nsclient++")
  puts ''nsclient installed'
else
  puts 'no such directory'

`puts` sends the string to stdout, you want to return the string. Ruby will implicitly return the last statement in a block. Which is how the examples in http://docs.puppetlabs.com/guides/custom_facts.html  works.

HTH,
Justin

end
end
end

my init.pp is dead simple:

class nscp-test {
        notify{$nsclient :}
}

Here's what happens when I run puppet agent --test on the client (windows 2003):

C:\Documents and Settings\All Users\Application Data\PuppetLabs\puppet\var\lib\facter>puppet agent --test
Info: Retrieving plugin
Info: Loading facts in C:/Documents and Settings/All Users/Application Data/PuppetLabs/puppet/var/lib/facter/nsclient.rb
no such directory
no such directory
Info: Caching catalog for <snipped>
Info: Applying configuration version '1360274145'
Notice: undef
Notice: /Stage[main]/Nscp-test/Notify[undef]/message: defined 'message' as 'undef'
Notice: Finished catalog run in 0.42 seconds

from the command line,  facter --puppet nsclient works just fine.

So am I missing something dead simple, or what? This is my first time doing custom facts.

Thanks,

Dan

--
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 post to this group, send email to puppet...@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dan McManus

unread,
Feb 7, 2013, 5:39:42 PM2/7/13
to puppet...@googlegroups.com
Hah, yet, just removing the "puts" worked. Many thanks.

ad

unread,
Feb 7, 2013, 5:43:14 PM2/7/13
to puppet...@googlegroups.com
Note that you can also use Puppet.notice to help debug and such. 

Adam
Reply all
Reply to author
Forward
0 new messages