0
votes

I have two Puppet Resource Types, a File and an Exec:

file { 'folder_a':
  source  => 'puppet:///modules/folder_a',
  ensure  => 'directory',
  recurse => true,
  path    => 'C:/folder_a',
  source_permissions => ignore,
  notify  => Exec['install.bat'],
}

exec { 'test_cmd':
  path      => $::path,
  command   => 'cmd.exe /c C:/test.cmd',
  provider  => windows,
  subscribe => File['folder_a'],
  logoutput => true,
}

If the File Resource doesn't apply, I don't want the Exec Resource to run either. But if the source files are updated, then the Exec should run.

Is this possible?

1

1 Answers

1
votes

Yes. As noted in the docs for the Exec type, there is the refreshonly attribute:

refreshonly

The command should only be run as a refresh mechanism for when a dependent object is changed.

It sounds like this is exactly what you need:

exec { 'test_cmd':
  path      => $::path,
  command   => 'cmd.exe /c C:/test.cmd',
  provider  => windows,
  subscribe => File['folder_a'],
  logoutput => true,
  refreshonly => true, # Add this line.
} 

Keep in mind that some strongly recommend refreshonly to be used as a last resort only.