Controlling Puppet class execution order with parameters.

16 views
Skip to first unread message

Harish Kothuri

unread,
May 24, 2017, 11:57:40 AM5/24/17
to Puppet Users
Hi,

I have 3 classes and i need to execute class 3 only when class 1 and class 2 completes. All of these classes must be attached to a host.

class1($version='1.1.1'){
   .
   .
   .
}
class2($version='2.2.2'){
   .
   .
   .
}

and 

class3(){
    import class1
    import class2
   
    exec{ 'something':
          cmd => 'some command here',
          before => [Class['class1'], Class['class2']]
    }
}

When i try to apply the above relation, i get the following error

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: Class[class1] is already declared; cannot re declare on node machine.domain.com

Can any one guide me how to handle this scenario?

Thanks




Martin Alfke

unread,
May 24, 2017, 12:18:59 PM5/24/17
to puppet...@googlegroups.com
Hi Harish,

import is deprecated in Puppet 4!

You can use require:

class 3 {
require class1
require class2

}

Best,
Martin
> --
> 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/5e5d0f57-5df3-43f5-8d96-48896ed258b2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Peter Kristolaitis

unread,
May 24, 2017, 12:38:49 PM5/24/17
to puppet...@googlegroups.com

You need to use 'require' instead of 'import'.

Harish Kothuri

unread,
May 25, 2017, 8:45:00 AM5/25/17
to Puppet Users
I'm using Puppet 3.8.7 and "require" didn't work.

I could make it work with following

class1($version='1.1.1'){
   include Class3
   .
   .
   .before => [Class["Class3"]]
}
class2($version='2.2.2'){
   include Class3
   .
   .   .before => [Class["Class3"]]
}

and 

class3()
{

Arnau

unread,
May 25, 2017, 9:16:34 AM5/25/17
to puppet...@googlegroups.com
Hi,

1.- one module for you stuuf (moduleA)
2.- one file per class
3.-) one class that "contain" the others and set order.

moduleA/class1.pp
class moduleA::class1 { }

moduleA/class2.pp
class moduleA::class2 { }

moduleaA/class3.pp
class moduleA::class3 { }


moduleA/init.pp
contain moduelA::class1
contain moduelA::class2
contain moduelA::class3

Class['moduelA::class1'] ->
Class['moduelA::class2'] ->
Class['moduelA::class3'] 


HTH,
Arnau

--
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+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages