Adding lines to /etc/profile with puppet?
Solution 1
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?
Solution 2
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.
Related videos on Youtube
miku
Updated on September 17, 2022Comments
-
miku over 1 year
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.
-
kashani about 13 yearsIf 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
-
-
Rahim about 13 yearsThis also works on OpenSUSE and Gentoo.
-
miku about 13 yearsThanks, that's great. Got it almost working, just need to find an appropriate way to reference a file relative to the
.pp
as source. -
kashani about 13 yearsAssuming Puppet 0.25 or better source => puppet:///$modulename/$file with the real system path being $modulename/files/$file
-
ztron about 13 yearsIIRC 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
-
gak over 11 yearsMake sure you have pluginsync enabled on the client, otherwise this seems to silently fail.
-
Francesco Casula about 9 yearshere's the doc with direct anchor forge.puppetlabs.com/puppetlabs/stdlib#resources