Search code examples
macospuppet

Debugging puppet error : Could not find dependency


Background

Puppet Newbie, trying to maintain some old puppet version on a box. The aim is to unload an old program using it's old plist file and start new one.

Problem

I have following code in .pp file

$old_launch_agent_path = "${home}/Library/LaunchAgents/com.company.program.plist"

exec {
  'stop-old-program':
  command => "/bin/launchctl unload ${old_launch_agent_path}",
  refreshonly => true,
  subscribe => [ File[$old_launch_agent_path] ];
}

Puppet rejects this with:

Error: Could not find dependency File[/Users/executer/Library/LaunchAgents/com.company.program.plist] for Exec[stop-old-program] at /private/tmp/mobile-puppet-manifests/puppet-manifests-test/modules/program/manifests/init.pp:51

The changes are on a git branch and are being applied sudo puppet-apply -d -f -b mac-upgrade

ls -l /Users/executer/Library/LaunchAgents/com.company.program.plist`
-rw-r--r--  1 executer  staff  999 May 19 14:36 /Users/executer/Library/LaunchAgents/com.company.program.plist

Solution

  • I infer that you have specified the subscribe attribute of Exec with the idea that it will cause the Exec to run in the event that the designated file has changed (since the last puppet apply, I guess). That exhibits a relatively common misunderstanding of Puppet's signaling model.

    Puppet does not track what files or other resources looked like on or after previous runs. It knows at most what they looked like at some point during the current run, whether that is what they are supposed to look like, and whether they have (yet) been updated during the current run.

    The subscribe metaparameter does two things:

    1. The same thing that require does: ensure that the designated resource(s) are checked, and synced if necessary (and refreshed, if applicable) before the resource on which the metaparameter appears is checked, synced, or refreshed.

    2. In the event that the designated resource was initially out of sync and Puppet successfully synced it, the resource on which the metaparameter appears is refreshed.

    The latter is what the Puppet docs mean when they talk about one resource being "changed" causing another to be refreshed. They are referring to the resource being changed by Puppet, to bring it into sync. Thus, it makes no sense to try to subscribe to a resource that is not under Puppet management. Such a resource can never be changed by Puppet, at least not such that Puppet would recognize that anything had happened.

    On a more technical level, the syntactic structure File[$old_launch_agent_path] with which you are expressing your subscription is an example of a "resource reference". These refer to resources declared elsewhere in the same catalog, and they are invalid if no such resource in fact is declared. Whether a corresponding physical resource exists on the target system does not factor in.