在Puppet中用ERB模板来自动配置Apache虚拟主机
模板文件是在puppet模块下面templates目录中以”.erb”结尾的文件,puppet模板主要用于文件,例如各种服务的配置文件,相同的服务,不同的配置就可以考虑使用模板文件,例如Nginx和Apache的虚拟主机配置就可以考虑采用ERB模板。apache模块生成这里的过程略过,这里只贴上重要文档的内容,/etc/puppet/modules/apache/manifests/ini.pp文件内容如下所示:
class apache{
package{"httpd":
ensure =>present,
}
service{"httpd":
ensure =>running,
require =>Package["httpd"],
}
}
define apache::vhost ( $sitedomain, $port ) {
file { "/etc/httpd/conf.d/httpd_vhost_${sitedomain}.conf":
#path => '/etc/httpd/conf/httpd_vhost.conf',
content => template("apache/httpd.conf.erb"),
require => Package["httpd"],
}
}
/etc/puppet/modules/apache/templates中的httpd.conf.erb模板文件内容如下所示:
<VirtualHost *:80>
ServerName <%= sitedomain %>
DocumentRoot /var/www/html/<%= sitedomain %>
ErrorLog logs/<%= sitedomain %>_error.log
CustomLog logs/<%= sitedomain %>_access.log common
</VirtualHost>
注:很多资料和文档都是复制/etc/httpd/conf/httpd.conf文件来作为httpd.conf.erb模板,我觉得这种做法还是欠缺考虑的,一般来说,每台Aapche主机上面至少有个基于域名的虚拟主机,有的更多,十几个也很常见,所以我们才需要用独立的虚拟主机文件来管理虚拟主机并自动的载入,这也是我们利用erb模板文件将虚拟主机的文件定义路径放在/etc/httpd/conf.d目录下的原因。
在一辆拥挤的公车上,一位女郎忽然叫了起来:别挤啦!别挤啦!把人家的奶都挤出来啦!(她拿着酸奶呢)。 走,MM,咱们化蝶去…… 写的真的很不错 如果回帖是一种美德,那我早就成为圣人了! 我抢、我抢、我抢沙发~ 丑,但是丑的特别,也就是特别的丑!
页:
[1]