Ask Your Question

Multiple edits on the same config file, restart service if any of the edits is successful in updating the file.

asked 2018-11-28 22:50:39 -0600

jongm0816 gravatar image

I need to do multiple edits to the file /etc/postfix/ The condition I want is 'if at least of of the edits is able to change the file, restart the postfix service.

The code I have below looks like will only restart the service if 'myhostname' entry is added.

Any suggestion please ?


if $mtafix == 'True' {

   $postfix_conf = '/etc/postfix/'
   $myhostname = $::fqdn
   $mydomain = $::domain
   $mynetworks = ','
   $mail_spool_directory = '/var/spool/mail'

   file { '/var/spool/mail':
       status => 'directory',
       owner  => 'postfix',
       group  => 'mail',
       mode   => '0775',

   file { '/var/mail':
       ensure => 'link',
       target => '/var/spool/mail',

   file { $postfix_conf :
       ensure => 'present',
       notify => Service['postfix'],

   file_line { "Add myhostname entry":
       path    => $postfix_conf,
       line    => 'myhostname = $myhostname',

   file_line { "Add mydomain entry":
       path    => $postfix_conf,
       line    => 'mydomain = $mydomain',

   file_line { "Comment out inet_interfaces":
       path    => $postfix_conf,
       match   => '^inet_interfaces.*$',
       line    => '# &',
       replace => 'True',

   file_line { "Add mynetworks entry":
       path    => $postfix_conf,
       line    => 'mynetworks = $mynetworks',

   file_line { "Add mail_spool_directory entry":
       path    => $postfix_conf,
       line    => 'mail_spool_directory = $mail_spool_directory',



edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-11-29 08:31:30 -0600

DarylW gravatar image

All that you have to do is add notify => Service['postfix'] in every single resource that would modify the config file for that service.

Remember, you are building a graph of dependencies, not running resources in order like a script. Any of the resources that trigger a 'change' will then trigger a downstream notification to the postfix Service, so that puppet will know to restart it. It will be restarted at least once, but it could potentially be restarted multiple times.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-11-28 22:50:39 -0600

Seen: 67 times

Last updated: Nov 29