smoeding / puppet-sendmail

Manage the Sendmail MTA using Puppet
BSD 2-Clause "Simplified" License
1 stars 11 forks source link

Use of sendmail::mc::daemon_options class always triggers service refresh #5

Closed cornben closed 8 years ago

cornben commented 8 years ago

First off, thank you for your work on this project! I've encountered an issue while using sendmail::mc::daemon_options, where every time the puppet agent runs, a refresh of the service is triggered. This is due to the DAEMON_OPTIONS line being written to sendmail.mc always being ordered differently. Any ideas for a work-around?

Example changes to sendmail.mc after two puppet agent runs:

< DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Addr=127.0.0.1, Port=smtp')dnl
> DAEMON_OPTIONS(`Port=smtp, Family=inet, Name=MTA-v4, Addr=127.0.0.1')dnl

Versions: stm/sendmail - 0.4.0 concat - 2.1.0 stdlib - 4.11.0 ruby - 1.8.7 puppet - 3.8.6

This is the full class that I'm using, should it be helpful:

class xx_mail::sendmail-client {

class { 'sendmail':
  smart_host => 'mail-lab01.domain.com',
  enable_ipv4_daemon => false,
  enable_ipv6_daemon => false,
}

sendmail::mc::masquerade_as { 'domain.com':
  masquerade_envelope => true,
}

sendmail::mc::daemon_options { 'MTA-v4':
  addr   => '127.0.0.1',
  family => 'inet',
  port   => 'smtp',
}

}
smoeding commented 8 years ago

Thanks for reporting this issue.

I haven't seen this problem in my tests/setup but I have an idea where this might be coming from. I will investigate this further.

Could you please add the Versions of Ruby and Puppet you are using?

cornben commented 8 years ago

I've updated my original post to include the Ruby and Puppet versions. Thank you again for your work on this module!

smoeding commented 8 years ago

Ruby 1.8 is probably the culprit here. The code uses a hash to store all the parameter values. Then the hash is iterated to create the items for the template. Iterating a hash in Ruby 1.9 or later uses the order of insertion. In Ruby 1.8 the order of items is undefined. This most likely causes the issue.

I already have an idea how to fix this.

smoeding commented 8 years ago

Could you maybe help by testing the fix in your environment?

Download the modified damon_options.pp file and use it to replace the file manifests/mc/daemon_options.pp in the sendmail module. This should prevent rewriting the parameters with each run.

cornben commented 8 years ago

Tested in my environment. The parameters are no longer changing order on each run, so unnecessary service refresh events are no longer happening. However, it does look like there are empty variables written to the configuration file, as indicated by the extra commas. Note: This did not prevent the sendmail service from starting or break any basic functionality.

DAEMON_OPTIONS(`Name=MTA-v4, Family=inet, Addr=127.0.0.1, Port=smtp, , , , , , , , , , ')dnl

smoeding commented 8 years ago

I have updated the file linked in my last comment again. This should not only fix the parameter rewrite but also prevent the generation of those unnecessary commas in the call.

I appreciate another test in your environment.

cornben commented 8 years ago

I tested the updated daemon_options.pp and verified that the extra commas are no longer present.

DAEMON_OPTIONS(`Name=MTA-v4, Family=inet, Addr=127.0.0.1, Port=smtp')dnl

Thank you!

smoeding commented 8 years ago

Cool. Thanks! I will include this fix in version 0.5.0 of the module.