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