Puppet managed Httpd in Redhat or CentOS
2011-01-01
**再次声明 用puppet的管理服务器的童鞋们。 部署puppet并不困难。 如何用好puppet是对puppet语法掌握程度。 ** 下面贴一个用puppet管理 httpd的实例,希望对puppet初学者有帮助
class httpd
{
define init ($user = "apache", $group = "apache", $file="/etc/httpd/conf/httpd.conf")
{
$packagelist = ["httpd","httpd-tools"]
package {
$packagelist:
ensure => present,
}
group { $group: ensure => present, require => Package["httpd"]}
user { $user: ensure => present, home => "/var/www",
managehome => false, membership => minimum, groups => ["$group"],
shell => "/sbin/nologin", require => Package["httpd"],
}
file {
"httpd.conf":
name => $file,
owner => root, group => root, mode => 644,
checksum => md5,
content => template("httpd/httpd.conf.erb"),
notify => Exec["reload"];
"/etc/httpd/conf.d":
ensure => directory, checksum => mtime,
mode => 0644, owner => root, group => root,
notify => Exec["reload"],
ignore => [".svn",".ignore"],
require => Package["httpd"];
}
service {
"httpd":
ensure => running,
enable => true,
hasrestart => true,
hasstatus => true,
start => "/etc/init.d/httpd start",
require => Package["httpd"],
}
exec { "reload":
command => "/etc/init.d/httpd reload",
onlyif => "/usr/sbin/apachectl -t",
require => Service["httpd"],
refreshonly => true,
}
}
define vhost ( $admin = "webmaster", $aliases = '', $docroot, $ensure = 'present', $domain = "")
{
file { "/etc/httpd/conf.d/$name.conf":
mode => "644",
ensure => $ensure,
require => Package["httpd"],
notify => Exec["reload-apache2"],
content => template("httpd/vhost.conf.erb"),
}
}
}