On Mon, Aug 22, 2011 at 11:03 AM, jcbollinger <john.bollin...@stjude.org>wrote:

>
>
> On Aug 22, 2:08 am, Brian Troutwine <br...@troutwine.us> wrote:
> > Hello, all.
> >
> > I am unable to get the utilize the output of a custom fact in a template
> > while, simultaniously, succeeding at doing so with another custom fact. I
> > receive no errors and am utterly at a loss. The failing custom fact that
> > looks like this:
> >
> > # cat /var/lib/puppet/lib/facter/memorysize_mb.rb
> > # As seen in:
> http://groups.google.com/group/puppet-users/browse_thread/thread/f1c0...
> >
> > require 'facter'
> > Facter.add("memorysize_mb") do
> >   confine :kernel => :Linux
> >   ram = 0
> >   # Steal linux's meminfo
> >   File.open( "/proc/meminfo" , 'r' ) do |f|
> >     f.grep( /^MemTotal:/ ) { |mem|
> >       ram = mem.split( / +/ )[1].to_i / 1024
> >     }
> >   end
> >   setcode do
> >     ram
> >   end
> > end
> >
> > The following works great:
> >
> > # facter --puppet memorysize_mb
> > 17495
>
>
> Is that on the client for which the template is screwy?  If not then
> the first thing to do is to test there.  Possibly the fact is not
> getting synced to the client, or perhaps it fails there.
>
>
Ah, yes, terribly sorry. This was run on the client machine.


>
> > Just like I expect; just like as advertised here:
> http://www.puppetlabs.com/blog/facter-part-2-testing-and-deployment/and
> > herehttp://projects.puppetlabs.com/projects/1/wiki/Adding_Factsandherehttp://
> www.krzywanski.net/archives/666. Everything looks to be going
> > smooth. Indeed, I already have another custom fact that I'm using to
> great
> > success in templates already. Looks like this:
> >
> > # cat /var/lib/puppet/lib/facter/stack_depth.rb
> >
> > require 'facter'
> >
> > Facter.add('stack_depth') do
> >   setcode do
> >     %x{bash -c 'ulimit -s'}.chomp.to_i
> >   end
> > end
> >
> > In my template when I do
> >
> > maintenance_work_mem = <%= memorysize_mb.to_i * 0.15 %>MB
> > max_stack_depth = <%= stack_depth.to_i - 1000 %>kB
> >
> > the rendered configuration is
> >
> > maintenance_work_mem = MB
> > max_stack_depth = 7192kB
>
>
> It makes me nervous to see executable code inside the block passed to
> Facter.add() but outside the setcode therein.  Evidently it works in
> some contexts, but I don't see what you're gaining by doing that
> here.  All except the 'confine' should be inside the setcode block.
> (In fact, I suspect the confine will fail to have the desired effect
> otherwise.)
>
>
It's a function of my ignorance of writing custom facts. I have yet to find
a good reference for doing so and aped entirely code examples found online.
I haven't the slightest idea of what setcode does. Here's my top search
result for 'factor puppet':

  http://www.puppetlabs.com/puppet/related-projects/facter/

Dead end. Going to

  http://docs.puppetlabs.com/

I search for 'factor' or 'fact' and get a brief reference to using
pre-cooked facts. The search 'puppet custom facts' lead to the references
mentioned in my previous email; none of which are API references. The phrase
'facter rdoc puppet' returns nothing apropos. Do you know of a proper
reference to facter's API? If not, would you kindly explain setcode and why
code being outside of it makes you nervous?


> Also, try 'notify'ing the fact value in the scope wherein you evaluate
> the template.  For example,
>
> class example {
>  notify { "maintenance_work_mem_debug":
>    message => "maintenance_work_mem is '${::maintenance_work_mem}'
> for kernel '${::kernel}'"
>  }
>
>  file {"/etc/my_templated_file":
>    content => template("my_template.erb")
>  }
> }
>
>
The issue has nondeterministically resolved itself, which is a bummer; I can
no longer debug. I understand 'notify' only in the context of services or
execs. What does it mean to notify a fact? Moreover, do you have a reference
to the broader meaning of 'notify' that I am, apparently, missing?


>
> John
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To post to this group, send email to puppet-users@googlegroups.com.
> To unsubscribe from this group, send email to
> puppet-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.
>
>


-- 
Brian L. Troutwine

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to