我对 Puppet 和 Solaris 还不太熟悉,在使用 Puppet 在 Solaris 10 VM 上安装软件包时遇到了问题。作为测试的一部分,我想看看是否可以在只有 Java 5 update 24 的 Solaris 10 VM 上安装 Java 6 update 43。下面显示了我遇到的问题和我的问题。
环境
Solaris 版本: SunOS 5.10 Generic_142910-17 i386
傀儡版本: 3.1.1
问题
似乎如果某个软件包尚未在 Solaris 上安装,Puppet 就不会安装它。Puppet 会抛出以下消息:
Error: /Stage[main]/Java::Jdk_solaris/Package[SUNWj6cfg]: Could not evaluate: Unable to get information about package SUNWj6cfg because of: No message
发生了什么
当 puppet 尝试在 Solaris 机器上安装软件包时,它会在尝试安装该软件包之前运行以下命令(我在 puppet 运行期间打开 --debug 标志时看到了此命令):
pkginfo -l [whatever the package name is]
来自 puppet agent --test --debug 输出的示例:
Debug: Executing '/usr/bin/pkginfo -l'
Debug: Executing '/usr/bin/pkginfo -l SUNWj6cfg'
Error: /Stage[main]/Java::Jdk_solaris/Package[SUNWj6cfg]: Could not evaluate: Unable to get information about package SUNWj6cfg because of: No message
当 pkginfo 查找不存在的包名称(即未安装或名称错误等)时,它会返回错误,如下所示:
vagrant@puppet-master:[/etc/puppet/manifests] $ pkginfo -l SUNWj6cfg
ERROR: information for "SUNWj6cfg" was not found
好的,这解释了为什么 Puppet 会出现错误。这很合理。这让我想到了以下问题:
我的问题
为什么 Puppet 在尝试安装软件包之前要检查该软件包是否存在?有没有办法绕过此检查,以便 Puppet 安装“全新”软件包?
根据我所看到的情况,Puppet 似乎只能安装服务器上已经存在的软件包(即 pkginfo 可以找到它们)。这似乎不是理想的行为。我想有很多情况下我希望让 Puppet 安装 Solaris 服务器上以前从未存在过的软件包。根据我的经验,如果软件包已经存在,pkgadd 将用新软件包覆盖该软件包。
例如,如果我想在安装了 Java 6 update 21 的 Solaris 10 机器上安装 Java 6 update 43,pkgadd 会很乐意覆盖现有的 SUNWj6* 软件包。此外,如果 SUNWj6* 软件包根本不存在(即我通过 pkgrm 完全删除了 Java 6),pkgadd 也会很乐意安装它们。
我想了解为什么 Puppet 会这样表现。我是不是完全忽略了什么?我说得有道理吗?
清单
为了完整性(我想也是为了字数),这里是我的傀儡清单(无论如何,都是相关的):
/etc/puppet/modules/java/manifests/init.pp:
class java ($distribution,
$version,
$update
) {
$class_prefix = $distribution ? {
jdk => 'java::jdk',
jre => 'java::jre',
}
case $::operatingsystem {
'RedHat', 'CentOS': {
class { "${java::class_prefix}_redhat":
version => "${java::version}"
}
->
Class["java"]
}
'Solaris': {
class { "${java::class_prefix}_solaris":
version => "${java::version}",
update => "${java::update}",
}
->
Class["java"]
}
}
}
/etc/puppet/modules/java/manifests/jdk_solaris.pp:
class java::jdk_solaris ($version,
$update
) {
$working_dir = "/opt/tmp"
$zip_file_name_32 = "jdk-${version}u${update}-solaris-i586.tar.Z"
$zip_file_name_64 = "jdk-${version}u${update}-solaris-x64.tar.Z"
$admin_file = "java_admin"
$java_packages = [ "SUNWj6cfg",
"SUNWj6dev",
"SUNWj6jmp",
"SUNWj6man",
"SUNWj6rt" ]
file {
"${java::jdk_solaris::working_dir}/${java::jdk_solaris::zip_file_name_32}":
ensure => file,
source => "puppet:///modules/java/${java::jdk_solaris::zip_file_name_32}";
"${java::jdk_solaris::working_dir}/${java::jdk_solaris::admin_file}":
ensure => file,
source => "puppet:///modules/java/${java::jdk_solaris::admin_file}";
"${java::jdk_solaris::working_dir}/SUNWj6cfg/install/checkinstall":
ensure => file,
source => "puppet:///modules/java/SUNWj6cfg/checkinstall",
require => Exec["zcat_32"];
"${java::jdk_solaris::working_dir}/SUNWj6dev/install/checkinstall":
ensure => file,
source => "puppet:///modules/java/SUNWj6dev/checkinstall",
require => Exec["zcat_32"];
"${java::jdk_solaris::working_dir}/SUNWj6jmp/install/checkinstall":
ensure => file,
source => "puppet:///modules/java/SUNWj6jmp/checkinstall",
require => Exec["zcat_32"];
"${java::jdk_solaris::working_dir}/SUNWj6man/install/checkinstall":
ensure => file,
source => "puppet:///modules/java/SUNWj6man/checkinstall",
require => Exec["zcat_32"];
"${java::jdk_solaris::working_dir}/SUNWj6rt/install/checkinstall":
ensure => file,
source => "puppet:///modules/java/SUNWj6rt/checkinstall",
require => Exec["zcat_32"];
}
file { "${java::jdk_solaris::working_dir}":
ensure => directory,
}
exec { "zcat_32":
cwd => "${java::jdk_solaris::working_dir}",
command => "zcat ${java::jdk_solaris::zip_file_name_32} | tar -xf -",
creates => [
"${java::jdk_solaris::working_dir}/SUNWj6cfg",
"${java::jdk_solaris::working_dir}/SUNWj6dev",
"${java::jdk_solaris::working_dir}/SUNWj6jmp",
"${java::jdk_solaris::working_dir}/SUNWj6man",
"${java::jdk_solaris::working_dir}/SUNWj6rt"
],
path => "/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin:/usr/local/sbin:/opt/csw/bin:/opt/csw/sbin",
require => [
File["${java::jdk_solaris::working_dir}"],
File["${java::jdk_solaris::working_dir}/${java::jdk_solaris::zip_file_name_32}"],
],
}
#------------------------------------------------------------------------------------------------------------------------
# INSTALL JDK
#------------------------------------------------------------------------------------------------------------------------
package { $java_packages:
ensure => installed,
source => "${java::jdk_solaris::working_dir}",
adminfile => "${java::jdk_solaris::working_dir}/${java::jdk_solaris::admin_file}",
require => [
Exec["zcat_32"],
File[
"${java::jdk_solaris::working_dir}/SUNWj6cfg/install/checkinstall",
"${java::jdk_solaris::working_dir}/SUNWj6dev/install/checkinstall",
"${java::jdk_solaris::working_dir}/SUNWj6jmp/install/checkinstall",
"${java::jdk_solaris::working_dir}/SUNWj6man/install/checkinstall",
"${java::jdk_solaris::working_dir}/SUNWj6rt/install/checkinstall"
] # end file array
], # end require array
}
#------------------------------------------------------------------------------------------------------------------------
# CLEAN UP AFTER INSTALLATION
#------------------------------------------------------------------------------------------------------------------------
exec { "jdk_solaris_cleanup":
cwd => "${java::jdk_solaris::working_dir}",
command => "rm -r ${java::jdk_solaris::admin_file} SUNWj* THIRDPARTYLICENSEREADME.txt COPYRIGHT LICENSE README.html ${java::jdk_solaris::zip_file_name_32}",
path => "/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin:/usr/local/sbin:/opt/csw/bin:/opt/csw/sbin",
require => Package[$java_packages],
}
}