用puppet将行添加到/ etc / profile?

我使用puppet来安装当前的JDK和tomcat。

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

现在我想补充一点

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

/etc/profile ,只是为了避免这种情况。 我还没有在文档中find直接的答案。 有没有推荐的方法来做到这一点?

一般来说,我该如何告诉puppet把这个文件放在那里或者修改那个文件呢? 我使用puppet作为单个节点(独立模式)只是为了试用它并保留服务器设置的日志 。

将文件添加到/etc/profile.d/ ,后缀为.sh 。 它将作为Red Hat和Debian中衍生的/ etc / profile的一部分来源,不能在其他发行版上说。 一般来说,如果可能的话,最好是添加片段而不是replace分布式文件,因为它往往更安全。

所以在傀儡,下面会做:

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

这是你在找什么,或者你需要更多的细节?

mark的解决scheme是最好的添加到每个人的个人资料,但如果你需要确保一些文件中有一些行,Puppet Labs有一个很好的模块叫做stdlib ,其中包括file_line将会做你所需要的。 以前我在exectypes中使用过echo和grep来做到这一点,但是file_line更容易和更清晰。

这里有它的帮助:

 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.