Run puppet exec command only if output file has changed

puppet

I am using an exec command to run a shell script which modifies certain configuration files of other packages. The exec command is triggered whenever input parameters such as ip addresses, ports or url change, or when the shell script itself has been changed.

I have to use a shell script because the configuration files of the software package differ slightly between releases. I think it is easier to update the configuration file per sed script instead of providing different puppet templates for each particular release.

But this configuration does not detect when any of the configuration files have been modified outside of puppet. Puppet does not know about the files which are been modified by the shell script.

What I am looking for is a way to make the exec command dependend on the checksums of arbitrary other files:

exec { "my_command.sh":
  only_if_file_has_changed => [ 
    "/etc/mysoftware/config.xml", 
    "/etc/othersoftware/defaults", 
  ]
}

Is this possible? Please advise.

Best Answer

It would work like this:

exec { 'my_command.sh':
  command   => '/bin/my_command.sh',
  subscribe => [ 
    File['/etc/mysoftware/config.xml'], 
    File['/etc/othersoftware/defaults'], 
  ],
  refreshonly => true,
}

The obvious constraint here is, that the files /etc/mysoftware/config.xml and /etc/othersoftware/defaults must be changed via Puppet too.
If they are changed by something else (external to Puppet), see Felix' answer.
You can also subscribe to Package['xxx'] or any other more fitting dependency of course.