Puppet--自动化管理postfix

Puppet自动化管理postfix

创建postfix模块对应的文件和目录

  
  
  
  
  1. [root@master ~]# mkdir -p /etc/puppet/modules/postfix/{files,manifests,templates} 
  2.  
  3. [root@master ~]# touch /etc/puppet/modules/postfix/manifests/{init.pp,install.pp,config.pp,service.pp} 
  4.  
  5. [root@master ~]# touch /etc/puppet/modules/postfix/files/master.cf 
  6.  
  7. [root@master ~]# touch /etc/puppet/modules/postfix/templates/main.cf.erb 

       配置install.pp

  
  
  
  
  1. [root@master ~]# vim /etc/puppet/modules/postfix/manifests/install.pp 
  2.  
  3.   
  4.  
  5.    class postfix::install { 
  6.  
  7.        package{["postfix","mailx"]: 
  8.  
  9.            ensure=>present, 
  10.  
  11.        } 
  12.  
  13.    } 

配置config.pp

  
  
  
  
  1. [root@master ~]# vim /etc/puppet/modules/postfix/manifests/config.pp 
  2.  
  3.    class postfix::config{ 
  4.  
  5.        File{ 
  6.  
  7.            owner=>"postfix"
  8.  
  9.            group=>"postfix"
  10.  
  11.            mode=>0644
  12.  
  13.        }   
  14.  
  15.        file{"/etc/postfix/master.cf"
  16.  
  17.            ensure=>present, 
  18.  
  19.            source=>"puppet://$puppetserver/modules/postfix/master.cf"
  20.  
  21.           require=>Class["postfix::install"], 
  22.  
  23.           notify=>Class["postfix::service"], 
  24.  
  25.       }  
  26.  
  27.       file{"/etc/postfix/main.cf"
  28.  
  29.           ensure=>present, 
  30.  
  31.           content=>template("postfix/main.cf.erb"), 
  32.  
  33.           require=>Class["postfix::install"], 
  34.  
  35.           notify=>Class["postfix::service"], 
  36.  
  37.       } 
  38.  
  39.   } 

  配置postfix模板文件

  
  
  
  
  1. [root@master ~]# vim /etc/puppet/modules/postfix/templates/main.cf.erb   
  2.  
  3.    soft_bounce = no 
  4.  
  5.    command_directory = /usr/sbin 
  6.  
  7.    daemon_directory = /usr/libexec/postfix 
  8.  
  9.    mail_owner = postfix 
  10.  
  11.    myhostname = <%= hostname %> 
  12.  
  13.    mydomain = <%= domain %> 
  14.  
  15.    myorigin = $mydomain 
  16.  
  17.    mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain 
  18.  
  19.   unknown_local_recipient_reject_code = 550 
  20.  
  21.   relay_domains = $mydestination 
  22.  
  23.   smtpd_reject_unlisted_recipient = yes 
  24.  
  25.   unverified_recipient_reject_code = 550 
  26.  
  27.   smtpd_banner = $myhostname ESMTP 
  28.  
  29.  setgid_group = postdrop 

   配置service.pp文件

  
  
  
  
  1. [root@master ~]# vim /etc/puppet/modules/postfix/manifests/service.pp 
  2.  
  3.    class postfix::service{ 
  4.  
  5.        service {"postfix"
  6.  
  7.            ensure=>running, 
  8.  
  9.            hasstatus=>true, 
  10.  
  11.            hasrestart=>true, 
  12.  
  13.            enable=>true, 
  14.  
  15.            require=>Class["postfix::config"], 
  16.  
  17.        } 
  18.  
  19.    } 

   最后编辑init.pp

  
  
  
  
  1. [root@master ~]# vim /etc/puppet/modules/postfix/manifests/init.pp   
  2.  
  3.    class postfix{ 
  4.  
  5.        include postfix::install,postfix::config,postfix::service 
  6.  
  7.    } 

   Postfix的模板配置完成,接下来需要将该模板应用到节点

  
  
  
  
  1. [root@master ~]# vim /etc/puppet/manifests/nodes.pp  
  2.  
  3.   class base { 
  4.  
  5.        include sudo,ssh 
  6.  
  7.    } 
  8.  
  9.    
  10.  
  11.    node 'client1.centos' { 
  12.  
  13.        include base 
  14.  
  15.        include postfix 
  16.  
  17.    } 

   到节点上检查模块的配置是否生效

  
  
  
  
  1. [root@client1 ~]# puppetd   --server  master.puppet --test 
  2.  
  3. info: FileBucket adding {md5}49b648101b0e361231a977aa89e0dd60 
  4.  
  5. info: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]: Filebucketed /etc/postfix/main.cf to puppet with sum 49b648101b0e361231a977aa89e0dd60 
  6.  
  7. notice: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]/content: content changed '{md5}49b648101b0e361231a977aa89e0dd60' to '{md5}e952770fbd49dcac604e41b689a9f871' 
  8.  
  9. notice: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]/owner: owner changed 'root' to 'postfix' 
  10.  
  11. notice: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]/group: group changed 'root' to 'postfix' 
  12.  
  13. info: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]: Scheduling refresh of Service[postfix] 
  14.  
  15. info: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]: Scheduling refresh of Service[postfix] 
  16.  
  17. info: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]: Scheduling refresh of Service[postfix] 
  18.  
  19. notice: /Stage[main]/Postfix::Service/Service[postfix]: Triggered 'refresh' from 6 events 
  20.  
  21. notice: Finished catalog run in 2.70 seconds 

  查看postfix服务状态

  
  
  
  
  1. [root@client1 ~]# service postfix status 
  2.  
  3. master (pid  30794) 正在运行... 

 

你可能感兴趣的:(linux)