Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
1  
If you're getting into Puppet, check out Example42 for prebuilt modules. They don't always work as you'd want, but they're coherent and stable. github.com/example42/puppet-modules –  kashani Feb 22 '11 at 16:38
add comment

2 Answers

up vote 14 down vote accepted

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?

share|improve this answer
    
This also works on OpenSUSE and Gentoo. –  Kamil Kisiel Feb 22 '11 at 16:02
    
Thanks, that's great. Got it almost working, just need to find an appropriate way to reference a file relative to the .pp as source. –  miku Feb 22 '11 at 16:17
    
Assuming Puppet 0.25 or better source => puppet:///$modulename/$file with the real system path being $modulename/files/$file –  kashani Feb 22 '11 at 16:35
1  
IIRC 2.6.5 and later emits a deprecation warning if you use the puppet:///$modulename/files/$filename notation. it should look like puppet:///modules/$modulename/files/$filename –  ztron Mar 18 '11 at 20:58
add comment

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.
share|improve this answer
1  
Make sure you have pluginsync enabled on the client, otherwise this seems to silently fail. –  Gerald Kaszuba Dec 25 '12 at 20:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.