从Puppet文件存储执行安装程序

从Puppet文件存储执行安装程序,puppet,Puppet,我已经存储了Linux产品的安装程序,需要用应答文件安装。到目前为止,我有以下代码: class installpackage { file { 'MyInstallerFile': path => '/tmp/MyInstallerFile', ensure => present, owner => 'root', group => 'root',

我已经存储了Linux产品的安装程序,需要用应答文件安装。到目前为止,我有以下代码:

class installpackage {
    file { 'MyInstallerFile':
            path => '/tmp/MyInstallerFile',
            ensure => present,
            owner => 'root',
            group => 'root',
            mode => '777',
            source => 'puppet:///extra_files/MyInstallerFile',
    }
    file { 'answer_file':
            path => '/tmp/answer_file',
            ensure => present,
            owner => 'root',
            group => 'root',
            mode => '777',
            source => 'puppet:///extra_file/answer_file',
    }

   exec { "install":
cwd => '/tmp',
             command => '/tmp/MyInstallerFile --answer /tmp/answer_file',
            logoutput => true,
           require => File['MyInstallerFile', 'answer_file'],
   }
}
但是,当我尝试运行它时,会出现一系列错误:

Info: Retrieving plugin
Info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb
Info: Loading facts in /var/lib/puppet/lib/facter/facter_dot_d.rb
Info: Loading facts in /var/lib/puppet/lib/facter/pe_version.rb
Info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb
Info: Caching catalog for puppetagent.example.com
Info: Applying configuration version '1370899438'
Notice: /Stage[main]/Installpackage/Exec[install]/returns: couldn't find HOME environment variable to expand path
Notice: /Stage[main]/Installpackage/Exec[install]/returns:     while executing
Notice: /Stage[main]/Installpackage/Exec[install]/returns: "file normalize ~"
Notice: /Stage[main]/Installpackage/Exec[install]/returns:     (procedure "::InstallJammer::HomeDir" line 2)
Notice: /Stage[main]/Installpackage/Exec[install]/returns:     invoked from within
Notice: /Stage[main]/Installpackage/Exec[install]/returns: "::InstallJammer::HomeDir"
Notice: /Stage[main]/Installpackage/Exec[install]/returns:     (procedure "::InstallJammer::CommonInit" line 183)
Notice: /Stage[main]/Installpackage/Exec[install]/returns:     invoked from within
Notice: /Stage[main]/Installpackage/Exec[install]/returns: "::InstallJammer::CommonInit"
Notice: /Stage[main]/Installpackage/Exec[install]/returns:     (procedure "::InstallJammer::InitInstall" line 19)
Notice: /Stage[main]/Installpackage/Exec[install]/returns:     invoked from within
Notice: /Stage[main]/Installpackage/Exec[install]/returns: "::InstallJammer::InitInstall"
Notice: /Stage[main]/Installpackage/Exec[install]/returns:     (file "/installkitvfs/main.tcl" line 71313)
Error: /tmp/MyInstallerFile --answer /tmp/answer_file returned 1 instead of one of [0]
Error: /Stage[main]/Installpackage/Exec[install]/returns: change from notrun to 0 failed: MyInstallerFile --answer /tmp/answer_file returned 1 instead of one of [0]
Notice: Finished catalog run in 5.31 seconds

我做错了怎么办?

默认情况下,Puppet以root用户身份运行

我认为您的
$HOME
环境变量不是由root设置的


作为测试,您可以
su
root
,并
echo$HOME
以确定是否存在这种情况。

尝试在命令行上显式设置$HOME变量:

exec { "install":
    ...
    command => 'HOME=/path/to/somewhere /tmp/MyInstallerFile --answer /tmp/answer_file',
    ...
}

问题似乎在于机器的成像方式,解决Exec问题的一个解决方案是在命令前面添加“sudo”。当然,这仅限于Linux环境


另一个解决方案,也许是一个更好的主意,就是创建您所需要的安装程序的Debian包。这简化了管理,并推出了新版本,而不是执行卸载例行程序。

您必须这样做

   $path => $::path,   
   $cwd  => '/location/of/your/installer'
    $path => [$::path,'/additional/path/to/other/directory'],
    $cwd  => '/location/of/your/installer',
$::path是对默认环境变量的引用。您可以像这样在数组中设置其他路径

   $path => $::path,   
   $cwd  => '/location/of/your/installer'
    $path => [$::path,'/additional/path/to/other/directory'],
    $cwd  => '/location/of/your/installer',

我尝试将$HOME设置为/root。所以我不知道为什么Puppet没有选择$HOME变量。有没有办法手动指定它?