Albatross
Albatross

Reputation: 690

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

Upvotes: 1

Views: 425

Answers (2)

John Bollinger
John Bollinger

Reputation: 181008

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.

Upvotes: 0

Ramin
Ramin

Reputation: 121

Couple of things to add to your mental model in Puppet which will help you think about this. The Puppet catalog is a DAG, directed acyclic graph. Each resource you define such as file, package, service, etc is a node in that DAG. Metaparamters like before, notify, subscribe, etc set the relationships between the nodes in the graph.

What your error means is that Puppet can't find the resource File['your file'] in the catalog in order to add the relationships you've defined. The usual reason is that you have not defined it. Or misspelled it, that's my favorite mistake. Looking at your code you've merely assigned a variable and then referenced it as a resource.

Removing the subscribe is simplest. Or you can define the File though unless you want to change the content of the file I wouldn't bother.

Upvotes: 2

Related Questions