Adding lines to /etc/profile with puppet?

Add a file to /etc/profile.d/ with the suffix .sh. It will be sourced as part of /etc/profile in Red Hat and Debian and derivatives, can't say on other distros. Generally speaking, if at all possible, it's better to add snippets rather than replace distributed files as it tends to be more future safe.

So in puppet, the following would do:

file { "/etc/profile.d/set_java_home.sh":
    ensure => present,
    source => ...[whatever's appropriate for your setup]...,
    ...
}

This what you're looking for or do you need more detail?


mark's solution is the best for adding stuff to everyone's profile, but if you ever need to ensure some lines are in a file, Puppet Labs has a great module called stdlib which includes file_line which will do what you need. Previously I've used echo and grep in the exec type to do this, but file_line is so much easier and cleaner.

Here's the help for it:

Ensures that a given line is contained within a file. The implementation
matches the full line, including whitespace at the beginning and end. If
the line is not contained in the given file, Puppet will add the line to
ensure the desired state. Multiple resources may be declared to manage
multiple lines in the same file.

Example:

file_line { 'sudo_rule':
   path => '/etc/sudoers',
   line => '%sudo ALL=(ALL) ALL',
}
file_line { 'sudo_rule_nopw':
   path => '/etc/sudoers',
   line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',
}

In this example, Puppet will ensure both of the specified lines are
contained in the file /etc/sudoers.