On Sep 13, 2010, at 8:56 PM, Matt Robinson wrote:
> On puppet 2.6 I'm trying to get the compiled catalog for a node in a
> script, but I'm having trouble figuring out how to do this with puppet
> code and still take the facts into account (the facts live in the
> --yamldir by default at /var/lib/puppet/yaml/facts). I'm hoping
> someone knows how to do this without having to do a lot of digging,
> since if that's what it takes I'll keep digging.
>
> I can find the catalog like so
>
> require 'puppet'
> Puppet::Resource::Catalog.find('ubuntu1004desktop.localdomain')
>
> But the catalog this finds doesn't use fact information. I can tell
> because if I have a site.pp like this:
>
> node default {
> $mynotice = $operatingsystem ? {
> Ubuntu => 'ubuntu',
> default => 'blah',
> }
> notify { $mynotice : }
>
> and in irb run
>
>
> Puppet::Resource::Catalog.find('ubuntu1004desktop.localdomain').vertices.select
> {|vertex| vertex.type == "Notify"}.map {|v| v.title}
> => ["blah"]
>
> I know the facts can be accessed by puppet code since I can get the
> catalog to compile to pson and use the facts in the yamldir (looks
> like yamldir isn't the best name for that option or directory) using
> the --compile option:
>
> puppet master --compile ubuntu1004desktop.localdomain
> =>
> {
> "exported": false,
> "line": 6,
> "title": "ubuntu",
> "tags": [
> "notify",
> "ubuntu",
> "node",
> "default",
> "class"
> ],
> "type": "Notify",
> "file": "/etc/puppet/manifests/site.pp"
> },
>
> So I thought I traced the code path to see where the facts were
> getting loaded and found a couple things that I thought might get the
> facts to load properly, but they didn't. Here's a few of the things
> I've tried to get the facts loaded.
>
> Puppet::Node.cache_class = :yaml
> Puppet::Node::Facts.terminus_class = :facter
> Puppet::Node::Facts.cache_class = :yaml
> Puppet.parse_config
>
> Probably way more info than anyone needed and thanks in advance if
> anyone knows where to look.
I think you're essentially there - I think if you just set the
Facts.terminus_class = :yaml, it should work. I think you're looking at the
terminus settings for puppet but you want puppetmaster behavior.
You can introspect this pretty easily with irb:
l...@localhost $ irb
irb(main):001:0> require 'puppet'
=> true
irb(main):002:0> Puppet[:confdir] = "/tmp/foo"
=> "/tmp/foo"
irb(main):003:0> Puppet[:vardir] = "/tmp/foo"
=> "/tmp/foo"
irb(main):004:0> Puppet::Node::Facts.terminus_class = :yaml
=> :yaml
irb(main):005:0> Puppet::Node.terminus_class = :plain
=> :plain
irb(main):006:0> Puppet::Node.find "localhost"
=> #<Puppet::Node:0x1024cb500 @name="localhost", @classes=[], @expiration=Mon
Sep 13 21:51:51 -0700 2010, @time=Mon Sep 13 21:21:51 -0700 2010,
@parameters={}>
irb(main):014:0> Puppet::Node::Facts.indirection.terminus.base
=> "/tmp/foo/client_yaml"
So basically, you can see that the params aren't including the facts, and this
is a problem with the run_mode, which I don't quite understand. Jesse Wolfe
should be able to help with that, I think, and once you've got that sorted you
should be all set.
Make sense?
--
We all have strength enough to endure the misfortunes of others.
-- Francois de La Rochefoucauld
---------------------------------------------------------------------
Luke Kanies -|- http://puppetlabs.com -|- +1(615)594-8199
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.