创建postfix模块对应的文件和目录
- [root@master ~]# mkdir -p /etc/puppet/modules/postfix/{files,manifests,templates}
- [root@master ~]# touch /etc/puppet/modules/postfix/manifests/{init.pp,install.pp,config.pp,service.pp}
- [root@master ~]# touch /etc/puppet/modules/postfix/files/master.cf
- [root@master ~]# touch /etc/puppet/modules/postfix/templates/main.cf.erb
配置install.pp
- [root@master ~]# vim /etc/puppet/modules/postfix/manifests/install.pp
- class postfix::install {
- package{["postfix","mailx"]:
- ensure=>present,
- }
- }
配置config.pp
- [root@master ~]# vim /etc/puppet/modules/postfix/manifests/config.pp
- class postfix::config{
- File{
- owner=>"postfix",
- group=>"postfix",
- mode=>0644,
- }
- file{"/etc/postfix/master.cf":
- ensure=>present,
- source=>"puppet://$puppetserver/modules/postfix/master.cf",
- require=>Class["postfix::install"],
- notify=>Class["postfix::service"],
- }
- file{"/etc/postfix/main.cf":
- ensure=>present,
- content=>template("postfix/main.cf.erb"),
- require=>Class["postfix::install"],
- notify=>Class["postfix::service"],
- }
- }
配置postfix模板文件
- [root@master ~]# vim /etc/puppet/modules/postfix/templates/main.cf.erb
- soft_bounce = no
- command_directory = /usr/sbin
- daemon_directory = /usr/libexec/postfix
- mail_owner = postfix
- myhostname = <%= hostname %>
- mydomain = <%= domain %>
- myorigin = $mydomain
- mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
- unknown_local_recipient_reject_code = 550
- relay_domains = $mydestination
- smtpd_reject_unlisted_recipient = yes
- unverified_recipient_reject_code = 550
- smtpd_banner = $myhostname ESMTP
- setgid_group = postdrop
配置service.pp文件
- [root@master ~]# vim /etc/puppet/modules/postfix/manifests/service.pp
- class postfix::service{
- service {"postfix":
- ensure=>running,
- hasstatus=>true,
- hasrestart=>true,
- enable=>true,
- require=>Class["postfix::config"],
- }
- }
最后编辑init.pp
- [root@master ~]# vim /etc/puppet/modules/postfix/manifests/init.pp
- class postfix{
- include postfix::install,postfix::config,postfix::service
- }
Postfix的模板配置完成,接下来需要将该模板应用到节点
- [root@master ~]# vim /etc/puppet/manifests/nodes.pp
- class base {
- include sudo,ssh
- }
- node 'client1.centos' {
- include base
- include postfix
- }
到节点上检查模块的配置是否生效
- [root@client1 ~]# puppetd --server master.puppet --test
- info: FileBucket adding {md5}49b648101b0e361231a977aa89e0dd60
- info: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]: Filebucketed /etc/postfix/main.cf to puppet with sum 49b648101b0e361231a977aa89e0dd60
- notice: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]/content: content changed '{md5}49b648101b0e361231a977aa89e0dd60' to '{md5}e952770fbd49dcac604e41b689a9f871'
- notice: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]/owner: owner changed 'root' to 'postfix'
- notice: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]/group: group changed 'root' to 'postfix'
- info: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]: Scheduling refresh of Service[postfix]
- info: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]: Scheduling refresh of Service[postfix]
- info: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]: Scheduling refresh of Service[postfix]
- notice: /Stage[main]/Postfix::Service/Service[postfix]: Triggered 'refresh' from 6 events
- notice: Finished catalog run in 2.70 seconds
查看postfix服务状态
- [root@client1 ~]# service postfix status
- master (pid 30794) 正在运行...
本文转自 waydee 51CTO博客,原文链接:http://blog.51cto.com/waydee/847137,如需转载请自行联系原作者