Darin Perusich
2011-Dec-05 21:21 UTC
[Puppet Users] File dependency not found when specified in a "define"
Hello All, I''m working on an ssh module and using a "define" to specify "non-standard" sshd_config options via templates. I basically want to add additional entries to the AllowGroups, set or unset Subsystem options, etc. Whenever I run "puppet agent --test --noop" against this modules is fails with "err: Failed to apply catalog: Could not find dependency File[sshd_config] for Service[sshd] at /etc/puppet/modules/ssh/manifests/init.pp:42". I''ve reviewed/compared this modules against other modules which are using define in the way and have following http://docs.puppetlabs.com/learning/definedtypes.html but I have no idea what''s causing the client/agent side error. "puppet parser --debug --verbose validate init.pp" doesn''t return any errors, or debugging/verbosity for that matter, so it''s syntactically sound. Puppet version is 2.7.6 on both the client and server. My ssh class/module can be found at this link. If anyone can provide any insight as to what the problem is I''d really appreciate it. I''ve been banging my head on this for far to long. http://pastebin.com/dGwtEEzB -- Later, Darin -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Phillip Frost
2011-Dec-05 21:26 UTC
Re: [Puppet Users] File dependency not found when specified in a "define"
On Dec 5, 2011, at 4:21 PM, Darin Perusich wrote:> Hello All, > > I''m working on an ssh module and using a "define" to specify "non-standard" sshd_config options via templates. I basically want to add additional entries to the AllowGroups, set or unset Subsystem options, etc. Whenever I run "puppet agent --test --noop" against this modules is fails with "err: Failed to apply catalog: Could not find dependency File[sshd_config] for Service[sshd] at /etc/puppet/modules/ssh/manifests/init.pp:42". > [...] > http://pastebin.com/dGwtEEzBHow are you declaring this ssh::sshd_config resource or the ssh class? I suspect you are declaring ssh:sshd_config but not the class, so the sshd service and sshd_config file declared therein aren''t declared, thus the error. If that''s the case, one solution is to add "include ssh" inside ssh::ssh_config. This will implicitly declare the ssh class whenever you declare a ssh::sshd_config. The other solution (which I''d prefer, because explicit is better than implicit) is to declare the ssh class explicitly before you declare an ssh:ssh_config, with either: include ssh or class { ''ssh'': } -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Darin Perusich
2011-Dec-06 13:59 UTC
Re: [Puppet Users] File dependency not found when specified in a "define"
Hi Phillip, On Mon, Dec 5, 2011 at 4:26 PM, Phillip Frost <indigo@bitglue.com> wrote:> > On Dec 5, 2011, at 4:21 PM, Darin Perusich wrote: > > > Hello All, > > > > I''m working on an ssh module and using a "define" to specify > "non-standard" sshd_config options via templates. I basically want to add > additional entries to the AllowGroups, set or unset Subsystem options, etc. > Whenever I run "puppet agent --test --noop" against this modules is fails > with "err: Failed to apply catalog: Could not find dependency > File[sshd_config] for Service[sshd] at > /etc/puppet/modules/ssh/manifests/init.pp:42". > > [...] > > http://pastebin.com/dGwtEEzB > > How are you declaring this ssh::sshd_config resource or the ssh class? I > suspect you are declaring ssh:sshd_config but not the class, so the sshd > service and sshd_config file declared therein aren''t declared, thus the > error. > >The ssh class, as posted in the pastebin link, is defined in /etc/puppet/modules/ssh/manifests/init.pp, and given that the ssh:sshd_config is defined within said init.pp I didn''t think I needed to do anything else.> If that''s the case, one solution is to add "include ssh" inside > ssh::ssh_config. This will implicitly declare the ssh class whenever you > declare a ssh::sshd_config. The other solution (which I''d prefer, because > explicit is better than implicit) is to declare the ssh class explicitly > before you declare an ssh:ssh_config, with either: > > include ssh > > or > > class { ''ssh'': } >I have tried this by placing the ''define sshd_config'' into a separate file, /etc/puppet/modules/ssh/manifests/sshd_config.pp, and using "include ssh". I prefer this method but I get the same error. I''ve merged the define back into init.pp thinking I wouldn''t need to explicitly declare the ssh class within ssh::sshd_config because of it''s inclusion. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2011-Dec-07 21:58 UTC
[Puppet Users] Re: File dependency not found when specified in a "define"
On Dec 6, 7:59 am, Darin Perusich <da...@darins.net> wrote:> I have tried this by placing the ''define sshd_config'' into a separate file, > /etc/puppet/modules/ssh/manifests/sshd_config.pp, and using "include ssh". > I prefer this method but I get the same error. I''ve merged the define back > into init.pp thinking I wouldn''t need to explicitly declare the ssh class > within ssh::sshd_config because of it''s inclusion.- Hide quoted text -In the first place, your definition is a bit screwey in that it cannot be instantiated more than once (you would get a duplicate resource error on File[''sshd_config'']). A definition creates a resource *type* but you''re using it as if it created a single resource. And that leads directly to the crux of your problem: at the point where your service resource is parsed, no instance of the definition can yet have been created, and therefore File[''sshd_config''] cannot yet have been declared. The service cannot declare a dependency on an undeclared resource. Since you would prefer to put the definition in its own file anyway, I recommend you do so. Then, add "include ''ssh''" at the beginning of its body and re-enable the ''notify'' parameter in the file resource. Remove the ''subscribe'' from the service resource, but add "require => Package[''ssh'']". Then you should be good to go. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2011-Dec-07 22:16 UTC
[Puppet Users] Re: File dependency not found when specified in a "define"
On Dec 7, 3:58 pm, I wrote:> In the first place, your definition is a bit screwey in that it cannot > be instantiated more than once (you would get a duplicate resource > error on File[''sshd_config'']). A definition creates a resource *type* > but you''re using it as if it created a single resource.The *right* way to do this, by the way, involves making that a class instead of a definition. I am not inclined to recommend parameterized classes to anyone, however, and to change from a definition to an unparameterized class would take more work and be more disruptive than would the approach I described in my previous post. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Darin Perusich
2011-Dec-09 19:02 UTC
Re: [Puppet Users] Re: File dependency not found when specified in a "define"
Hi John, On Wed, Dec 7, 2011 at 4:58 PM, jcbollinger <John.Bollinger@stjude.org>wrote:> > On Dec 6, 7:59 am, Darin Perusich <da...@darins.net> wrote: > > I have tried this by placing the ''define sshd_config'' into a separate > file, > > /etc/puppet/modules/ssh/manifests/sshd_config.pp, and using "include > ssh". > > I prefer this method but I get the same error. I''ve merged the define > back > > into init.pp thinking I wouldn''t need to explicitly declare the ssh class > > within ssh::sshd_config because of it''s inclusion.- Hide quoted text - > > > In the first place, your definition is a bit screwey in that it cannot > be instantiated more than once (you would get a duplicate resource > error on File[''sshd_config'']). A definition creates a resource *type* > but you''re using it as if it created a single resource. > >This is my first attempt at setting up a dynamic template so i''m not surprised it''s screwy. It''s loosely based on similar modules I''ve seen online and what I''ve gathered from read the documentation. Basically what i want is to specify a ''default'' sshd_config, based on the template, with the ability to change things like AllowGroups/User, sftp-server options, etc.> And that leads directly to the crux of your problem: at the point > where your service resource is parsed, no instance of the definition > can yet have been created, and therefore File[''sshd_config''] cannot > yet have been declared. The service cannot declare a dependency on an > undeclared resource. > > Since you would prefer to put the definition in its own file anyway, I > recommend you do so. Then, add "include ''ssh''" at the beginning of > its body and re-enable the ''notify'' parameter in the file resource. > Remove the ''subscribe'' from the service resource, but add "require => > Package[''ssh'']". Then you should be good to go. > >I''ll give these changes a try and let you know how things turn out. Thanks! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Darin Perusich
2011-Dec-12 14:42 UTC
Re: [Puppet Users] Re: File dependency not found when specified in a "define"
> >> In the first place, your definition is a bit screwey in that it cannot >> be instantiated more than once (you would get a duplicate resource >> error on File[''sshd_config'']). A definition creates a resource *type* >> but you''re using it as if it created a single resource. >> >> And that leads directly to the crux of your problem: at the point >> where your service resource is parsed, no instance of the definition >> can yet have been created, and therefore File[''sshd_config''] cannot >> yet have been declared. The service cannot declare a dependency on an >> undeclared resource. >> >> Since you would prefer to put the definition in its own file anyway, I >> recommend you do so. Then, add "include ''ssh''" at the beginning of >> its body and re-enable the ''notify'' parameter in the file resource. >> Remove the ''subscribe'' from the service resource, but add "require => >> Package[''ssh'']". Then you should be good to go. >> >> > I''ll give these changes a try and let you know how things turn out. > >I''ve updated the module using your recommendations and it is working nicely, however I do get the duplicate resource on File[''sshd_config''] if/when it''s set multiple times. What would be the recommended way to of handling this? Other than not duplicating the resource. Thanks! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2011-Dec-12 23:08 UTC
[Puppet Users] Re: File dependency not found when specified in a "define"
On Dec 12, 8:42 am, Darin Perusich <da...@darins.net> wrote:> >> In the first place, your definition is a bit screwey in that it cannot > >> be instantiated more than once (you would get a duplicate resource > >> error on File[''sshd_config'']). A definition creates a resource *type* > >> but you''re using it as if it created a single resource. > > >> And that leads directly to the crux of your problem: at the point > >> where your service resource is parsed, no instance of the definition > >> can yet have been created, and therefore File[''sshd_config''] cannot > >> yet have been declared. The service cannot declare a dependency on an > >> undeclared resource. > > >> Since you would prefer to put the definition in its own file anyway, I > >> recommend you do so. Then, add "include ''ssh''" at the beginning of > >> its body and re-enable the ''notify'' parameter in the file resource. > >> Remove the ''subscribe'' from the service resource, but add "require => > >> Package[''ssh'']". Then you should be good to go. > > > I''ll give these changes a try and let you know how things turn out. > > I''ve updated the module using your recommendations and it is working > nicely, however I do get the duplicate resource on File[''sshd_config''] > if/when it''s set multiple times. What would be the recommended way to of > handling this? Other than not duplicating the resource.Declaring a duplicate resource will always cause Puppet to throw an error during catalog compilation. This is an intentional behavior, and there is no way to avoid it other than not duplicating the resource. A better question, then, is how to avoid duplicating the resource. One way, of course, is to be careful about when and where you instantiate your definition. I gather that''s what you are trying to avoid. I now refer you to my earlier remarks about the right way to approach this problem: that is, the right way is to use a class rather than a definition. By itself, however, that''s not enough to solve a duplicate resource problem. You must be sure to change to an *unparameterized* class, and you should use the ''include'' function to assign it to nodes in all the places where you now instantiate the definition. This means you will need an alternative mechanism for feeding data to the class (since parameters are not viable for this scenario). A good alternative is external data accessed via extlookup() or hiera, but you could also use class variables (of some other class) or global variables. Or perhaps you can make the class smart enough to figure out the appropriate values itself. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2011-Dec-13 13:52 UTC
[Puppet Users] Re: File dependency not found when specified in a "define"
On Dec 12, 5:08 pm, jcbollinger <John.Bollin...@stJude.org> wrote:> [...] the right way is to use a class rather than a > definition. By itself, however, that''s not enough to solve a > duplicate resource problem.Clarification: using the parameterized class declaration syntax will more than once for the same class will cause a different error. Technically speaking, you no longer have a duplicate resource, but the catalog still won''t compile. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.