我需要编写一个 list 作为将安装的install-apache.pp
apache2
软件包(如果是基于 Debian 的系统)或httpd
软件包(如果是基于 RedHat 的系统)
下面是代码;这在 CentOS 中有效,但在 Ubuntu 中无效。
case $facts['os']['name'] {
'Debian': {
package { 'apache2':
ensure => installed,
}
service { 'apache2':
ensure => running,
}
}
'RedHat': {
package { 'httpd' :
ensure => installed,
}
service { 'httpd':
ensure => running,
}
}
}
所以我做了一些更改,如下所示,但不确定为什么它不起作用。
case $operatingsystem {
'Debian': {
package { 'apache2':
ensure => installed,
} ->
service { 'apache2':
ensure => running,
enable => true,
}
}
'RedHat': {
package { 'httpd' :
ensure => installed,
} ->
service { 'httpd':
ensure => running,
enable => true,
}
}
}
用于执行的命令:
puppet apply install-apache.pp --logdest /root/output.log
最佳答案
这里的问题是,您正在使用事实 $facts['os']['name']
,它被分配了发行版的特定操作系统,而不是该操作系统的系列分配。这一事实将在 Ubuntu 上分配给 Ubuntu
,而不是 Debian
。该事实需要修复为 $facts['os']['family']
,它将在 Ubuntu 上分配给 Debian
。
您还可以使用selectors除了修复之外,还要进一步改进这一点。还建议在该 list 中的包
上构建服务
的依赖关系,以确保正确的排序。提神醒脑也会有帮助。
考虑到这些修复和改进,您的最终 list 将如下所示:
$web_service = $facts['os']['family'] ? {
'RedHat' => 'httpd',
'Debian' => 'apache2',
default => fail('Unsupported operating system.'),
}
package { $web_service:
ensure => installed,
}
~> service { $web_service:
ensure => running,
enable => true,
}
关于puppet - 安装和运行 apache2 或 httpd 的平台独立 list ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53253135/