Linux – Adding lines to /etc/profile with puppet

bashjavalinuxpuppet

I use puppet to install a current JDK and tomcat.

package {
    [ "openjdk-6-jdk", "openjdk-6-doc", "openjdk-6-jre",
      "tomcat6", "tomcat6-admin", "tomcat6-common", "tomcat6-docs", 
      "tomcat6-user" ]:
    ensure => present,
}

Now I'd like to add

JAVA_HOME="/usr/lib/java"
export JAVA_HOME

to /etc/profile, just to get this out of the way. I haven't found a straightforward answer in the docs, yet. Is there a recommended way to do this?

In general, how do I tell puppet to place this file there or modify that file? I'm using puppet for a single node (in standalone mode) just to try it out and to keep a log of the server setup.

Best Answer

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?