newly added ruby function executes on the server instead of the node

53 views
Skip to first unread message

vicki

unread,
Apr 5, 2012, 3:06:00 PM4/5/12
to puppet...@googlegroups.com
Hi,
1) I added this test function tom my /etc/puppet/modules/write_line_to_file/lib/puppet/parser/functions/write_line_to_file.rb :

module Puppet::Parser::Functions newfunction(:write_line_to_file) do |args|
    filename = args[0]
    str = args[1]
    File.open(args[0], 'a') {|fd| fd.puts str }
  end
end


2) I invoked it in the /etc/puppet/modules/write_line_to_file/manifest/init.pp like this:

class write_line_to_file{
write_line_to_file('/tmp/some_file', "Hello world!")
}


3) And I also included this module into my /etc/puppet/manifests/nodes.pp under the correct node:
node default {}
node 'testnode.domain.com'
{
include hosts
include uninstall_screen
include write_line_to_file
}


The function does execute, but on the puppetmaster - not on the remote node. Other two functions execute on the correct node. What am I missing?

Thank you!
Vicki

Nan Liu

unread,
Apr 5, 2012, 3:14:10 PM4/5/12
to puppet...@googlegroups.com

Functions run on puppet master, facts and resource provider run on
puppet agent. Writing functions won't allow you to change puppet agent
files (unless you clone module and run puppet apply). If you are
trying to write line to a file either use augeas type or puppet
file_line from stdlib:

http://forge.puppetlabs.com/puppetlabs/stdlib

HTH,

Nan

Christopher Wood

unread,
Apr 5, 2012, 3:18:34 PM4/5/12
to puppet...@googlegroups.com

For more complicated things than a single line in a file (like RedHat-
style network configs), I've had success with using a template to emit
YAML and then having a puppetized script on the node execute to
complete the configuration. It's a half-decent way of puppetizing an
arbitrary number of files at once.

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

vicki

unread,
Apr 5, 2012, 3:27:47 PM4/5/12
to puppet...@googlegroups.com
Thank you for the quick reply! This explains the the behavior I see.
Reply all
Reply to author
Forward
0 new messages