Jan
2011-Apr-19 08:06 UTC
[Puppet Users] Bake custom function in order to heck for a files existence (on the puppetmaster)
Hi guys, I just try to cook up some ruby code to check for a files existence on the puppetmaster. I tried to bake a custom function in order to be able to use it in connection with an if statement in my manifests. I''ve read the page about how to write custom functions .. http://projects.puppetlabs.com/projects/puppet/wiki/Writing_Your_Own_Functions .. but ain''t got any luck so far :/ Currently my function looks like this: ---------------------------------------------------------------------------- # cat /var/lib/puppet/lib/puppet/parser/functions/exists.rb; module Puppet::Parser::Functions newfunction(:exists, :type => :rvalue) do |args| filename = args[0] File::exist?(filename) end end ---------------------------------------------------------------------------- It also seems like it''s being recognized by puppet because no errors occurs: ---------------------------------------------------------------------------- irb(main):003:0> require ''puppet'' => true irb(main):004:0> require /var/lib/puppet/lib/puppet/parser/functions/ .exists.rb.swp exists.rb irb(main):004:0> require ''/var/lib/puppet/lib/puppet/parser/functions/exists.rb'' => true irb(main):005:0> Puppet::Parser::Functions.function(:exists) => "function_exists" ---------------------------------------------------------------------------- The part of my manifest looks like this: ---------------------------------------------------------------------------- if (exists("/path/to/file")) { [..my puppet code..] } ---------------------------------------------------------------------------- The "puppet code" somehow won''t get evaluated if the clients catalog is being build. If I remove the if-statement the respective code is being execute on the respective client. Any ideas? I think that the function doesn''t return anything and that''s the major problem!? Cheers! JD -- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Jan
2011-Apr-19 11:09 UTC
Re: [Puppet Users] [SOLVED] Bake custom function in order to heck for a files existence (on the puppetmaster)
I was using the wrong path so the function seems to work as expected :) On 04/19/2011 10:06 AM Jan wrote:> Hi guys, > > I just try to cook up some ruby code to check for a files existence on the > puppetmaster. I tried to bake a custom function in order to be able to use > it in connection with an if statement in my manifests. > > I''ve read the page about how to write custom functions .. > > http://projects.puppetlabs.com/projects/puppet/wiki/Writing_Your_Own_Functions > > .. but ain''t got any luck so far :/ > > Currently my function looks like this: > > ---------------------------------------------------------------------------- > # cat /var/lib/puppet/lib/puppet/parser/functions/exists.rb; > module Puppet::Parser::Functions > newfunction(:exists, :type => :rvalue) do |args| > filename = args[0] > File::exist?(filename) > end > end > ---------------------------------------------------------------------------- > > It also seems like it''s being recognized by puppet because no errors occurs: > > ---------------------------------------------------------------------------- > irb(main):003:0> require ''puppet'' > => true > irb(main):004:0> require /var/lib/puppet/lib/puppet/parser/functions/ > .exists.rb.swp exists.rb > irb(main):004:0> require > ''/var/lib/puppet/lib/puppet/parser/functions/exists.rb'' > => true > irb(main):005:0> Puppet::Parser::Functions.function(:exists) > => "function_exists" > ---------------------------------------------------------------------------- > > The part of my manifest looks like this: > > ---------------------------------------------------------------------------- > if (exists("/path/to/file")) { > [..my puppet code..] > } > ---------------------------------------------------------------------------- > > The "puppet code" somehow won''t get evaluated if the clients catalog is > being build. If I remove the if-statement the respective code is being > execute on the respective client. Any ideas? I think that the function > doesn''t return anything and that''s the major problem!? > > Cheers! > > JD >-- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.