Classes, Subclasses, and Requirements

1,326 views
Skip to first unread message

LTH

unread,
May 17, 2012, 10:53:03 AM5/17/12
to puppet...@googlegroups.com
Hello,

I'm having some trouble with subclasses accessing other subclasses within the same main class.

I have boiled it down a general case.  I have the following files:

## /etc/puppet/modules/test1
class test1 {

  class {'test2::bar':}  

}

## /etc/puppet/modules/test2/init.pp
class test2 {
  class {test2::foo}
  class {test2::bar}
  class {test2::baz}
}

## /etc/puppet/modules/test2/foo.pp
class test2::foo {
     # do something here in foo
 
}

## /etc/puppet/modules/test2/bar.pp
class test2::bar {
     # do something here that requires test2::foo
  exec { 'bar_in_tmp':  
    path    => '/usr/bin:/usr/sbin:/bin',
    command => "touch /tmp/bar",
    creates => '/tmp/bar',
    require => [
    Class['test2::foo'],
                ],
  }

}

## /etc/puppet/modules/test2/baz.pp

class test2::baz {
  # do something unwanted here
 

}

When the agent runs it dies saying "Could not find dependence Class['Test2::Foo']  for Exec['bar_in_tmp']"

Now if I change that line in test1 to just class {'test2':} it runs without error.  However since the main class call test2::baz, it does more than I wanted.  Am I not understanding something?  How do I just do bar and foo?

Thanks in advance,

-LTH




James Sweeny

unread,
May 17, 2012, 11:23:40 AM5/17/12
to puppet...@googlegroups.com
You can't require Class['test2::foo'] unless it's already available where you're requiring it. You need to include test2::foo in test2::bar.






--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/QJOSn1NqhEsJ.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.



--

James Sweeny

Professional Services


LTH

unread,
May 17, 2012, 1:06:30 PM5/17/12
to puppet...@googlegroups.com
On Thursday, May 17, 2012 11:23:40 AM UTC-4, James Sweeny wrote:
You can't require Class['test2::foo'] unless it's already available where you're requiring it. You need to include test2::foo in test2::bar.


Thanks.

If I include test2:foo in test2::bar, do I still need  require => [Class['test2::foo'] on the exec?  In testing this, it seems that I don't.




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.

James Sweeny

unread,
May 17, 2012, 1:14:40 PM5/17/12
to puppet...@googlegroups.com
The point of the "require" parameter is to define a dependency relationship. In the example you gave, it doesn't really make sense to have the exec require a class that does nothing (test2::foo), so you can drop the require.

On the other hand, if the exec actually needed test2::foo to work correctly (for example, if test2::foo created a shell script that the exec needed to run), you would need that require or your catalog would likely fail to apply.

See here for more info: http://docs.puppetlabs.com/references/stable/metaparameter.html#require

To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/MqrvCA3LpnYJ.

To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Reply all
Reply to author
Forward
0 new messages