我可以使用Puppet运行一个shell内置命令吗?

我希望~/.bashrc在任何时候改变其内容。 我用这样的东西创build了一个bashrc类:

 file { "/root/.bashrc": ensure => present, owner => root, group => root, mode => 0644, source => "puppet:///bashrc/root/.bashrc" } exec { "root_bashrc": command => "source /root/.bashrc", subscribe => File["/root/.bashrc"], } 

但是如你所知, source是一个shell内置的命令,在运行agent的时候,我得到了下面的错误:

 # puppet agent --no-daemonize --verbose notice: Starting Puppet client version 2.7.1 info: Caching catalog for svr051-4170 info: Applying configuration version '1311563901' err: /Stage[main]/Bashrc/Exec[root_bashrc]/returns: change from notrun to 0 failed: Could not find command 'source' notice: Finished catalog run in 2.28 seconds notice: Caught INT; calling stop 

有没有任何解决方法来做到这一点?

在Puppet中.bashrc一个新的.bashrc是没有意义的,因为它会在一个子shell中运行,并且这些变化不会传播到你当前的shell(也就是我猜想你正在尝试的)。 你不能做我想做的事情。

从技术上讲,你可以使用:

 exec { "root_bashrc": command => "bash -c 'source /root/.bashrc'", subscribe => File["/root/.bashrc"], refreshonly => true, } 

但是,正如@womble 已经指出的那样 ,采购.bashrc没有意义, 它只会影响在该命令中运行的bash shell,而不会影响当前正在运行的bash shell。

每次在任何当前正在运行的交互式shell中显示提示时,您可以设置PROMPT_COMMAND="source /root/.bashrc"来重新运行.bashrc,但似乎有点资源密集。 我从来没有尝试过,但我认为这将工作。

你也可以经常用true &&或者使用provider => shell命令来命令你的命令。

看到这个和这个额外的讨论。

这应该是:

 file { "/root/.bashrc": ensure => present, owner => root, group => root, mode => 0644, source => "puppet:///bashrc/root/.bashrc" } exec { "root_bashrc": command => "source /root/.bashrc", provider => shell, subscribe => File["/root/.bashrc"], }