Dictating class evaluation order

92 views
Skip to first unread message

Andrew Langhorn

unread,
Jul 18, 2015, 7:19:07 PM7/18/15
to puppet...@googlegroups.com

Hi,


I have a Puppet manifest which makes use of the tomcat::instance defined type from the camptocamp/tomcat module on the Puppet Forge as follows:


class apps::reservations {


include tomcat


tomcat::instance { ‘reservations’:

ensure => present,

http_port => 8080,

}


}


However, when I run Puppet against a Vagrant VM, it tells me that the tomcat class hasn’t been evaluated, so it can’t use tomcat::instance (because of underlying failures when using the Tomcat module):


==> app: Warning: Scope(Tomcat::Instance[reservations]): Could not look up qualified variable 'tomcat::instance_basedir'; class tomcat has not been evaluated


This makes some sense to me, since I’m not defining an order in which Puppet should run these resources. If the Tomcat module is not evaluated in to the catalogue before I use the tomcat::instance resource, then failures will occur.


How can I get Puppet to instantiate the Tomcat module first before then looking to work with tomcat::instance? Adding the require metaparameter to the tomcat::instance resource doesn't appear to do what I want it to do (i.e. evaluate the include before using the resource).


I’ve seen a related problem before, and fixed that after a while, but this one’s got me a bit stumped. It doesn't help either that I can't remember how I fixed the last issue, even after looking through Git commits. Sad times.


Thanks!


Andrew

Felix Frank

unread,
Jul 18, 2015, 8:06:26 PM7/18/15
to puppet...@googlegroups.com
On 07/19/2015 01:19 AM, Andrew Langhorn wrote:

class apps::reservations {


include tomcat


tomcat::instance { ‘reservations’:

ensure => present,

http_port => 8080,

}


}


However, when I run Puppet against a Vagrant VM, it tells me that the tomcat class hasn’t been evaluated, so it can’t use tomcat::instance (because of underlying failures when using the Tomcat module):


==> app: Warning: Scope(Tomcat::Instance[reservations]): Could not look up qualified variable 'tomcat::instance_basedir'; class tomcat has not been evaluated


Hmm, if the resource declaration is lexically preceded by an 'include tomcat' then this should not happen.

In this case, the order in your manifest is really important. Is your snippet truly representative of your actual code?

Regards,
Felix

Andrew Langhorn

unread,
Jul 19, 2015, 10:07:39 AM7/19/15
to puppet...@googlegroups.com
Hi Felix,

Thanks for the reply.

Yep - that snippet is representative. I've copied the full thing for you below. Granted, it needs some tidying up, but I think it should just work as it stands:

class app::reservations {

include tomcat

Exec {
  path => "/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin:/usr/local/sbin",
}

tomcat::instance { 'reservations':
  ensure    => present,
  http_port => 8080,
  require   => Class['tomcat'],
}

file { '/srv/tomcat/reservations/webapps/reservations.war':
  ensure => present,
  source => 'puppet:///modules/app/reservations.war',
  owner  => 'tomcat',
  group  => 'adm',
  mode   => '0755',
  notify => Exec['restart-reservations-tomcat'],
  }

exec { 'restart-reservations-tomcat':
  command => '/etc/init.d/tomcat-reservations restart',
}

}

Under normal circumstances, I agree that explicitly including the Tomcat class up above the instantiation of the tomcat::instance class should work fine. I don't know why it's not working quite as expected. Here's the output from Puppet with the --debug flag:

==> app: Debug: importing '/opt/puppet/modules/app/manifests/reservations.pp' in environment development
==> app: Debug: Automatically imported app:reservations from app/reservations in to development
==> app: Debug: importing '/opt/puppet/modules/app/manifests/tomcat.pp' in environment development
==> app: Debug: Automatically imported app::tomcat from app/tomcat into development
==> app: Debug: importing '/opt/puppet/vendor/modules/tomcat/manifests/instance.pp' in environment development
==> app: Debug: Automatically imported tomcat::instance from tomcat/instance into development
==> app: Warning: Scope(Tomcat::Instance[reservations]): Could not look up qualified variable 'tomcat::instance_basedir'; class tomcat has not been evaluated
==> app: Warning: Scope(Tomcat::Instance[reservations]): Could not look up qualified variable 'tomcat::version'; class tomcat has not been evaluated

Values for both tomcat::version and tomcat::instance_basedir are retrieved from a case statement which, ultimately, resides at https://github.com/camptocamp/puppet-tomcat/blob/master/manifests/params.pp, which either works out a value or just passes in a value, respectively.

So, it looks like the Tomcat module is - at least partially - being imported.

I'm a bit stumped now!

Andrew

Andrew Langhorn

unread,
Jul 19, 2015, 10:11:12 AM7/19/15
to puppet...@googlegroups.com
I should probably add that, for $reasons, I'm using Puppet 3.6.1.

Peter Huene

unread,
Jul 19, 2015, 2:55:13 PM7/19/15
to puppet...@googlegroups.com
It looks like the loader found app/manifests/tomcat.pp instead of tomcat/manifests/init.pp.  Perhaps qualify the include as `include ::tomcat`?  Not sure if that would work with Puppet 3.6 though.
 
==> app: Debug: Automatically imported app::tomcat from app/tomcat into development
==> app: Debug: importing '/opt/puppet/vendor/modules/tomcat/manifests/instance.pp' in environment development
==> app: Debug: Automatically imported tomcat::instance from tomcat/instance into development
==> app: Warning: Scope(Tomcat::Instance[reservations]): Could not look up qualified variable 'tomcat::instance_basedir'; class tomcat has not been evaluated
==> app: Warning: Scope(Tomcat::Instance[reservations]): Could not look up qualified variable 'tomcat::version'; class tomcat has not been evaluated

Values for both tomcat::version and tomcat::instance_basedir are retrieved from a case statement which, ultimately, resides at https://github.com/camptocamp/puppet-tomcat/blob/master/manifests/params.pp, which either works out a value or just passes in a value, respectively.

So, it looks like the Tomcat module is - at least partially - being imported.

I'm a bit stumped now!

Andrew

On Sunday, 19 July 2015 01:06:26 UTC+1, Felix.Frank wrote:
On 07/19/2015 01:19 AM, Andrew Langhorn wrote:

class apps::reservations {


include tomcat


tomcat::instance { ‘reservations’:

ensure => present,

http_port => 8080,

}


}


However, when I run Puppet against a Vagrant VM, it tells me that the tomcat class hasn’t been evaluated, so it can’t use tomcat::instance (because of underlying failures when using the Tomcat module):


==> app: Warning: Scope(Tomcat::Instance[reservations]): Could not look up qualified variable 'tomcat::instance_basedir'; class tomcat has not been evaluated


Hmm, if the resource declaration is lexically preceded by an 'include tomcat' then this should not happen.

In this case, the order in your manifest is really important. Is your snippet truly representative of your actual code?

Regards,
Felix

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/2d506a73-c86a-4ddd-bfd4-09579565bd04%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Join us at PuppetConf 2015, October 5-9 in Portland, OR - www.2015.puppetconf.com 
Register early to save 40%!

Andrew Langhorn

unread,
Jul 19, 2015, 7:38:48 PM7/19/15
to puppet...@googlegroups.com
I don't know why, but when I renamed the class, things started to work.
Very odd. Maybe I should just upgrade to the latest stable 3.x release (3.8.0, I think), or even 4.

Thanks though - especially helpful on this list, as usual :)

--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/w9mVNiq8kAk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CACZQQfO4BWWK3_aZ2xBWSRaKGnGp00uaA66DVFxkL-7jdOadbA%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Andrew Langhorn
Web Operations
Government Digital Service

a: 6th Floor, Aviation House, 125 Kingsway, London, WC2B 6NH

Gareth Rushgrove

unread,
Jul 20, 2015, 3:29:47 AM7/20/15
to puppet...@googlegroups.com
Hi Andrew

On 20 July 2015 at 00:38, Andrew Langhorn
<andrew....@digital.cabinet-office.gov.uk> wrote:
> I don't know why, but when I renamed the class, things started to work.
> Very odd. Maybe I should just upgrade to the latest stable 3.x release
> (3.8.0, I think), or even 4.

See Peter's email above.

The issue appears to be that you had two classes called tomcat, and
'include tomcat' will load the first one it finds which in this case
was the one from app/manifests/tomcat.pp rather than the one you
expected from the third party module. So it never loads
tomcat::instance_basedir etc.

Instead of include tomcat you can use the following formulation:

include ::tomcat

This forces the lookup to be from the top level, so should correctly
import the tomcat module you are expecting. I'd probably do that as
well.

Gareth
> https://groups.google.com/d/msgid/puppet-users/CANCa_Wb%3DS72jJ45fbYU4eag5CedYYUxoBCc6eY8L3uXxyWZ8-A%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Gareth Rushgrove
@garethr

devopsweekly.com
morethanseven.net
garethrushgrove.com

Andrew Langhorn

unread,
Jul 20, 2015, 4:24:45 AM7/20/15
to puppet...@googlegroups.com
Morning Gareth,

Ah - I re-read that, and that makes more sense, especially since renaming the class fixed it. I'll give it a go to neaten up the module; am sure it will work.

Thanks both!

:)

A

For more options, visit https://groups.google.com/d/optout.


--

Reply all
Reply to author
Forward
0 new messages