Hello! I''ve been trying to use facts from Facter in a custom function. I''ve been following Matthew''s entry in the wiki (http://www.reductivelabs.com/trac/puppet/wiki/WritingYourOwnFunctions). What i''m seeing is that Facter[''fqdn''].value is always returning the fqdn of the puppetmaster host. I was expecting the fqdn of the client host. Here''s the code that is exhibiting this behavior: require ''md5'' module Puppet::Parser::Functions newfunction(:hour_from_fqdn, :type => :rvalue) do |args| MD5.new(Facter[''fqdn''].value).to_s.hex % 4 end end I''ve managed to get this working by using $fqdn inside my node definition and passing it through to my custom definition like this: node ''somenode.domain.com'' { custom_definition { name: address => $fqdn } } define custom_definition ($address){ "custom_name": $random_hour = hour_from_fqdn($address) file { "/path/to/file": content => template("my_template") } } I just wanted to verify that from a call to Facter[''fqdn''].value I should see somenode.domain.com instead of puppet.domain.com as the result. Any thoughts or suggestions? Thanks, Dustin
Dustin Kanske wrote:> Hello! > > I''ve been trying to use facts from Facter in a custom function. I''ve > been following Matthew''s entry in the wiki > (http://www.reductivelabs.com/trac/puppet/wiki/WritingYourOwnFunctions). > > What i''m seeing is that Facter[''fqdn''].value is always returning the > fqdn of the puppetmaster host. I was expecting the fqdn of the client > host.That seems to be working as designed, based on what Matt''s got on the wiki: "Your function will be executed on the server. This means that any files or other resources you reference must be available on the server, and you can''t do anything that requires direct access to the client machine." Perhaps a better question is whether or not (and how) it''s possible to write a custom function that''s executed on the client? Cheers, Matt -- Matt Moor Infrastructure Manager Vquence - Making Video Clickable W: http://www.vquence.com E: matt.moor@vquence.com P: +61 2 8215 0574 F: +61 2 8215 0589 M: +61 414 592 943
On Apr 30, 2007, at 8:26 PM, Dustin Kanske wrote:> Hello! > > I''ve been trying to use facts from Facter in a custom function. I''ve > been following Matthew''s entry in the wiki > (http://www.reductivelabs.com/trac/puppet/wiki/ > WritingYourOwnFunctions). > > What i''m seeing is that Facter[''fqdn''].value is always returning the > fqdn of the puppetmaster host. I was expecting the fqdn of the client > host.Nope, that''s the local library, on the server. If you want a variable from the parser, use ''lookupvar(varname)''. By default it will return "" on undefined varables, but if you add ''false'' as a second argument, it will return :missing instead. -- To get back my youth I would do anything in the world, except take exercise, get up early, or be respectable. -- Oscar Wilde --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
On Apr 30, 2007, at 9:15 PM, Matt Moor wrote:> That seems to be working as designed, based on what Matt''s got on > the wiki:That''s actually Jeff McCune''s document, FWIW.> Perhaps a better question is whether or not (and how) it''s possible to > write a custom function that''s executed on the client?Yes, as long as it doesn''t need to accept any arguments; it''s called a "fact". :) In other words, no, not in the way you''re thinking -- the client does a clean hand-off of everything it knows, the parser compiles the configuration with no more interaction with the client, and the complete configuration is sent back to the client. -- Morgan''s Second Law: To a first approximation all appointments are canceled. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
On 4/30/07, Luke Kanies <luke@madstop.com> wrote:> On Apr 30, 2007, at 9:15 PM, Matt Moor wrote: > > That seems to be working as designed, based on what Matt''s got on > > the wiki: > > That''s actually Jeff McCune''s document, FWIW. > > > Perhaps a better question is whether or not (and how) it''s possible to > > write a custom function that''s executed on the client? > > Yes, as long as it doesn''t need to accept any arguments; it''s called > a "fact". :) > > In other words, no, not in the way you''re thinking -- the client does > a clean hand-off of everything it knows, the parser compiles the > configuration with no more interaction with the client, and the > complete configuration is sent back to the client. >So the root of all of this is, how do you get a fact about the client in a custom function on the server? The answer seems to be lookupvar(''ipaddress'') and not Facter[''ipaddress''].value (as described in WritingYourOwnFunctions). lookupvar(''ipaddress'') gives me the right answer on my setup. The article specifically says that you can use facts about the client in functions on the server but the way it said to get the fact didn''t work for me :)> -- > Morgan''s Second Law: > To a first approximation all appointments are canceled. > --------------------------------------------------------------------- > Luke Kanies | http://reductivelabs.com | http://madstop.com > > > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users >
On Mon, Apr 30, 2007 at 05:38:48PM -1000, Dustin Kanske wrote:> On 4/30/07, Luke Kanies <luke@madstop.com> wrote: > > On Apr 30, 2007, at 9:15 PM, Matt Moor wrote: > > > That seems to be working as designed, based on what Matt''s got on > > > the wiki: > > > > That''s actually Jeff McCune''s document, FWIW. > > > > > Perhaps a better question is whether or not (and how) it''s possible to > > > write a custom function that''s executed on the client? > > > > Yes, as long as it doesn''t need to accept any arguments; it''s called > > a "fact". :) > > > > In other words, no, not in the way you''re thinking -- the client does > > a clean hand-off of everything it knows, the parser compiles the > > configuration with no more interaction with the client, and the > > complete configuration is sent back to the client. > > > > So the root of all of this is, how do you get a fact about the client > in a custom function on the server? > > The answer seems to be lookupvar(''ipaddress'') and not > Facter[''ipaddress''].value (as described in > WritingYourOwnFunctions). lookupvar(''ipaddress'') gives me the right > answer on my setup. > > The article specifically says that you can use facts about the client > in functions on the server but the way it said to get the fact didn''t > work for me :)/me looks embarrassed I suspect my testing method for the code in that article[1] may not have been entirely sufficient. I *thought* Facter[''varname''] worked, but when all is said and done, it does seem a bit stupid to do client fact lookups on the server via Facter[]. On the upside, it''s a wiki, so feel free to fix up the code to do the right thing... <grin> - Matt [1] I don''t know which page Luke was saying that Jeff wrote, but WritingYourOwnFunctions is entirely my fault, as the page history will attest. -- English is about as pure as a cribhouse whore. We don''t just borrow words; on occasion, English has pursued other languages down alleyways to beat them unconscious and rifle their pockets for new vocabulary." -- James D. Nicoll, resident of rec.arts.sf.written
Thanks for writing up the article, Matt. I was surprised to see that you had written up exactly what I was looking for :)> I suspect my testing method for the code in that article[1] may not have > been entirely sufficient. I *thought* Facter[''varname''] worked, but when > all is said and done, it does seem a bit stupid to do client fact lookups on > the server via Facter[]. > > On the upside, it''s a wiki, so feel free to fix up the code to do the right > thing... <grin> >Heh. I didn''t want to update it if it was working for other people though. I''ll drop in my example soon into the wiki. Thanks for your reply, -Dustin> - Matt > > [1] I don''t know which page Luke was saying that Jeff wrote, but > WritingYourOwnFunctions is entirely my fault, as the page history will > attest. > > > -- > English is about as pure as a cribhouse whore. We don''t just borrow > words; on occasion, English has pursued other languages down alleyways > to beat them unconscious and rifle their pockets for new vocabulary." > -- James D. Nicoll, resident of rec.arts.sf.written > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users >
On May 1, 2007, at 12:08 AM, Matt Palmer wrote:> > [1] I don''t know which page Luke was saying that Jeff wrote, but > WritingYourOwnFunctions is entirely my fault, as the page history will > attest.Huh, my bad; I was sure Jeff had pinged me about this first and then wrote the doc. Oops. -- Ours is the age that is proud of machines that think and suspicious of men who try to. -- H. Mumford Jones --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Luke Kanies wrote:> On Apr 30, 2007, at 9:15 PM, Matt Moor wrote: >> That seems to be working as designed, based on what Matt''s got on >> the wiki: > > That''s actually Jeff McCune''s document, FWIW.I don''t remember writing it. =) Version 1 (modified by mpalmer, 3 months ago) -- Jeff McCune The Ohio State University Department of Mathematics Systems Manager _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users