Using exec to create facts is not working

8 views
Skip to first unread message

typedeaf

unread,
May 5, 2008, 4:24:51 PM5/5/08
to Puppet Users
I am trying to read a variable that is within a file and make it a new
'fact'.
This does not seem to be working at all. Results below.
Is there a better way to do this?

nodes.pp
------------
node 'puppet-client' {
include test
}

classes/test.pp
-------------------
class test {
exec { "testvar":
path => "/bin:/usr/bin",
command => "export FACTER_testvar=$(grep val /tmp/
tfile1)"
}

case $testvar {
val1: { notice("found val1") }
val2: { notice("found val2") }
default: { fail("found nothing") }
}
}

puppet-client/tmp/tfile1
------------------------------
blah
val1
blee

RESULTS
-----------
[root@puppet-client ~]# puppetd -t
notice: Ignoring cache
err: Could not retrieve catalog: found nothing at /etc/puppet/
manifests/classes/test.pp:10 on node puppet-client
warning: Not using cache on failed catalog

typedeaf

unread,
May 5, 2008, 4:34:08 PM5/5/08
to Puppet Users
Can't get generate to work properly either:

Server
--------
class test {

$testvar = generate("/bin/grep", "val", "/tmp/tfile1")

case $testvar {
val1: { notice("found val1") }
val2: { notice("found val2") }
default: { fail("found nothing") }
}
}

Client
-------

[root@puppet-client ~]# /bin/grep val /tmp/tfile1
val1
[root@puppet-client ~]# puppetd -t
notice: Ignoring cache
err: Could not retrieve catalog: found nothing at /etc/puppet/
manifests/classes/test.pp:8 on node puppet-client
warning: Not using cache on failed catalog

Any ideas?

Peter Meier

unread,
May 5, 2008, 4:37:43 PM5/5/08
to puppet...@googlegroups.com
Hi

> I am trying to read a variable that is within a file and make it a new
> 'fact'.
> This does not seem to be working at all. Results below.
> Is there a better way to do this?


I don't know from where the hell you have this way or why you do it that
complicated. Ever tried:
http://reductivelabs.com/trac/puppet/wiki/AddingFacts ???

greets pete

Luke Kanies

unread,
May 5, 2008, 5:08:15 PM5/5/08
to puppet...@googlegroups.com
On May 5, 2008, at 3:24 PM, typedeaf wrote:

> I am trying to read a variable that is within a file and make it a new
> 'fact'.
> This does not seem to be working at all. Results below.
> Is there a better way to do this?


As Pete said, use custom facts.

You can't generate facts in the same run as you use them without
following the directions at AddingFacts -- clients determine their
fact list before the server ever starts compiling.

--
Progress isn't made by early risers. It's made by lazy men trying to
find easier ways to do something. --Robert Heinlein
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com

typedeaf

unread,
May 5, 2008, 6:54:44 PM5/5/08
to Puppet Users
Thanks. When testing my fact as stated in the link posted, I get the
following error:

[root@puppet-n1 manifests]# facter datacenter
/root/lib/ruby/facter: Is a directory - /root/lib/ruby/facter
(Errno::EISDIR)
from /usr/bin/facter:16:in `load'
from /usr/bin/facter:16

I did "mkdir -p ~/lib/ruby/facter; export RUBYLIB=~/lib/ruby" and then
copied the facter to the directory.

typedeaF

typedeaf

unread,
May 13, 2008, 12:41:52 PM5/13/08
to Puppet Users
Got the custom fact working, however it does not work from the CLI
using facter as http://reductivelabs.com/trac/puppet/wiki/AddingFacts
describes.
I used the "custom" module as described here
http://reductivelabs.com/trac/puppet/wiki/PluginsInModules

tF
Reply all
Reply to author
Forward
0 new messages