Does a service resource autorequire its package resource?

Skip to first unread message

royhills

unread,
Jan 19, 2013, 1:03:58 PM1/19/13
to puppet...@googlegroups.com
I've seen a couple of instances where a service resource has failed with an error because it's
been evaluated before its corresponding package is installed. I can fix this by adding an explicit
require to the service resource, or by just running puppet again, but I thought that there would be
an implicit or automatic require from a service object to the associate service object.

Here's an example class where I've seen this, although it only happens when I have this class
as part of a larger overall manifest and I'm commissioning a new system.

class tftp_server {

   package { 'tftpd-hpa':
      ensure => installed,
   }

   service { 'tftpd-hpa':
      ensure => running,
      enable => true,
      hasstatus => true,
      hasrestart => true,
   }

   file { '/srv/tftp':
      ensure => 'directory',
      owner => 'root',
      group => 'root',
      mode => '0644',
      require => Package['tftpd-hpa'],
      source => 'puppet:///modules/tftp_server/tftp',
      recurse => true,
      purge => true,
      ignore => '.svn',
   }
}

Note that there is no notify/subscribe between the file object and the service object. Perhaps
that's why I get the problem?

What I see is:

info: Applying configuration version '1358616112'
...
err: /Stage[main]/Tftp_server/Service[tftpd-hpa]: Could not evaluate: Could not find init script for 'tftpd-hpa'
...
notice: /Stage[main]/Tftp_server/Package[tftpd-hpa]/ensure: ensure changed 'purged' to 'present'
...

In http://docs.puppetlabs.com/learning/ordering.html, it says "Some of Puppet’s resource types will notice
when an instance is related to other resources, and they’ll set up automatic dependencies", but it doesn't
state exactly what resources this relates to. I'd expected service/package to be one of the examples though.

I'm running puppet 2.6.2 on Debian Squeeze with Ruby 1.8.7.

Nan Liu

unread,
Jan 19, 2013, 3:01:41 PM1/19/13
to puppet...@googlegroups.com
This is not an auto dependency. They are all documented in the resource type document by searching autorequires:

Nan

Ken Barber

unread,
Jan 19, 2013, 3:01:58 PM1/19/13
to Puppet Users
> I've seen a couple of instances where a service resource has failed with an
> error because it's
> been evaluated before its corresponding package is installed. I can fix this
> by adding an explicit
> require to the service resource, or by just running puppet again, but I
> thought that there would be
> an implicit or automatic require from a service object to the associate
> service object.

That would be nice, but alas its not true. You have to build up the
dependencies between service and package yourself.

> Here's an example class where I've seen this, although it only happens when
> I have this class
> as part of a larger overall manifest and I'm commissioning a new system.
>
> class tftp_server {
>
> package { 'tftpd-hpa':
> ensure => installed,
> }
>
> service { 'tftpd-hpa':
> ensure => running,
> enable => true,
> hasstatus => true,
> hasrestart => true,
> }
>
> file { '/srv/tftp':
> ensure => 'directory',
> owner => 'root',
> group => 'root',
> mode => '0644',
> require => Package['tftpd-hpa'],
> source => 'puppet:///modules/tftp_server/tftp',
> recurse => true,
> purge => true,
> ignore => '.svn',
> }
> }
>
> Note that there is no notify/subscribe between the file object and the
> service object. Perhaps
> that's why I get the problem?

Yes. A notify/subscribe will restart the service if the file resource
changes (good for configuration files) AND build up the ordering so
this occur in the order you desire.

> What I see is:
>
> info: Applying configuration version '1358616112'
> ...
> err: /Stage[main]/Tftp_server/Service[tftpd-hpa]: Could not evaluate: Could
> not find init script for 'tftpd-hpa'
> ...
> notice: /Stage[main]/Tftp_server/Package[tftpd-hpa]/ensure: ensure changed
> 'purged' to 'present'
> ...
>
> In http://docs.puppetlabs.com/learning/ordering.html, it says "Some of
> Puppet’s resource types will notice
> when an instance is related to other resources, and they’ll set up automatic
> dependencies", but it doesn't
> state exactly what resources this relates to. I'd expected service/package
> to be one of the examples though.

Take a look at the Type reference, and search for 'Autorequires'.

http://docs.puppetlabs.com/references/latest/type.html

The more obvious and common autorequire cases are:

* user: groups defined in the user resource
* file: creates groups and users defined in owner, group parameters first
* cron: creates users defined in the cron resource first
* package: creates file resources, if the package is being installed
from a file (as apposed to something on the network)

ken.

royhills

unread,
Jan 20, 2013, 4:14:18 AM1/20/13
to puppet...@googlegroups.com
Thanks for the responses. The pointer to the autorequires sections in the type reference is what
I was looking for.

It might be a good idea to add this pointer to the autorequire section in the docs here:
http://docs.puppetlabs.com/learning/ordering.html

This is what I read first, and it doesn't mention where to find out the details.  Here's what
it says:

"Don’t sweat much about the details of autorequiring; it’s fairly conservative and should
generally do the right thing without getting in your way. If you forget it’s there and make
explicit dependencies, your code will still work."

Reply all
Reply to author
Forward
0 new messages