How to prevent Puppet’s file_line resource from always triggering an event

puppet

I use the file_line resource from puppetlabs/stdlib to add lines to a file with Puppet. I would like to trigger a service reload when the file_line actually changes the file. Here is what I've tried:

First try

service { 'test-service':
  ensure => 'running',
  enable => true
}
file_line { 'test':
  path   => '/file'
  line   => 'test parameter'
  notify => Service['test-service']
}

Second try

service { 'test-service':
  ensure => 'running',
  enable => true
}
file_line { 'test':
  path   => '/file'
  line   => 'test parameter'
}~>Service['test-service']

Or similar with File_line['test']~>Service['test-service'] on the header.

Third try

file { '/file':
  path   => '/file',
  notify => Service['test-service']
}
service { 'test-service':
  ensure => 'running',
  enable => true
}
file_line { 'test':
  path   => '/file'
  line   => 'test parameter'
}

Fourth try

service { 'test-service':
  ensure    => 'running',
  enable    => true,
  subscribe => File_line['test']
}
file_line { 'test':
  path   => '/file'
  line   => 'test parameter'
}

In each case, file_line always trigger the service reload, even when nothing has changed in the file. It seems file_line is first removing all lines, and then re-adding them. Playing with the match option didn't change this behaviour.

How to make it trigger the service reload only if the file has changed?

Edit: here is the output of puppet agent --test:

Notice: /Stage[main]/Profile::testprofile/File_line[test]/ensure: created
Info: /Stage[main]/Profile::testprofile/File_line[test]: Scheduling refresh of Service[test-service]
Notice: /Stage[main]/Profile::testprofile/Service[test-service]: Triggered 'refresh' from 1 events

Best Answer

OK I figured this had to do with the content I was writing to the file! If you try to add carriage returns using file_line, it will always trigger a refresh:

file_line { 'test':
  path => '/file',
  line => 'first param\nsecond param'
}

If I remove the \n, the problem disappear. So better call file_line twice than once with carriage returns.